Class: SelfishAssociations::ScopeReaders::Relation
- Inherits:
- BasicObject
- Defined in:
- lib/selfish_associations/scope_readers/relation.rb
Instance Attribute Summary collapse
-
#attributes_for_create ⇒ Object
readonly
Returns the value of attribute attributes_for_create.
-
#conditions_for_find ⇒ Object
readonly
Returns the value of attribute conditions_for_find.
-
#traverser ⇒ Object
readonly
Returns the value of attribute traverser.
Instance Method Summary collapse
- #create_with(conditions) ⇒ Object
-
#initialize(klass) ⇒ Relation
constructor
A new instance of Relation.
- #joins_for_create ⇒ Object
- #joins_for_find ⇒ Object
- #read(scope) ⇒ Object
-
#where(conditions) ⇒ Object
TODO: implement argless where() and not().
Constructor Details
#initialize(klass) ⇒ Relation
Returns a new instance of Relation.
22 23 24 25 26 27 28 |
# File 'lib/selfish_associations/scope_readers/relation.rb', line 22 def initialize(klass) @traverser = ::SelfishAssociations::AssociationTraverser.new(klass) @conditions_for_find = {} @joins_for_find = [] @attributes_for_create = {} @joins_for_create = [] end |
Instance Attribute Details
#attributes_for_create ⇒ Object (readonly)
Returns the value of attribute attributes_for_create.
19 20 21 |
# File 'lib/selfish_associations/scope_readers/relation.rb', line 19 def attributes_for_create @attributes_for_create end |
#conditions_for_find ⇒ Object (readonly)
Returns the value of attribute conditions_for_find.
19 20 21 |
# File 'lib/selfish_associations/scope_readers/relation.rb', line 19 def conditions_for_find @conditions_for_find end |
#traverser ⇒ Object (readonly)
Returns the value of attribute traverser.
20 21 22 |
# File 'lib/selfish_associations/scope_readers/relation.rb', line 20 def traverser @traverser end |
Instance Method Details
#create_with(conditions) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/selfish_associations/scope_readers/relation.rb', line 45 def create_with(conditions) @attributes_for_create.merge!(conditions) @joins_for_create += @traverser.associations!(merge: false) @traverser.reset! return self end |
#joins_for_create ⇒ Object
56 57 58 |
# File 'lib/selfish_associations/scope_readers/relation.rb', line 56 def joins_for_create ::SelfishAssociations::PathMerger.new(@joins_for_create).merge end |
#joins_for_find ⇒ Object
52 53 54 |
# File 'lib/selfish_associations/scope_readers/relation.rb', line 52 def joins_for_find ::SelfishAssociations::PathMerger.new(@joins_for_find).merge end |
#read(scope) ⇒ Object
30 31 32 33 34 |
# File 'lib/selfish_associations/scope_readers/relation.rb', line 30 def read(scope) args = scope.arity == 0 ? [] : [@traverser] instance_exec(*args, &scope) return self end |
#where(conditions) ⇒ Object
TODO: implement argless where() and not()
37 38 39 40 41 42 43 |
# File 'lib/selfish_associations/scope_readers/relation.rb', line 37 def where(conditions) create_with(conditions) @conditions_for_find.merge!(conditions) @joins_for_find += @traverser.associations!(merge: false) @traverser.reset! return self end |