Class: MiniDefender::Rules::AcceptedIf
- Inherits:
-
Accepted
- Object
- MiniDefender::Rule
- Accepted
- MiniDefender::Rules::AcceptedIf
- Defined in:
- lib/mini_defender/rules/accepted_if.rb
Constant Summary
Constants inherited from Accepted
MiniDefender::Rules::Accepted::ALLOWED_VALUES
Class Method Summary collapse
Instance Method Summary collapse
- #active?(validator) ⇒ Boolean
-
#initialize(target, value) ⇒ AcceptedIf
constructor
A new instance of AcceptedIf.
Methods inherited from Accepted
Methods inherited from MiniDefender::Rule
available?, #bails?, #coerce, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, #message, #passes?, #priority, #stops?, #with_message
Constructor Details
#initialize(target, value) ⇒ AcceptedIf
Returns a new instance of AcceptedIf.
6 7 8 9 10 11 |
# File 'lib/mini_defender/rules/accepted_if.rb', line 6 def initialize(target, value) raise ArgumentError, 'Target must be a string' unless target.is_a?(String) @target = target @value = value end |
Class Method Details
.make(args) ⇒ Object
17 18 19 20 21 |
# File 'lib/mini_defender/rules/accepted_if.rb', line 17 def self.make(args) raise ArgumentError, 'Target and expected value are required.' unless args.length == 2 self.new(args[0], args[1]) end |
.signature ⇒ Object
13 14 15 |
# File 'lib/mini_defender/rules/accepted_if.rb', line 13 def self.signature 'accepted_if' end |
Instance Method Details
#active?(validator) ⇒ Boolean
23 24 25 |
# File 'lib/mini_defender/rules/accepted_if.rb', line 23 def active?(validator) validator.data[@target] === @value end |