mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-24 23:06:42 +00:00
little cleanup and consistency
This commit is contained in:
parent
1001d29c01
commit
904c202fb4
@ -168,9 +168,9 @@ module ValidatesTimeliness
|
|||||||
exp, processor = expression_set(type, string).find do |regexp, proc|
|
exp, processor = expression_set(type, string).find do |regexp, proc|
|
||||||
full = /\A#{regexp}\Z/ if strict
|
full = /\A#{regexp}\Z/ if strict
|
||||||
full ||= case type
|
full ||= case type
|
||||||
when :datetime then /\A#{regexp}\Z/
|
|
||||||
when :date then /\A#{regexp}/
|
when :date then /\A#{regexp}/
|
||||||
else /#{regexp}\Z/
|
when :time then /#{regexp}\Z/
|
||||||
|
when :datetime then /\A#{regexp}\Z/
|
||||||
end
|
end
|
||||||
matches = full.match(string.strip)
|
matches = full.match(string.strip)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -111,13 +111,11 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
|
|
||||||
def error_messages
|
def error_messages
|
||||||
return @error_messages if defined?(@error_messages)
|
@error_messages ||= ValidatesTimeliness.default_error_messages.merge(custom_error_messages)
|
||||||
@error_messages = ValidatesTimeliness.default_error_messages.merge(custom_error_messages)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_error_messages
|
def custom_error_messages
|
||||||
return @custom_error_messages if defined?(@custom_error_messages)
|
@custom_error_messages ||= configuration.inject({}) {|msgs, (k, v)|
|
||||||
@custom_error_messages = configuration.inject({}) {|msgs, (k, v)|
|
|
||||||
if md = /(.*)_message$/.match(k.to_s)
|
if md = /(.*)_message$/.match(k.to_s)
|
||||||
msgs[md[1].to_sym] = v
|
msgs[md[1].to_sym] = v
|
||||||
end
|
end
|
||||||
|
|||||||
@ -35,7 +35,7 @@ describe ValidatesTimeliness::ActiveRecord::AttributeMethods do
|
|||||||
@person.birth_time
|
@person.birth_time
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should call rea_date_time_attribute when datetime attribute is retrieved" do
|
it "should call read_date_time_attribute when datetime attribute is retrieved" do
|
||||||
@person.should_receive(:read_date_time_attribute)
|
@person.should_receive(:read_date_time_attribute)
|
||||||
@person.birth_date_and_time = "2000-01-01 12:00"
|
@person.birth_date_and_time = "2000-01-01 12:00"
|
||||||
@person.birth_date_and_time
|
@person.birth_date_and_time
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user