Skip to content

Instantly share code, notes, and snippets.

View snusnu's full-sized avatar

Martin Gamsjaeger snusnu

View GitHub Profile
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,
@snusnu
snusnu / gist:5759
Created August 16, 2008 21:18
Extension to sam/extlib that makes dealing with nested modules easier
class Object
def full_const_defined?(name)
!!full_const_get(name) rescue false
end
end
# 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
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'
module Foo
def foo
:foo
end
end
class Session
def user
@user ||= real_user_object
class << @user
# config/router.rb
Merb::Router.prepare do
resources :articles do
resources :comments do
resources :ratings, :controller => "Community::Ratings"
end
resource :editor
end
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 }
require 'rexml/document'
begin
gem('fastercsv')
require 'faster_csv'
rescue LoadError
nil
end
begin
#!/usr/bin/env ruby
require 'rubygems'
gem 'dm-core', '=0.9.10'
require 'dm-core'
# uncomment for logging output
#DataMapper::Logger.new(STDOUT, :debug)
#!/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:')