Class: BabySqueel::Relation

Inherits:
Table
  • Object
show all
Defined in:
lib/baby_squeel/relation.rb

Direct Known Subclasses

Association, DSL

Instance Attribute Summary collapse

Attributes inherited from Table

#_join, #_on, #_table

Instance Method Summary collapse

Methods inherited from Table

#[], #_arel, #alias, #alias!, #alias?, #as, #evaluate, #find_alias, #inner, #inner!, #on, #on!, #outer, #outer!

Constructor Details

#initialize(scope) ⇒ Relation

Returns a new instance of 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

#_scopeObject

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
    raise AssociationNotFoundError.new(_scope.model_name, name)
  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