Module: Bsm::Constrainable::Model::ClassMethods
- Defined in:
- lib/bsm/constrainable/model.rb
Instance Method Summary collapse
-
#_constrainable ⇒ Object
Store for constrainable definitions.
-
#constrain(*args) ⇒ Object
Delegator to Relation#constrain.
-
#constrainable(name = nil, &block) ⇒ Object
Constraint definition for a model.
Instance Method Details
#_constrainable ⇒ Object
Store for constrainable definitions
34 35 36 |
# File 'lib/bsm/constrainable/model.rb', line 34 def _constrainable @constrainable ||= {} end |
#constrain(*args) ⇒ Object
Delegator to Relation#constrain
29 30 31 |
# File 'lib/bsm/constrainable/model.rb', line 29 def constrain(*args) scoped.constrain(*args) end |
#constrainable(name = nil, &block) ⇒ Object
Constraint definition for a model. Example:
class Post < ActiveRecord::Base
constrainable do
# Add your default constraints
end
constrainable :custom do
# Add your custom constraints
end
end
21 22 23 24 25 26 |
# File 'lib/bsm/constrainable/model.rb', line 21 def constrainable(name = nil, &block) name = name.present? ? name.to_sym : :default _constrainable[name] ||= Bsm::Constrainable::Schema.new(self) _constrainable[name.to_sym].instance_eval(&block) if block _constrainable[name] end |