Class: HammerCLI::Options::Validators::DSL::BaseConstraint
- Inherits:
-
Object
- Object
- HammerCLI::Options::Validators::DSL::BaseConstraint
- Defined in:
- lib/hammer_cli/options/validators/dsl.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#rejected_msg ⇒ Object
readonly
Returns the value of attribute rejected_msg.
-
#required_msg ⇒ Object
readonly
Returns the value of attribute required_msg.
Instance Method Summary collapse
- #exist? ⇒ Boolean
-
#initialize(option_definitions, option_values, to_check) ⇒ BaseConstraint
constructor
A new instance of BaseConstraint.
- #rejected(args = {}) ⇒ Object
- #required(args = {}) ⇒ Object
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_msg ⇒ Object (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_msg ⇒ Object (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
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 |