Class: Kumi::Core::RubyParser::InputBuilder

Inherits:
Object
  • Object
show all
Includes:
ErrorReporting, Syntax
Defined in:
lib/kumi/core/ruby_parser/input_builder.rb

Instance Method Summary collapse

Methods included from ErrorReporting

#inferred_location, #raise_localized_error, #raise_syntax_error, #raise_type_error, #report_enhanced_error, #report_error, #report_semantic_error, #report_syntax_error, #report_type_error

Constructor Details

#initialize(context) ⇒ InputBuilder

Returns a new instance of InputBuilder.



10
11
12
# File 'lib/kumi/core/ruby_parser/input_builder.rb', line 10

def initialize(context)
  @context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *_args) ⇒ Object



46
47
48
49
50
# File 'lib/kumi/core/ruby_parser/input_builder.rb', line 46

def method_missing(method_name, *_args)
  allowed_methods = "'key', 'integer', 'float', 'decimal', 'string', 'boolean', 'any', 'scalar', 'array', 'hash', and 'element'"
  raise_syntax_error("Unknown method '#{method_name}' in input block. Only #{allowed_methods} are allowed.",
                     location: @context.current_location)
end

Instance Method Details

#array(name_or_elem_type, **kwargs) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/kumi/core/ruby_parser/input_builder.rb', line 26

def array(name_or_elem_type, **kwargs, &)
  if block_given?
    create_array_field_with_block(name_or_elem_type, kwargs, &)
  elsif kwargs.any?
    create_array_field(name_or_elem_type, kwargs)
  else
    Kumi::Core::Types.array(name_or_elem_type)
  end
end

#hash(name_or_key_type, val_type = nil, **kwargs) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/kumi/core/ruby_parser/input_builder.rb', line 36

def hash(name_or_key_type, val_type = nil, **kwargs, &)
  if block_given?
    create_hash_field_with_block(name_or_key_type, kwargs, &)
  elsif val_type.nil?
    create_hash_field(name_or_key_type, kwargs)
  else
    Kumi::Core::Types.hash(name_or_key_type, val_type)
  end
end

#key(name, type: :any, domain: nil) ⇒ Object



14
15
16
17
# File 'lib/kumi/core/ruby_parser/input_builder.rb', line 14

def key(name, type: :any, domain: nil)
  normalized_type = normalize_type(type, name)
  @context.inputs << Kumi::Syntax::InputDeclaration.new(name, domain, normalized_type, [], nil, loc: @context.current_location)
end

#respond_to_missing?(_method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/kumi/core/ruby_parser/input_builder.rb', line 52

def respond_to_missing?(_method_name, _include_private = false)
  false
end