Class: Squeel::Nodes::Join
- Inherits:
-
Object
- Object
- Squeel::Nodes::Join
- Defined in:
- lib/squeel/nodes/join.rb
Overview
A node representing a joined association
Instance Attribute Summary collapse
- #_klass ⇒ Class, NilClass
-
#_name ⇒ Symbol
readonly
The join’s association name.
-
#_type ⇒ Arel::InnerJoin, Arel::OuterJoin
readonly
The ARel join type.
Instance Method Summary collapse
-
#convert_to_class(value) ⇒ Class
private
Convert the given value into a class.
-
#eql?(other) ⇒ Boolean
(also: #==)
Compare with other objects.
-
#initialize(name, type = Arel::InnerJoin, klass = nil) ⇒ Join
constructor
Create a new Join node.
-
#inner ⇒ Join
Set the join type to an inner join.
-
#method_missing(method_id, *args) ⇒ Object
Ensures that a Join can be used as the base of a new KeyPath.
-
#outer ⇒ Join
Set the join type to an outer join.
-
#polymorphic? ⇒ NilClass, Class
Returns a true value (the class itself) if a polymorphic belongs_to class has been set.
-
#to_sym ⇒ NilClass
expand_hash_conditions_for_aggregates assumes our hash keys can be converted to symbols, so this has to be implemented, but it doesn’t really have to do anything useful.
-
#~ ⇒ KeyPath
Return a KeyPath containing only this Join, but flagged as absolute.
Constructor Details
#initialize(name, type = Arel::InnerJoin, klass = nil) ⇒ Join
Create a new Join node
21 22 23 24 |
# File 'lib/squeel/nodes/join.rb', line 21 def initialize(name, type = Arel::InnerJoin, klass = nil) @_name, @_type = name, type @_klass = convert_to_class(klass) if klass end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#node_name ⇒ KeyPath #node_name(klass) ⇒ KeyPath
Ensures that a Join can be used as the base of a new KeyPath
70 71 72 73 74 75 76 77 |
# File 'lib/squeel/nodes/join.rb', line 70 def method_missing(method_id, *args) super if method_id == :to_ary if (args.size == 1) && (Class === args[0]) KeyPath.new(self, Join.new(method_id, Arel::InnerJoin, args[0])) else KeyPath.new(self, method_id) end end |
Instance Attribute Details
#_klass ⇒ Class, NilClass
15 16 17 |
# File 'lib/squeel/nodes/join.rb', line 15 def _klass @_klass end |
#_name ⇒ Symbol (readonly)
Returns The join’s association name.
8 9 10 |
# File 'lib/squeel/nodes/join.rb', line 8 def _name @_name end |
#_type ⇒ Arel::InnerJoin, Arel::OuterJoin (readonly)
Returns The ARel join type.
11 12 13 |
# File 'lib/squeel/nodes/join.rb', line 11 def _type @_type end |
Instance Method Details
#convert_to_class(value) ⇒ Class (private)
Convert the given value into a class.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/squeel/nodes/join.rb', line 100 def convert_to_class(value) case value when String, Symbol Kernel.const_get(value) when Class value else raise ArgumentError, "#{value} cannot be converted to a Class" end end |
#eql?(other) ⇒ Boolean Also known as: ==
Compare with other objects
54 55 56 57 58 59 |
# File 'lib/squeel/nodes/join.rb', line 54 def eql?(other) self.class == other.class && self._name == other._name && self._type == other._type && self._klass == other._klass end |
#inner ⇒ Join
Set the join type to an inner join
28 29 30 31 |
# File 'lib/squeel/nodes/join.rb', line 28 def inner @_type = Arel::InnerJoin self end |
#outer ⇒ Join
Set the join type to an outer join
35 36 37 38 |
# File 'lib/squeel/nodes/join.rb', line 35 def outer @_type = Arel::OuterJoin self end |
#polymorphic? ⇒ NilClass, Class
Returns a true value (the class itself) if a polymorphic belongs_to class has been set
49 50 51 |
# File 'lib/squeel/nodes/join.rb', line 49 def polymorphic? @_klass end |
#to_sym ⇒ NilClass
expand_hash_conditions_for_aggregates assumes our hash keys can be converted to symbols, so this has to be implemented, but it doesn’t really have to do anything useful.
91 92 93 |
# File 'lib/squeel/nodes/join.rb', line 91 def to_sym nil end |