Class: Console1984::CommandValidator::ForbiddenReopeningValidation

Inherits:
Object
  • Object
show all
Includes:
Freezeable
Defined in:
lib/console1984/command_validator/forbidden_reopening_validation.rb

Overview

Validates attempts to reopen classes and modules based on a configured set.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Freezeable

freeze_all, included

Constructor Details

#initialize(banned_classes_or_modules) ⇒ ForbiddenReopeningValidation

Returns a new instance of ForbiddenReopeningValidation.



7
8
9
# File 'lib/console1984/command_validator/forbidden_reopening_validation.rb', line 7

def initialize(banned_classes_or_modules)
  @banned_class_or_module_names = banned_classes_or_modules.collect(&:to_s)
end

Instance Attribute Details

#banned_class_or_module_namesObject (readonly)

Returns the value of attribute banned_class_or_module_names.



5
6
7
# File 'lib/console1984/command_validator/forbidden_reopening_validation.rb', line 5

def banned_class_or_module_names
  @banned_class_or_module_names
end

Instance Method Details

#validate(parsed_command) ⇒ Object

Raises a Console1984::Errors::ForbiddenCommandAttempted if an banned class or module reopening is detected.



13
14
15
16
17
# File 'lib/console1984/command_validator/forbidden_reopening_validation.rb', line 13

def validate(parsed_command)
  if contains_invalid_class_or_module_declaration?(parsed_command)
    raise Console1984::Errors::ForbiddenCommandAttempted
  end
end