Created
October 4, 2011 07:42
-
-
Save moro/1261087 to your computer and use it in GitHub Desktop.
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
# 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