This file contains hidden or 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
| class MyModel | |
| include DataMapper::Resource | |
| # adds self.validate_constraint | |
| # validation will be performed in specified before callbacks | |
| include DataMapper::Validations::Constraints | |
| # validate an existing constraint (expects class MyConstraint to be loaded) | |
| validate_constraint :my_constraint, |
This file contains hidden or 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
| class Object | |
| def full_const_defined?(name) | |
| !!full_const_get(name) rescue false | |
| end | |
| end |
This file contains hidden or 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
| # Trip obviously being a DataMapper::Resource here ... | |
| irb(main):001:0> Trip.all :conditions => {} | |
| ArgumentError: +options[:conditions]+ cannot be empty | |
| from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/query.rb:226:in `assert_valid_options' | |
| from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/query.rb:163:in `initialize' | |
| from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/model.rb:394:in `new' | |
| from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/model.rb:394:in `scoped_query' | |
| from /Users/snusnu/projects/surf/gems/gems/dm-core-0.9.7/lib/dm-core/model.rb:252:in `all' | |
| from (irb):1 |
This file contains hidden or 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
| mungo:~/projects/trippings snusnu$ irb | |
| irb(main):001:0> require "rubygems"; require "randexp" | |
| => true | |
| irb(main):002:0> /\w{10}/.gen | |
| => "flattering" | |
| irb(main):003:0> /\w{20}/.gen | |
| => "hypsidolichocephalic" | |
| irb(main):004:0> /\w{30}/.gen | |
| NoMethodError: undefined method `pick' for nil:NilClass | |
| from /usr/local/lib/ruby/gems/1.8/gems/randexp-0.1.4/lib/randexp/randgen.rb:35:in `word' |
This file contains hidden or 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
| module Foo | |
| def foo | |
| :foo | |
| end | |
| end | |
| class Session | |
| def user | |
| @user ||= real_user_object | |
| class << @user |
This file contains hidden or 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
| # config/router.rb | |
| Merb::Router.prepare do | |
| resources :articles do | |
| resources :comments do | |
| resources :ratings, :controller => "Community::Ratings" | |
| end | |
| resource :editor | |
| end | |
This file contains hidden or 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
| class Articles < Application | |
| controlling :articles do |a| | |
| a.action :new, :only_provides => :html | |
| a.action :edit, :only_provides => :html | |
| a.action :create, :provides => [ :xml, :json, :yml ] do | |
| a.on_success { display member, :status => 201, :location => resource(member) } | |
| a.on_failure { display member.errors, :status => 422 } |
This file contains hidden or 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
| require 'rexml/document' | |
| begin | |
| gem('fastercsv') | |
| require 'faster_csv' | |
| rescue LoadError | |
| nil | |
| end | |
| begin |
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| gem 'dm-core', '=0.9.10' | |
| require 'dm-core' | |
| # uncomment for logging output | |
| #DataMapper::Logger.new(STDOUT, :debug) |
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| require 'rubygems' | |
| gem 'dm-core', '=0.9.10' | |
| require 'dm-core' | |
| DataMapper::Logger.new(STDOUT, :debug) | |
| DataMapper.setup(:default, 'sqlite3:memory:') | |
OlderNewer