Class: HammerCLI::Validator::OneOfConstraint

Inherits:
BaseConstraint show all
Defined in:
lib/hammer_cli/validator.rb

Instance Attribute Summary

Attributes inherited from BaseConstraint

#rejected_msg

Instance Method Summary collapse

Methods inherited from BaseConstraint

#required

Constructor Details

#initialize(options, to_check) ⇒ OneOfConstraint

Returns a new instance of OneOfConstraint.



104
105
106
107
# File 'lib/hammer_cli/validator.rb', line 104

def initialize(options, to_check)
  raise 'Set at least one expected option' if to_check.empty?
  super(options, to_check)
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/hammer_cli/validator.rb', line 124

def exist?
  return count_present_options == 1
end

#rejectedObject

Raises:

  • (NotImplementedError)


109
110
111
# File 'lib/hammer_cli/validator.rb', line 109

def rejected
  raise NotImplementedError, '#rejected is unsupported for OneOfConstraint'
end

#required_msgObject



113
114
115
116
117
118
119
120
121
122
# File 'lib/hammer_cli/validator.rb', line 113

def required_msg
  case count_present_options
  when 0
    _("One of options %s is required")
  when 1
    ''
  else
    _("Only one of options %s can be set")
  end
end