Class: Cyrel::AST::ClauseAdapter

Inherits:
Clause::Base show all
Defined in:
lib/cyrel/ast/clause_adapter.rb

Overview

Adapter that allows AST nodes to work with the existing clause-based system Now with simple caching for performance

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ast_node) ⇒ ClauseAdapter

Returns a new instance of ClauseAdapter.



10
11
12
13
# File 'lib/cyrel/ast/clause_adapter.rb', line 10

def initialize(ast_node)
  @ast_node = ast_node
  super()
end

Instance Attribute Details

#ast_nodeObject (readonly)

Returns the value of attribute ast_node.



8
9
10
# File 'lib/cyrel/ast/clause_adapter.rb', line 8

def ast_node
  @ast_node
end

Instance Method Details

#deconstructObject

Ruby 3.0+ pattern matching support



23
24
25
# File 'lib/cyrel/ast/clause_adapter.rb', line 23

def deconstruct
  [ast_node]
end

#deconstruct_keys(_keys) ⇒ Object



27
28
29
# File 'lib/cyrel/ast/clause_adapter.rb', line 27

def deconstruct_keys(_keys)
  { ast_node: ast_node, type: ast_node.class }
end

#render(query) ⇒ Object



15
16
17
18
19
20
# File 'lib/cyrel/ast/clause_adapter.rb', line 15

def render(query)
  # Create a compiler that delegates parameter registration to the query
  compiler = QueryIntegratedCompiler.new(query)
  compiler.compile(ast_node)
  compiler.output.string
end