Class: Shellissimo::CommandParamValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/shellissimo/command_param_validator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/shellissimo/command_param_validator.rb', line 4

def block
  @block
end

#descriptionObject (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

.mandatoryObject



15
16
17
# File 'lib/shellissimo/command_param_validator.rb', line 15

def mandatory
  new("mandatory") { |v| !v.nil? }
end

.noopObject



7
8
9
# File 'lib/shellissimo/command_param_validator.rb', line 7

def noop
  new { |v| true }
end

.optionalObject



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