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

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

Instance Method Summary collapse

Instance Method Details

#method_added(name) ⇒ Object

prevent accidental addition of new DSL keywords



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kumi/core/ruby_parser/guard_rails.rb', line 15

def method_added(name)
  if GuardRails::RESERVED.include?(name)
    # Check if this is a redefinition by looking at the call stack
    # We want to allow the original definition but prevent redefinition
    calling_location = caller_locations(1, 1).first

    # Allow the original definition from schema_builder.rb
    if calling_location&.path&.include?("schema_builder.rb")
      super
      return
    end

    # This is a redefinition attempt, prevent it
    raise Kumi::Core::Errors::SemanticError,
          "DSL keyword `#{name}` is reserved; " \
          "do not redefine it inside SchemaBuilder"
  end
  super
end