Class: Squeel::Nodes::Stub
- Inherits:
-
Object
- Object
- Squeel::Nodes::Stub
- Includes:
- Aliasing, Operators, PredicateMethods
- Defined in:
- lib/squeel/nodes/stub.rb
Overview
Stub nodes are basically a container for a Symbol that can have handy predicate methods and operators defined on it since doing so on Symbol will incur the nerdrage of many.
Instance Attribute Summary collapse
-
#symbol ⇒ Symbol
readonly
The symbol contained by this stub.
Instance Method Summary collapse
-
#asc ⇒ Order
Create an ascending Order node with this Stub’s symbol as its expression.
-
#desc ⇒ Order
Create a descending Order node with this Stub’s symbol as its expression.
-
#eql?(other) ⇒ Boolean
Object comparison.
-
#func(*args) ⇒ Function
Create a Function node for a function named the same as this Stub and with the given arguments.
-
#hash ⇒ Object
To support object equality tests.
-
#initialize(symbol) ⇒ Stub
constructor
Create a new Stub.
-
#inner ⇒ Join
Create an inner Join node for the association named by this Stub.
-
#method_missing(method_id, *args) ⇒ Object
Create a KeyPath when any undefined method is called on a Stub.
-
#of_class(klass) ⇒ Join
Create a polymorphic Join node for the association named by this Stub,.
-
#outer ⇒ Join
Create an outer Join node for the association named by this Stub.
-
#to_s ⇒ String
(also: #to_str)
The Stub’s String equivalent.
-
#to_sym ⇒ Symbol
The symbol this Stub contains.
-
#~ ⇒ KeyPath
Return a KeyPath containing only this Stub, but flagged as absolute.
Methods included from Aliasing
Methods included from Operators
Constructor Details
#initialize(symbol) ⇒ Stub
Create a new Stub.
34 35 36 |
# File 'lib/squeel/nodes/stub.rb', line 34 def initialize(symbol) @symbol = symbol end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#node_name ⇒ KeyPath #node_name(klass) ⇒ KeyPath
Create a KeyPath when any undefined method is called on a Stub.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/squeel/nodes/stub.rb', line 68 def method_missing(method_id, *args) super if method_id == :to_ary if args.empty? KeyPath.new(self, method_id) elsif (args.size == 1) && (Class === args[0]) KeyPath.new(self, Join.new(method_id, Arel::InnerJoin, args[0])) else KeyPath.new(self, Nodes::Function.new(method_id, args)) end end |
Instance Attribute Details
#symbol ⇒ Symbol (readonly)
Returns The symbol contained by this stub.
30 31 32 |
# File 'lib/squeel/nodes/stub.rb', line 30 def symbol @symbol end |
Instance Method Details
#asc ⇒ Order
Create an ascending Order node with this Stub’s symbol as its expression
89 90 91 |
# File 'lib/squeel/nodes/stub.rb', line 89 def asc Order.new self.symbol, 1 end |
#desc ⇒ Order
Create a descending Order node with this Stub’s symbol as its expression
95 96 97 |
# File 'lib/squeel/nodes/stub.rb', line 95 def desc Order.new self.symbol, -1 end |
#eql?(other) ⇒ Boolean
Object comparison
39 40 41 42 |
# File 'lib/squeel/nodes/stub.rb', line 39 def eql?(other) self.class == other.class && self.symbol == other.symbol end |
#func(*args) ⇒ Function
Create a Function node for a function named the same as this Stub and with the given arguments
101 102 103 |
# File 'lib/squeel/nodes/stub.rb', line 101 def func(*args) Function.new(self.symbol, args) end |
#hash ⇒ Object
To support object equality tests
45 46 47 |
# File 'lib/squeel/nodes/stub.rb', line 45 def hash symbol.hash end |
#inner ⇒ Join
Create an inner Join node for the association named by this Stub
107 108 109 |
# File 'lib/squeel/nodes/stub.rb', line 107 def inner Join.new(self.symbol, Arel::InnerJoin) end |
#of_class(klass) ⇒ Join
Create a polymorphic Join node for the association named by this Stub,
120 121 122 |
# File 'lib/squeel/nodes/stub.rb', line 120 def of_class(klass) Join.new(self.symbol, Arel::InnerJoin, klass) end |
#outer ⇒ Join
Create an outer Join node for the association named by this Stub
113 114 115 |
# File 'lib/squeel/nodes/stub.rb', line 113 def outer Join.new(self.symbol, Arel::OuterJoin) end |
#to_s ⇒ String Also known as: to_str
Returns The Stub’s String equivalent.
55 56 57 |
# File 'lib/squeel/nodes/stub.rb', line 55 def to_s symbol.to_s end |
#to_sym ⇒ Symbol
Returns The symbol this Stub contains.
50 51 52 |
# File 'lib/squeel/nodes/stub.rb', line 50 def to_sym symbol end |