Class: OrientSupport::MatchStatement
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.
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/support/orientquery.rb', line 102
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
145
146
147
|
# File 'lib/support/orientquery.rb', line 145
def method_missing method, *arg, &b
@misc << method.to_s << generate_sql_list(arg)
end
|
Instance Attribute Details
Returns the value of attribute as.
100
101
102
|
# File 'lib/support/orientquery.rb', line 100
def as
@as
end
|
Returns the value of attribute where.
101
102
103
|
# File 'lib/support/orientquery.rb', line 101
def where
@where
end
|
Instance Method Details
#compose ⇒ Object
Also known as:
to_s
159
160
161
162
163
164
165
166
|
# File 'lib/support/orientquery.rb', line 159
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
153
154
155
156
157
|
# File 'lib/support/orientquery.rb', line 153
def compose_simple
'{'+ [ "class: #{@match_class}",
"as: #{@as}" ,
where_s ].compact.join(', ') + '}'
end
|
#match_alias ⇒ Object
134
135
136
|
# File 'lib/support/orientquery.rb', line 134
def match_alias
"as: #{@as }"
end
|
#maxdepth=(x) ⇒ Object
141
142
143
|
# File 'lib/support/orientquery.rb', line 141
def maxdepth=x
@maxdepth = x
end
|
149
150
151
|
# File 'lib/support/orientquery.rb', line 149
def misc
@misc.join(' ') unless @misc.empty?
end
|
137
138
139
|
# File 'lib/support/orientquery.rb', line 137
def where_s
compose_where( @where ).gsub( /where/, 'where:(' )<< ")" unless @where.blank?
end
|
130
131
132
|
# File 'lib/support/orientquery.rb', line 130
def while_s
compose_where( @while ).gsub( /where/, 'while:(' )<< ")" unless @while.blank?
end
|