Skip to content

Instantly share code, notes, and snippets.

@moro
Created October 4, 2011 07:42
Show Gist options
  • Save moro/1261087 to your computer and use it in GitHub Desktop.
Save moro/1261087 to your computer and use it in GitHub Desktop.
# XXX more specific name.
class Person < ActiveRecord::Base
exec_context :hoge, default: true do
validate :foo, presence: true
before_create :foobar
end
validate :bar, presence: true
end
person = Person.new
another = Person.new
Person.in_context(:hoge) do
person.valid? # => hoge
another.valid? # => hoge
end
person = Person.in_context(:hoge).new
another = Person.new
person.save! #=> hoge
another.save! #=> not hoge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment