class HammerCLI::Validator::BaseConstraint
Attributes
rejected_msg[R]
required_msg[R]
Public Class Methods
new(options, to_check)
click to toggle source
# File lib/hammer_cli/validator.rb, line 13 def initialize(options, to_check) @to_check = to_check @rejected_msg = "" @required_msg = "" @options = options.inject({}) do |hash, opt| hash.update({opt.attribute.attribute_name => opt}) end end
Public Instance Methods
exist?()
click to toggle source
# File lib/hammer_cli/validator.rb, line 33 def exist? raise NotImplementedError end
rejected(args={})
click to toggle source
# File lib/hammer_cli/validator.rb, line 23 def rejected(args={}) msg = args[:msg] || rejected_msg % option_switches.join(", ") raise ValidationError.new(msg) if exist? end
required(args={})
click to toggle source
# File lib/hammer_cli/validator.rb, line 28 def required(args={}) msg = args[:msg] || required_msg % option_switches.join(", ") raise ValidationError.new(msg) unless exist? end
Protected Instance Methods
get_option(name)
click to toggle source
# File lib/hammer_cli/validator.rb, line 39 def get_option(name) name = name.to_s raise _("Unknown option name '%s'") % name unless @options.has_key? name @options[name] end
option_passed?(option_name)
click to toggle source
# File lib/hammer_cli/validator.rb, line 45 def option_passed?(option_name) !get_option(option_name).get.nil? end
option_switches(opts=nil)
click to toggle source
# File lib/hammer_cli/validator.rb, line 49 def option_switches(opts=nil) opts ||= @to_check opts.collect do |option_name| get_option(option_name).attribute.long_switch || get_option(option_name).attribute.switches.first end end