Class: SetBuilder::Set
- Inherits:
-
Object
- Object
- SetBuilder::Set
- Defined in:
- lib/set_builder/set.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #constraints ⇒ Object
-
#initialize(model_or_scope, raw_data) ⇒ Set
constructor
A new instance of Set.
-
#perform ⇒ Object
Returns an instance of ActiveRecord::NamedScope::Scope which can fetch the objects which belong to this set.
-
#to_s ⇒ Object
Describes this set in natural language.
-
#valid? ⇒ Boolean
Returns true if all of the constraints in this set are valid.
Constructor Details
#initialize(model_or_scope, raw_data) ⇒ Set
Returns a new instance of Set.
6 7 8 9 |
# File 'lib/set_builder/set.rb', line 6 def initialize(model_or_scope, raw_data) @model, @scope = get_model_and_scope(model_or_scope) @set = raw_data end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
13 14 15 |
# File 'lib/set_builder/set.rb', line 13 def model @model end |
Instance Method Details
#constraints ⇒ Object
17 18 19 |
# File 'lib/set_builder/set.rb', line 17 def constraints @constraints ||= get_constraints end |
#perform ⇒ Object
Returns an instance of ActiveRecord::NamedScope::Scope which can fetch the objects which belong to this set
45 46 47 |
# File 'lib/set_builder/set.rb', line 45 def perform constraints.inject(@scope) {|scope, constraint| constraint.perform(scope)} end |
#to_s ⇒ Object
Describes this set in natural language
35 36 37 |
# File 'lib/set_builder/set.rb', line 35 def to_s constraints.to_sentence end |
#valid? ⇒ Boolean
Returns true if all of the constraints in this set are valid
26 27 28 |
# File 'lib/set_builder/set.rb', line 26 def valid? constraints.all?(&:valid?) end |