class HammerCLI::Options::Validators::DSL::OneOfConstraint

Public Class Methods

new(options, option_values, to_check) click to toggle source
# File lib/hammer_cli/options/validators/dsl.rb, line 101
def initialize(options, option_values, to_check)
  raise 'Set at least one expected option' if to_check.empty?
  super
end

Public Instance Methods

exist?() click to toggle source
# File lib/hammer_cli/options/validators/dsl.rb, line 121
def exist?
  return count_present_options == 1
end
rejected() click to toggle source
# File lib/hammer_cli/options/validators/dsl.rb, line 106
def rejected
  raise NotImplementedError, '#rejected is unsupported for OneOfConstraint'
end
required_msg() click to toggle source
# File lib/hammer_cli/options/validators/dsl.rb, line 110
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

Protected Instance Methods

count_present_options() click to toggle source
# File lib/hammer_cli/options/validators/dsl.rb, line 126
def count_present_options
  @to_check.count do |opt|
    option_passed?(opt)
  end
end