mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 15:22:58 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88fce1d679 | ||
|
|
ffd8476f74 | ||
|
|
728c5ccda5 | ||
|
|
4f0c81b6f8 |
@@ -1,3 +1,6 @@
|
||||
= 1.1.7 [2009-03-26]
|
||||
- Minor change to multiparameter attributes which I had not properly implemented for chaining
|
||||
|
||||
= 1.1.6 [2009-03-19]
|
||||
- Rail 2.3 support
|
||||
- Added :with_date and :with_time options. They allow an attribute to be combined with another attribute or value to make a datetime value for validation against the temporal restrictions
|
||||
|
||||
2
Rakefile
2
Rakefile
@@ -5,7 +5,7 @@ require 'date'
|
||||
require 'spec/rake/spectask'
|
||||
|
||||
GEM = "validates_timeliness"
|
||||
GEM_VERSION = "1.1.6"
|
||||
GEM_VERSION = "1.1.7"
|
||||
AUTHOR = "Adam Meehan"
|
||||
EMAIL = "adam.meehan@gmail.com"
|
||||
HOMEPAGE = "http://github.com/adzap/validates_timeliness"
|
||||
|
||||
@@ -16,18 +16,16 @@ module ValidatesTimeliness
|
||||
def execute_callstack_for_multiparameter_attributes_with_timeliness(callstack)
|
||||
errors = []
|
||||
callstack.each do |name, values|
|
||||
klass = (self.class.reflect_on_aggregation(name.to_sym) || column_for_attribute(name)).klass
|
||||
if values.empty?
|
||||
send(name + "=", nil)
|
||||
else
|
||||
column = column_for_attribute(name)
|
||||
column = column_for_attribute(name)
|
||||
if column && [:date, :time, :datetime].include?(column.type)
|
||||
begin
|
||||
value = if [:date, :time, :datetime].include?(column.type)
|
||||
time_array_to_string(values, column.type)
|
||||
callstack.delete(name)
|
||||
if values.empty?
|
||||
send("#{name}=", nil)
|
||||
else
|
||||
klass.new(*values)
|
||||
value = time_array_to_string(values, column.type)
|
||||
send("#{name}=", value)
|
||||
end
|
||||
send(name + "=", value)
|
||||
rescue => ex
|
||||
errors << ::ActiveRecord::AttributeAssignmentError.new("error on assignment #{values.inspect} to #{name}", ex, name)
|
||||
end
|
||||
@@ -36,10 +34,11 @@ module ValidatesTimeliness
|
||||
unless errors.empty?
|
||||
raise ::ActiveRecord::MultiparameterAssignmentErrors.new(errors), "#{errors.size} error(s) on assignment of multiparameter attributes"
|
||||
end
|
||||
execute_callstack_for_multiparameter_attributes_without_timeliness(callstack)
|
||||
end
|
||||
|
||||
def time_array_to_string(values, type)
|
||||
values = values.map(&:to_s)
|
||||
values = values.map {|v| v.to_s }
|
||||
|
||||
case type
|
||||
when :date
|
||||
@@ -57,7 +56,8 @@ module ValidatesTimeliness
|
||||
end
|
||||
|
||||
def extract_time_from_multiparameter_attributes(values)
|
||||
values.last(3).map { |s| s.rjust(2, "0") }.join(":")
|
||||
values = values.size > 3 ? values[3..5] : values
|
||||
values.map { |s| s.rjust(2, "0") }.join(":")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{validates_timeliness}
|
||||
s.version = "1.1.6"
|
||||
s.version = "1.1.7"
|
||||
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = ["Adam Meehan"]
|
||||
s.autorequire = %q{validates_timeliness}
|
||||
s.date = %q{2009-03-19}
|
||||
s.date = %q{2009-03-26}
|
||||
s.description = %q{Date and time validation plugin for Rails 2.x which allows custom formats}
|
||||
s.email = %q{adam.meehan@gmail.com}
|
||||
s.extra_rdoc_files = ["README.rdoc", "LICENSE", "TODO", "CHANGELOG"]
|
||||
|
||||
Reference in New Issue
Block a user