Class: CypherBuilder::OrderBy

Inherits:
Object
  • Object
show all
Includes:
Resolver
Defined in:
lib/cypher_builder/order_by.rb

Instance Method Summary collapse

Methods included from Resolver

#resolve, #wrap

Constructor Details

#initialize(first, *rest) ⇒ OrderBy

Returns a new instance of OrderBy.



15
16
17
# File 'lib/cypher_builder/order_by.rb', line 15

def initialize(first, *rest)
  @parts = wrap(*([first] + rest))
end

Instance Method Details

#as_cypher(payload:, context:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cypher_builder/order_by.rb', line 19

def as_cypher(payload:, context:)
  rsv = MicroResolver.new(payload, context.add(self))
  
  ps = @parts.reduce([]) do |r, v|
    if r.last && AsIs === v
      r[0..-2] + [[r.last, rsv.execute(v)].join(' ')]
    else
      r + [rsv.execute(v)]
    end
  end
  sprintf('ORDER BY %s', ps.join(', '))
end