Module: Console1984::Ext::Core::Module

Extended by:
ActiveSupport::Concern
Defined in:
lib/console1984/ext/core/module.rb

Overview

Extends Module to prevent invoking class_eval in user commands.

We don’t use the built-in configurable system from protections.yml because we use class_eval ourselves to implement it!

Instance Method Summary collapse

Instance Method Details

#instance_evalObject



8
9
10
11
12
13
14
# File 'lib/console1984/ext/core/module.rb', line 8

def instance_eval(*)
  if Console1984.command_executor.from_irb?(caller)
    raise Console1984::Errors::ForbiddenCommandAttempted
  else
    super
  end
end

#method_added(method) ⇒ Object



16
17
18
19
20
# File 'lib/console1984/ext/core/module.rb', line 16

def method_added(method)
  if Console1984.command_executor.from_irb?(caller) && banned_for_reopening?
    raise Console1984::Errors::ForbiddenCommandExecuted, "Trying to add method `#{method}` to #{self.name}"
  end
end