Class: HammerCLI::Options::Validators::DSL::BaseConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/hammer_cli/options/validators/dsl.rb

Direct Known Subclasses

AllConstraint, AnyConstraint, OneOfConstraint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(option_definitions, option_values, to_check) ⇒ BaseConstraint

Returns a new instance of BaseConstraint.



8
9
10
11
12
13
14
15
16
17
# File 'lib/hammer_cli/options/validators/dsl.rb', line 8

def initialize(option_definitions, option_values, to_check)
  @to_check = to_check
  @rejected_msg = ""
  @required_msg = ""

  @option_values = option_values
  @options = option_definitions.inject({}) do |hash, opt|
    hash.update({opt.attribute_name => opt})
  end
end

Instance Attribute Details

#rejected_msgObject (readonly)

Returns the value of attribute rejected_msg.



6
7
8
# File 'lib/hammer_cli/options/validators/dsl.rb', line 6

def rejected_msg
  @rejected_msg
end

#required_msgObject (readonly)

Returns the value of attribute required_msg.



6
7
8
# File 'lib/hammer_cli/options/validators/dsl.rb', line 6

def required_msg
  @required_msg
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/hammer_cli/options/validators/dsl.rb', line 29

def exist?
  raise NotImplementedError
end

#rejected(args = {}) ⇒ Object



19
20
21
22
# File 'lib/hammer_cli/options/validators/dsl.rb', line 19

def rejected(args={})
  msg = args[:msg] || rejected_msg % option_switches.join(", ")
  raise HammerCLI::Options::Validators::ValidationError.new(msg) if exist?
end

#required(args = {}) ⇒ Object



24
25
26
27
# File 'lib/hammer_cli/options/validators/dsl.rb', line 24

def required(args={})
  msg = args[:msg] || required_msg % option_switches.join(", ")
  raise HammerCLI::Options::Validators::ValidationError.new(msg) unless exist?
end