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

Raises:

  • (KeyError)


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

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

  @compiled_module.public_send(method_name, @input)
end

#from(new_input) ⇒ Object



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

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

#update(new_input) ⇒ Object



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

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