Class: BabySqueel::Relation
Direct Known Subclasses
Instance Attribute Summary collapse
-
#_scope ⇒ Object
Returns the value of attribute _scope.
Attributes inherited from Table
Instance Method Summary collapse
-
#association(name) ⇒ Object
Constructs a new BabySqueel::Association.
-
#initialize(scope) ⇒ Relation
constructor
A new instance of Relation.
-
#sift(sifter_name, *args) ⇒ Object
Invokes a sifter defined on the model.
Methods inherited from Table
#[], #_arel, #alias, #alias!, #find_alias, #inner, #inner!, #on, #on!, #outer, #outer!
Constructor Details
#initialize(scope) ⇒ Relation
7 8 9 10 |
# File 'lib/baby_squeel/relation.rb', line 7 def initialize(scope) super(scope.arel_table) @_scope = scope end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class BabySqueel::Table
Instance Attribute Details
#_scope ⇒ Object
Returns the value of attribute _scope.
5 6 7 |
# File 'lib/baby_squeel/relation.rb', line 5 def _scope @_scope end |
Instance Method Details
#association(name) ⇒ Object
Constructs a new BabySqueel::Association. Raises an exception if the association is not found.
14 15 16 17 18 19 20 |
# File 'lib/baby_squeel/relation.rb', line 14 def association(name) if reflection = _scope.reflect_on_association(name) Association.new(self, reflection) else not_found_error! name, type: AssociationNotFoundError end end |
#sift(sifter_name, *args) ⇒ Object
Invokes a sifter defined on the model
Examples
Post.where.has { sift(:name_contains, 'joe') }
27 28 29 |
# File 'lib/baby_squeel/relation.rb', line 27 def sift(sifter_name, *args) Nodes.wrap _scope.public_send("sift_#{sifter_name}", *args) end |