Class: Chewy::Index::Compiled::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/chewy/index/compiled.rb

Constant Summary collapse

IDENTIFIER_RE =
/\A[A-Za-z_][A-Za-z0-9_]*[!?=]?\z/

Instance Method Summary collapse

Constructor Details

#initialize(index, fields: [], method_name: :__chewy_compose__) ⇒ Compiler

Returns a new instance of Compiler.



108
109
110
111
112
113
114
# File 'lib/chewy/index/compiled.rb', line 108

def initialize(index, fields: [], method_name: :__chewy_compose__)
  @index       = index
  @procs       = index.compiled_procs
  @counter     = 0
  @fields      = fields.map(&:to_sym)
  @method_name = method_name
end

Instance Method Details

#buildObject



116
117
118
119
120
121
122
123
124
# File 'lib/chewy/index/compiled.rb', line 116

def build
  check_root_value!(@index.root)
  body = compose_children_src(@index.root, 'o0', restrict: @fields)
  <<~RUBY
    def self.#{@method_name}(o0, crutches, context)
      #{body}.as_json
    end
  RUBY
end