Module: Kumi::Core::RubyParser::GuardRails

Included in:
SchemaBuilder
Defined in:
lib/kumi/core/ruby_parser/guard_rails.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

RESERVED =
%i[input trait value fn lit ref].freeze

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *_args) ⇒ Object

catch any stray method call inside DSL block



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

def method_missing(name, *_args)
  raise_syntax_error(
    "unknown DSL keyword `#{name}`. Valid top-level keywords are: " \
    "input, value, let, trait, ref, fn, literal, select, index, import, codegen.",
    location: guard_rails_caller_location
  )
end

Class Method Details

.included(base) ⇒ Object



9
10
11
# File 'lib/kumi/core/ruby_parser/guard_rails.rb', line 9

def self.included(base)
  base.singleton_class.prepend(ClassMethods)
end

Instance Method Details

#guard_rails_caller_locationObject

The user’s DSL line that triggered the stray call. Stray keywords can fire before any DSL method set @context.current_location, so we read the caller stack directly instead of trusting the stored location.



48
49
50
51
52
53
# File 'lib/kumi/core/ruby_parser/guard_rails.rb', line 48

def guard_rails_caller_location
  frame = caller_locations(2).find { |f| !f.path.to_s.include?("ruby_parser") }
  return nil unless frame

  Kumi::Syntax::Location.new(file: frame.path, line: frame.lineno, column: 0)
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


55
# File 'lib/kumi/core/ruby_parser/guard_rails.rb', line 55

def respond_to_missing?(*) = false