Class: OrientSupport::MatchStatement
- Inherits:
-
Object
- Object
- OrientSupport::MatchStatement
show all
- Includes:
- Support
- Defined in:
- lib/support.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Support
#compose_where, #generate_sql_list
Constructor Details
#initialize(match_class = nil, **args) ⇒ MatchStatement
Returns a new instance of MatchStatement.
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/support.rb', line 99
def initialize match_class=nil, **args
@misc = []
@where = []
@while = []
@maxdepth = 0
@as = nil
@match_class = match_class
@as = match_class.pluralize if match_class.is_a? String
args.each do |k, v|
case k
when :as
@as = v
when :while
@while << v
when :where
@where << v
when :class
@match_class = v
@as = v.pluralize
else
self.send k, v
end
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arg, &b) ⇒ Object
142
143
144
|
# File 'lib/support.rb', line 142
def method_missing method, *arg, &b
@misc << method.to_s << " " << arg.map(&:to_s).join(' ')
end
|
Instance Attribute Details
#as ⇒ Object
Returns the value of attribute as.
97
98
99
|
# File 'lib/support.rb', line 97
def as
@as
end
|
#where ⇒ Object
Returns the value of attribute where.
98
99
100
|
# File 'lib/support.rb', line 98
def where
@where
end
|
Instance Method Details
#compose ⇒ Object
Also known as:
to_s
156
157
158
159
160
161
162
163
|
# File 'lib/support.rb', line 156
def compose
'{'+ [ "class: #{@match_class}",
"as: #{@as}" ,
where_s,
while_s,
@maxdepth >0 ? "maxdepth: #{maxdepth}": nil ].compact.join(', ')+'}'
end
|
#compose_simple ⇒ Object
used for the first compose-statement of a compose-query
150
151
152
153
154
|
# File 'lib/support.rb', line 150
def compose_simple
'{'+ [ "class: #{@match_class}",
"as: #{@as}" ,
where_s ].compact.join(', ') + '}'
end
|
#match_alias ⇒ Object
131
132
133
|
# File 'lib/support.rb', line 131
def match_alias
"as: #{@as }"
end
|
#maxdepth=(x) ⇒ Object
138
139
140
|
# File 'lib/support.rb', line 138
def maxdepth=x
@maxdepth = x
end
|
#misc ⇒ Object
146
147
148
|
# File 'lib/support.rb', line 146
def misc
@misc.join(' ') unless @misc.empty?
end
|
#where_s ⇒ Object
134
135
136
|
# File 'lib/support.rb', line 134
def where_s
compose_where( @where ).gsub( /where/, 'where:(' )<< ")" unless @where.blank?
end
|
#while_s ⇒ Object
127
128
129
|
# File 'lib/support.rb', line 127
def while_s
compose_where( @while ).gsub( /where/, 'while:(' )<< ")" unless @while.blank?
end
|