Class: Shellissimo::CommandParamValidator
- Inherits:
-
Object
- Object
- Shellissimo::CommandParamValidator
- Defined in:
- lib/shellissimo/command_param_validator.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object
- #call(value) ⇒ Object (also: #[])
-
#initialize(description = "", &block) ⇒ CommandParamValidator
constructor
A new instance of CommandParamValidator.
- #|(other) ⇒ Object
Constructor Details
#initialize(description = "", &block) ⇒ CommandParamValidator
Returns a new instance of CommandParamValidator.
20 21 22 23 24 |
# File 'lib/shellissimo/command_param_validator.rb', line 20 def initialize(description = "", &block) @description = description @block = block or raise ArgumentError, "command param validator block can't be blank" end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
4 5 6 |
# File 'lib/shellissimo/command_param_validator.rb', line 4 def block @block end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/shellissimo/command_param_validator.rb', line 4 def description @description end |
Class Method Details
.mandatory ⇒ Object
15 16 17 |
# File 'lib/shellissimo/command_param_validator.rb', line 15 def mandatory new("mandatory") { |v| !v.nil? } end |
.noop ⇒ Object
7 8 9 |
# File 'lib/shellissimo/command_param_validator.rb', line 7 def noop new { |v| true } end |
.optional ⇒ Object
11 12 13 |
# File 'lib/shellissimo/command_param_validator.rb', line 11 def optional new("optional") { |v| v.nil? } end |
Instance Method Details
#&(other) ⇒ Object
31 32 33 |
# File 'lib/shellissimo/command_param_validator.rb', line 31 def &(other) CommandParamValidator.new(description) { |value| block[value] && other.block[value] } end |
#call(value) ⇒ Object Also known as: []
26 27 28 |
# File 'lib/shellissimo/command_param_validator.rb', line 26 def call(value) @block.call(value) end |
#|(other) ⇒ Object
35 36 37 |
# File 'lib/shellissimo/command_param_validator.rb', line 35 def |(other) CommandParamValidator.new(description) { |value| block[value] || other.block[value] } end |