Class: Payload::Attr
- Inherits:
-
Object
show all
- Defined in:
- lib/payload/arm/attr.rb
Overview
Attribute DSL for select/group_by/order_by and filter expressions.
-
pl.attr.id -> “id”
-
pl.attr.created_at(:month) -> “month(created_at)”
-
pl.attr.amount(:sum) -> “sum(amount)”
-
pl.attr.sender.account_id -> “sender”
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(param, parent = nil) ⇒ Attr
Returns a new instance of Attr.
102
103
104
105
106
|
# File 'lib/payload/arm/attr.rb', line 102
def initialize(param, parent = nil)
@param = param.to_s
@parent = parent
@is_method = false
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/payload/arm/attr.rb', line 120
def method_missing(name, *args)
raise "cannot get attr of method" if @is_method
if args.size == 1 && args[0].is_a?(Symbol)
inner = Attr.new(name.to_s, self)
Attr.new(args[0].to_s, inner).call
else
Attr.new(name.to_s, self)
end
end
|
Instance Attribute Details
#param ⇒ Object
Returns the value of attribute param.
90
91
92
|
# File 'lib/payload/arm/attr.rb', line 90
def param
@param
end
|
#parent ⇒ Object
Returns the value of attribute parent.
90
91
92
|
# File 'lib/payload/arm/attr.rb', line 90
def parent
@parent
end
|
Class Method Details
.method_missing(name, *args) ⇒ Object
93
94
95
|
# File 'lib/payload/arm/attr.rb', line 93
def method_missing(name, *args)
new(name.to_s)
end
|
.respond_to_missing?(name, include_private = false) ⇒ Boolean
97
98
99
|
# File 'lib/payload/arm/attr.rb', line 97
def respond_to_missing?(name, include_private = false)
true
end
|
Instance Method Details
#!=(other) ⇒ Object
145
146
147
|
# File 'lib/payload/arm/attr.rb', line 145
def !=(other)
ARMNotEqual.new(self, other)
end
|
#<(other) ⇒ Object
153
154
155
|
# File 'lib/payload/arm/attr.rb', line 153
def <(other)
ARMLessThan.new(self, other)
end
|
#<=(other) ⇒ Object
161
162
163
|
# File 'lib/payload/arm/attr.rb', line 161
def <=(other)
ARMLessThanEqual.new(self, other)
end
|
#==(other) ⇒ Object
141
142
143
|
# File 'lib/payload/arm/attr.rb', line 141
def ==(other)
ARMEqual.new(self, other)
end
|
#>(other) ⇒ Object
149
150
151
|
# File 'lib/payload/arm/attr.rb', line 149
def >(other)
ARMGreaterThan.new(self, other)
end
|
#>=(other) ⇒ Object
157
158
159
|
# File 'lib/payload/arm/attr.rb', line 157
def >=(other)
ARMGreaterThanEqual.new(self, other)
end
|
#call ⇒ Object
Mark attribute as a function call (e.g. .month(), .sum())
136
137
138
139
|
# File 'lib/payload/arm/attr.rb', line 136
def call
@is_method = true
self
end
|
#contains(other) ⇒ Object
165
166
167
|
# File 'lib/payload/arm/attr.rb', line 165
def contains(other)
ARMContains.new(self, other)
end
|
#key ⇒ Object
108
109
110
|
# File 'lib/payload/arm/attr.rb', line 108
def key
@parent ? "#{@parent.key}[#{@param}]" : @param
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
131
132
133
|
# File 'lib/payload/arm/attr.rb', line 131
def respond_to_missing?(name, include_private = false)
true
end
|
#strip ⇒ Object
116
117
118
|
# File 'lib/payload/arm/attr.rb', line 116
def strip
to_s.strip
end
|
#to_s ⇒ Object
112
113
114
|
# File 'lib/payload/arm/attr.rb', line 112
def to_s
@is_method ? "#{@param}(#{@parent.key})" : key
end
|