Class: SetBuilder::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/set_builder/set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#modelObject (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

#constraintsObject



17
18
19
# File 'lib/set_builder/set.rb', line 17

def constraints
  @constraints ||= get_constraints
end

#performObject

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_sObject

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

Returns:

  • (Boolean)


26
27
28
# File 'lib/set_builder/set.rb', line 26

def valid?
  constraints.all?(&:valid?)
end