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.
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/support.rb', line 95
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
138
139
140
|
# File 'lib/support.rb', line 138
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.
93
94
95
|
# File 'lib/support.rb', line 93
def as
@as
end
|
#where ⇒ Object
Returns the value of attribute where.
94
95
96
|
# File 'lib/support.rb', line 94
def where
@where
end
|
Instance Method Details
#compose ⇒ Object
Also known as:
to_s
152
153
154
155
156
157
158
159
|
# File 'lib/support.rb', line 152
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
146
147
148
149
150
|
# File 'lib/support.rb', line 146
def compose_simple
'{'+ [ "class: #{@match_class}",
"as: #{@as}" ,
where_s ].compact.join(', ') + '}'
end
|
#match_alias ⇒ Object
127
128
129
|
# File 'lib/support.rb', line 127
def match_alias
"as: #{@as }"
end
|
#maxdepth=(x) ⇒ Object
134
135
136
|
# File 'lib/support.rb', line 134
def maxdepth=x
@maxdepth = x
end
|
#misc ⇒ Object
142
143
144
|
# File 'lib/support.rb', line 142
def misc
@misc.join(' ') unless @misc.empty?
end
|
#where_s ⇒ Object
130
131
132
|
# File 'lib/support.rb', line 130
def where_s
compose_where( @where ).gsub( /where/, 'where:(' )<< ")" unless @where.blank?
end
|
#while_s ⇒ Object
123
124
125
|
# File 'lib/support.rb', line 123
def while_s
compose_where( @while ).gsub( /where/, 'while:(' )<< ")" unless @while.blank?
end
|