Class: HammerCLI::Validator::BaseConstraint
- Inherits:
-
Object
- Object
- HammerCLI::Validator::BaseConstraint
- Defined in:
- lib/hammer_cli/validator.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(options, to_check) ⇒ BaseConstraint
constructor
A new instance of BaseConstraint.
- #rejected(args = {}) ⇒ Object
- #required(args = {}) ⇒ Object
Constructor Details
#initialize(options, to_check) ⇒ BaseConstraint
Returns a new instance of BaseConstraint.
13 14 15 16 17 18 19 20 21 |
# File 'lib/hammer_cli/validator.rb', line 13 def initialize(, to_check) @to_check = to_check @rejected_msg = "" @required_msg = "" @options = .inject({}) do |hash, opt| hash.update({opt.attribute.attribute_name => opt}) end end |
Instance Attribute Details
#rejected_msg ⇒ Object (readonly)
Returns the value of attribute rejected_msg.
11 12 13 |
# File 'lib/hammer_cli/validator.rb', line 11 def rejected_msg @rejected_msg end |
#required_msg ⇒ Object (readonly)
Returns the value of attribute required_msg.
11 12 13 |
# File 'lib/hammer_cli/validator.rb', line 11 def required_msg @required_msg end |
Instance Method Details
#exist? ⇒ Boolean
33 34 35 |
# File 'lib/hammer_cli/validator.rb', line 33 def exist? raise NotImplementedError end |
#rejected(args = {}) ⇒ Object
23 24 25 26 |
# 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 = {}) ⇒ Object
28 29 30 31 |
# 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 |