Class: Kumi::CompiledSchemaWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/kumi/schema.rb

Overview

Thin wrapper providing backward-compatible interface for pure module functions. The compiled module now contains only module-level functions (def self._name(input)), but users expect an instance-like interface with .from(), .update(), []. This wrapper bridges that gap.

Instance Method Summary collapse

Constructor Details

#initialize(compiled_module, input_data) ⇒ CompiledSchemaWrapper

Returns a new instance of CompiledSchemaWrapper.



13
14
15
16
# File 'lib/kumi/schema.rb', line 13

def initialize(compiled_module, input_data)
  @compiled_module = compiled_module
  @input = input_data
end

Instance Method Details

#[](declaration_name) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/kumi/schema.rb', line 18

def [](declaration_name)
  method_name = "_#{declaration_name}"
  unless @compiled_module.respond_to?(method_name)
    raise KeyError, "Unknown declaration: #{declaration_name}"
  end
  @compiled_module.public_send(method_name, @input)
end

#from(new_input) ⇒ Object



31
32
33
# File 'lib/kumi/schema.rb', line 31

def from(new_input)
  CompiledSchemaWrapper.new(@compiled_module, new_input)
end

#update(new_input) ⇒ Object



26
27
28
29
# File 'lib/kumi/schema.rb', line 26

def update(new_input)
  @input = @input.merge(new_input)
  self
end