Class: Kumi::Core::Compiler::AccessBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/kumi/core/compiler/access_builder.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.yjitObject

Returns the value of attribute yjit.



6
7
8
# File 'lib/kumi/core/compiler/access_builder.rb', line 6

def yjit
  @yjit
end

Class Method Details

.build(plans, strategy: nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kumi/core/compiler/access_builder.rb', line 10

def self.build(plans, strategy: nil)
  strategy ||= yjit ? :interp : :codegen
  accessors = {}

  plans.each_value do |variants|
    variants.each do |plan|
      accessors[plan.accessor_key] =
        case strategy
        when :codegen then AccessCodegen.fetch_or_compile(plan)
        else
          build_proc_for(
            mode: plan.mode,
            path_key: plan.path,
            missing: (plan.on_missing || :error).to_sym,
            key_policy: (plan.key_policy || :indifferent).to_sym,
            operations: plan.operations
          )
        end
    end
  end
  accessors.freeze
end

.build_proc_for(mode:, path_key:, missing:, key_policy:, operations:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/kumi/core/compiler/access_builder.rb', line 33

def self.build_proc_for(mode:, path_key:, missing:, key_policy:, operations:)
  case mode
  when :read        then Accessors::ReadAccessor.build(operations, path_key, missing, key_policy)
  when :materialize then Accessors::MaterializeAccessor.build(operations, path_key, missing, key_policy)
  when :ravel       then Accessors::RavelAccessor.build(operations, path_key, missing, key_policy)
  when :each_indexed then Accessors::EachIndexedAccessor.build(operations, path_key, missing, key_policy, true)
  else
    raise "Unknown accessor mode: #{mode.inspect}"
  end
end