Class: HammerCLI::Validator::BaseConstraint
- Inherits:
-
Object
- Object
- HammerCLI::Validator::BaseConstraint
show all
- Defined in:
- lib/hammer_cli/validator.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options, to_check) ⇒ BaseConstraint
13
14
15
16
17
18
19
20
21
|
# 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
|
Instance Attribute Details
#rejected_msg ⇒ Object
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
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
|