Class: TurboBoost::Commands::CommandValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_boost/commands/command_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, method_name) ⇒ CommandValidator

Returns a new instance of CommandValidator.



4
5
6
7
# File 'lib/turbo_boost/commands/command_validator.rb', line 4

def initialize(command, method_name)
  @command = command
  @method_name = method_name.to_sym
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



9
10
11
# File 'lib/turbo_boost/commands/command_validator.rb', line 9

def command
  @command
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



9
10
11
# File 'lib/turbo_boost/commands/command_validator.rb', line 9

def method_name
  @method_name
end

Instance Method Details

#validateObject Also known as: valid?



11
12
13
# File 'lib/turbo_boost/commands/command_validator.rb', line 11

def validate
  valid_class? && valid_method?
end

#validate!Object



16
17
18
19
20
21
22
23
24
# File 'lib/turbo_boost/commands/command_validator.rb', line 16

def validate!
  message = "`#{command.class.name}` is not a subclass of `#{TurboBoost::Commands::Command.name}`!"
  raise TurboBoost::Commands::InvalidClassError.new(message, command: command.class) unless valid_class?

  message = "`#{command.class.name}` does not define the public method `#{method_name}`!"
  raise TurboBoost::Commands::InvalidMethodError.new(message, command: command.class) unless valid_method?

  true
end