Class: OrientSupport::MatchStatement

Inherits:
Object
  • Object
show all
Includes:
Support
Defined in:
lib/support/orientquery.rb

Overview

class

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.


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/support/orientquery.rb', line 105

def initialize match_class=nil, **args
	reduce_class = ->(c){ c.is_a?(Class) ? c.ref_name : c.to_s }
    @misc  = []
    @where = []
    @while = []
    @maxdepth = 0
    @as =  nil


    @match_class = reduce_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 = reduce_class[v]

			@as = @match_class.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


163
164
165
# File 'lib/support/orientquery.rb', line 163

def method_missing method, *arg, &b
	@misc << method.to_s <<  generate_sql_list(arg) 
end

Instance Attribute Details

#asObject

Returns the value of attribute as


104
105
106
# File 'lib/support/orientquery.rb', line 104

def as
  @as
end

Instance Method Details

#composeObject Also known as: to_s


175
176
177
178
179
180
# File 'lib/support/orientquery.rb', line 175

def compose

	'{'+ [ "class: #{@match_class}", 
			"as: #{@as}" , where, while_s, 
				@maxdepth >0 ? "maxdepth: #{maxdepth}": nil  ].compact.join(', ')+'}'
end

#compose_simpleObject

used for the first compose-statement of a compose-query


171
172
173
# File 'lib/support/orientquery.rb', line 171

def compose_simple
	'{'+ [ "class: #{@match_class}", "as: #{@as}" , where ].compact.join(', ') + '}'
end

#match_aliasObject


136
137
138
# File 'lib/support/orientquery.rb', line 136

def match_alias
	"as: #{@as }"
end

#maxdepth=(x) ⇒ Object


159
160
161
# File 'lib/support/orientquery.rb', line 159

def maxdepth=x
	@maxdepth = x
end

#miscObject


167
168
169
# File 'lib/support/orientquery.rb', line 167

def misc
	@misc.join(' ') unless @misc.empty?
end

#where(value = nil) ⇒ Object

alias while while_s


150
151
152
153
154
155
156
157
# File 'lib/support/orientquery.rb', line 150

def where  value=nil
		if value.present?
			@where << value
			self
		elsif @where.present?
			"where: ( #{ generate_sql_list( @where ) }) "
		end
end

#while_s(value = nil) ⇒ Object


139
140
141
142
143
144
145
146
# File 'lib/support/orientquery.rb', line 139

def while_s  value=nil
		if value.present?
			@while << value
			self
		elsif @while.present?
			"while: ( #{ generate_sql_list( @where ) }) "
		end
end