Class: TurboBoost::Commands::CommandValidator
- Inherits:
-
Object
- Object
- TurboBoost::Commands::CommandValidator
- Defined in:
- lib/turbo_boost/commands/command_validator.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
Instance Method Summary collapse
-
#initialize(command, method_name) ⇒ CommandValidator
constructor
A new instance of CommandValidator.
- #validate ⇒ Object (also: #valid?)
- #validate! ⇒ Object
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
#command ⇒ Object (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_name ⇒ Object (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
#validate ⇒ Object 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! = "`#{command.class.name}` is not a subclass of `#{TurboBoost::Commands::Command.name}`!" raise TurboBoost::Commands::InvalidClassError.new(, command: command.class) unless valid_class? = "`#{command.class.name}` does not define the public method `#{method_name}`!" raise TurboBoost::Commands::InvalidMethodError.new(, command: command.class) unless valid_method? true end |