Class: MiniDefender::Rules::DateEq
Class Method Summary
collapse
Instance Method Summary
collapse
#active?, available?, #bails?, #coerce, #default_value, #defaults?, #error_message, #excluded?, #force_coerce?, #implicit?, #priority, #stops?, #with_message
Constructor Details
#initialize(target_date) ⇒ DateEq
Returns a new instance of DateEq.
6
7
8
9
|
# File 'lib/mini_defender/rules/date_eq.rb', line 6
def initialize(target_date)
@target_date = parse_date(target_date)
@valid_value = false
end
|
Class Method Details
.make(args) ⇒ Object
15
16
17
18
19
|
# File 'lib/mini_defender/rules/date_eq.rb', line 15
def self.make(args)
raise ArgumentError, 'Target date is required for date rules.' unless args.length == 1
self.new(args[0])
end
|
.signature ⇒ Object
11
12
13
|
# File 'lib/mini_defender/rules/date_eq.rb', line 11
def self.signature
'date_eq'
end
|
Instance Method Details
#message(attribute, value, validator) ⇒ Object
30
31
32
33
34
|
# File 'lib/mini_defender/rules/date_eq.rb', line 30
def message(attribute, value, validator)
return "The given value is not a valid date." unless @valid_value
"The value must be equal to #{@target_date}."
end
|
#passes?(attribute, value, validator) ⇒ Boolean
21
22
23
24
25
26
27
28
|
# File 'lib/mini_defender/rules/date_eq.rb', line 21
def passes?(attribute, value, validator)
value = parse_date(value)
@valid_value = true
value == @target_date
rescue ArgumentError
false
end
|