Class: OrientSupport::MatchConnection

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

Overview

where and while can be composed incremental direction, as, connect and edge cannot be changed after initialisation

Instance Method Summary collapse

Methods included from Support

#as, #compose_where, #generate_sql_list, #where, #while_s

Constructor Details

#initialize(edge = nil, direction: :both, as: nil, count: 1, **args) ⇒ MatchConnection

Returns a new instance of MatchConnection.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/support/orientquery.rb', line 115

def initialize edge= nil, direction: :both, as: nil, count: 1, **args

  the_edge = edge.is_a?( Class ) ?  edge.ref_name : edge.to_s   unless edge.nil? || edge == E
      @q =  MatchAttributes.new  the_edge ,  # class
        direction, #      may be :both, :in, :out
        as,        #      a string
        count,     #      a number 
        args[:where],
        args[:while],
        args[:max_depth],
        args[:depth_alias],      # not implemented
        args[:path_alias],       # not implemented
        args[:optional]          # not implemented
end

Instance Method Details

#composeObject Also known as: to_s



179
180
181
182
183
184
185
186
187
188
# File 'lib/support/orientquery.rb', line 179

def compose
where_statement =( where.nil? || where.size <5 ) ? nil : "where: ( #{ generate_sql_list( @q[:where] ) })"
while_statement =( while_s.nil? || while_s.size <5) ? nil : "while: ( #{ generate_sql_list( @q[:while] )})"

ministatement = "{"+ [ as, where_statement, while_statement, max_depth].compact.join(', ') + "}"
ministatement = "" if ministatement=="{}"

 (1 .. count).map{|x| direction }.join("") + ministatement

end

#count(c = nil) ⇒ Object



160
161
162
163
164
165
166
# File 'lib/support/orientquery.rb', line 160

def count c=nil
  if c
    @q[:count] = c
  else
    @q[:count]
  end
end

#directionObject



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/support/orientquery.rb', line 135

def direction
  fillup =  @q[:edge].present? ? @q[:edge] : ''
  case @q[:direction]
  when :both
    ".both(#{fillup})"
  when :in
    ".in(#{fillup})"
  when :out
    ".out(#{fillup})"
    when :both_vertex, :bothV
    ".bothV()"
  when :out_vertex, :outV
    ".outV()"
  when :in_vertex, :inV
    ".inV()"
   when :both_edge, :bothE
   ".bothE(#{fillup})"
  when :out_edge, :outE
    ".outE(#{fillup})"
  when :in_edge, :outE
    ".inE(#{fillup})"
  end

end

#direction=(dir) ⇒ Object



130
131
132
# File 'lib/support/orientquery.rb', line 130

def direction= dir
  @q[:direction] =  dir
end

#edgeObject



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

def edge
  @q[:edge]
end

#max_depth(d = nil) ⇒ Object



168
169
170
171
172
173
174
# File 'lib/support/orientquery.rb', line 168

def max_depth d=nil
  if d.nil?
    @q[:max_depth].present? ? "maxDepth: #{@q[:max_depth] }" : nil
  else
    @q[:max_depth] = d
  end
end