Method: Bsm::Constrainable::Field::Base#initialize
- Defined in:
- lib/bsm/constrainable/field/base.rb
#initialize(name, options = {}) ⇒ Base
Accepts a name and options. Valid options are:
-
:using- a Symbol or a Proc pointing to a DB column, optional (uses name by default) -
:with- a list of operators to use -
:scope- a Proc containing additional scopes
Examples:
Field::Integer.new :id
Field::Integer.new :uid, :using => :id
Field::Integer.new :uid, :using => proc { Model.scoped.table[:col_name] }
Field::String.new :name, :with => [:matches]
Field::String.new :author, :with => [:matches], :using => proc { Author.scoped.table[:name] }, :scope => proc { includes(:author) }
29 30 31 32 33 34 35 36 |
# File 'lib/bsm/constrainable/field/base.rb', line 29 def initialize(name, = {}) @name = name.to_s = .dup @attribute = .delete(:using) || name @operators = Set.new(self.class.operators & Array.wrap(.delete(:with))) @operators = Set.new(self.class.defaults) if @operators.empty? @scope = .delete(:scope) end |