This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# current code: | |
unless @users = cache_get("active_users") | |
@users = User.all(:active => true) | |
cache_set("active_users", @users) | |
# object caching can be used to avoid pulling huge amounts of data | |
# from the database. | |
# you could have calle cache_set with an expiration time as well: | |
# cache_set("active_users", @users, 10) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it 'should save both the object and parent if both are new' do | |
pending('This is a bug that should be fixed') do | |
area1 = Area.new(:name => 'area1') | |
area1.machine = Machine.new(:name => 'machine1') | |
area1.save | |
area1.machine_id.should == area1.machine.id | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
father = Father.new | |
child = Child.new(:father => father) | |
father.save | |
child.father_id.should == father.id # how? the child references the father, but there's no backlink atm | |
# ... unless |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inside Rakefile | |
unless ARGV.any? && ARGV[0][0..3] == 'dm:' | |
Kernel.send(:undef_method, :repository) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@identity_map = Hash.new do |h,model| | |
resource = h[model.base_model] | |
# set the IM if the resource's model is an ancestor of model | |
h[model] = resource if resource.model >= model | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Merb::BootLoader.after_app_loads do | |
DataObjects::Mysql.logger = DataObjects::Logger.new(STDOUT, Merb.logger.level) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get '/posts/:id' do |id| | |
# ... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource 'posts/:id' do | |
get do |id| | |
# show post id | |
end | |
put do |id, post| | |
# change post id, with the body params in "post" | |
end | |
delete do |id| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/local/bin/ruby | |
# Copyright (c) 2007 Dan Kubb <[email protected]> | |
# This tool shows any CSS rules that do not apply to HTML. Accepts a single | |
# argument on the command line, may be either a URI or an HTML file. | |
require 'rubygems' | |
require 'csspool' | |
require 'hpricot' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def xmlschema_datetime(dt) | |
string = sprintf '%4d-%02d-%02dT%02d:%02d:%02d', dt.year, dt.mon, dt.day, dt.hour, dt.min, dt.sec | |
string << sprintf('.%06d', dt.sec_fraction * 86400 * 10**6) if dt.sec_fraction.nonzero? | |
string << dt.zone | |
end |
OlderNewer