mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-22 22:06:45 +00:00
version 2.1
This commit is contained in:
parent
9b300e084b
commit
75a3b2bd83
@ -1,9 +1,8 @@
|
||||
= github/master
|
||||
- Dramatically simplified ActiveRecord monkey patching and hackery
|
||||
- Removed read_attribute override, which was a bit brutal
|
||||
- Removed attribute reader method override
|
||||
- Removed dirty attribute handling, now just uses regular AR way
|
||||
= 2.1.0 [2009-06-20]
|
||||
- Added ambiguous year threshold setting in Formats class to customize the threshold for 2 digit years (See README)
|
||||
- Fixed interpolation values in custom error message for Rails 2.2+
|
||||
- Fixed custom I18n local override of en locale
|
||||
- Dramatically simplified ActiveRecord monkey patching and hackery
|
||||
|
||||
= 2.0.0 [2009-04-12]
|
||||
- Error value formats are now specified in the i18n locale file instead of updating plugin hash. See OTHER CUSTOMISATION section in README.
|
||||
|
||||
2
Rakefile
2
Rakefile
@ -34,7 +34,7 @@ task :default => :spec
|
||||
desc "Run specs"
|
||||
Spec::Rake::SpecTask.new do |t|
|
||||
t.spec_files = FileList['spec/**/*_spec.rb']
|
||||
t.spec_opts = %w(-fs --color)
|
||||
t.spec_opts = %w(--color)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@ -6,12 +6,12 @@ module ValidatesTimeliness
|
||||
|
||||
module ActiveRecord
|
||||
|
||||
# Overrides write method for date, time and datetime columns
|
||||
# to use plugin parser. Also adds mechanism to store value
|
||||
# before type cast.
|
||||
#
|
||||
module AttributeMethods
|
||||
|
||||
# Overrides write method for date, time and datetime columns
|
||||
# to use plugin parser. Also adds mechanism to store value
|
||||
# before type cast.
|
||||
#
|
||||
def self.included(base)
|
||||
base.extend ClassMethods
|
||||
base.class_eval do
|
||||
@ -44,8 +44,9 @@ module ValidatesTimeliness
|
||||
|
||||
def define_attribute_methods_with_timeliness
|
||||
return if generated_methods?
|
||||
columns_hash.each do |name, column|
|
||||
timeliness_methods = []
|
||||
|
||||
columns_hash.each do |name, column|
|
||||
if [:date, :time, :datetime].include?(column.type)
|
||||
time_zone_aware = create_time_zone_conversion_attribute?(name, column) rescue false
|
||||
|
||||
@ -54,10 +55,12 @@ module ValidatesTimeliness
|
||||
write_date_time_attribute('#{name}', value, #{column.type.inspect}, #{time_zone_aware})
|
||||
end
|
||||
EOV
|
||||
timeliness_methods << name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
define_attribute_methods_without_timeliness
|
||||
@generated_methods += timeliness_methods
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -11,8 +11,8 @@ module ValidatesTimeliness
|
||||
base.alias_method_chain :execute_callstack_for_multiparameter_attributes, :timeliness
|
||||
end
|
||||
|
||||
# Overrides AR method to store multiparameter time and dates as string
|
||||
# allowing validation later.
|
||||
# Assign dates and times as formatted strings to force the use of the plugin parser
|
||||
# and store a before_type_cast value for attribute
|
||||
def execute_callstack_for_multiparameter_attributes_with_timeliness(callstack)
|
||||
errors = []
|
||||
callstack.each do |name, values|
|
||||
@ -46,18 +46,17 @@ module ValidatesTimeliness
|
||||
when :time
|
||||
extract_time_from_multiparameter_attributes(values)
|
||||
when :datetime
|
||||
date_values, time_values = values.slice!(0, 3), values
|
||||
extract_date_from_multiparameter_attributes(date_values) + " " + extract_time_from_multiparameter_attributes(time_values)
|
||||
extract_date_from_multiparameter_attributes(values) + " " + extract_time_from_multiparameter_attributes(values)
|
||||
end
|
||||
end
|
||||
|
||||
def extract_date_from_multiparameter_attributes(values)
|
||||
[values[0], *values.slice(1, 2).map { |s| s.rjust(2, "0") }].join("-")
|
||||
year = ValidatesTimeliness::Formats.unambiguous_year(values[0].rjust(2, "0"))
|
||||
[year, *values.slice(1, 2).map { |s| s.rjust(2, "0") }].join("-")
|
||||
end
|
||||
|
||||
def extract_time_from_multiparameter_attributes(values)
|
||||
values = values.size > 3 ? values[3..5] : values
|
||||
values.map { |s| s.rjust(2, "0") }.join(":")
|
||||
values[3..5].map { |s| s.rjust(2, "0") }.join(":")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -314,7 +314,12 @@ module ValidatesTimeliness
|
||||
args = order.invert.sort.map {|p| arg_map[p[1]][1] }
|
||||
arr = [nil] * 7
|
||||
order.keys.each {|k| i = arg_map[k][0]; arr[i] = arg_map[k][2] unless i.nil? }
|
||||
proc_string = "lambda {|#{args.join(',')}| md||=nil; [#{arr.map {|i| i.nil? ? 'nil' : i }.join(',')}].map {|i| i.is_a?(Float) ? i : i.to_i } }"
|
||||
proc_string = <<-EOL
|
||||
lambda {|#{args.join(',')}|
|
||||
md ||= nil
|
||||
[#{arr.map {|i| i.nil? ? 'nil' : i }.join(',')}].map {|i| i.is_a?(Float) ? i : i.to_i }
|
||||
}
|
||||
EOL
|
||||
eval proc_string
|
||||
end
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ Ginger.configure do |config|
|
||||
rails_versions = ['2.0.2', '2.1.2', '2.2.2', '2.3.2']
|
||||
|
||||
rails_versions.each do |v|
|
||||
g = Ginger::Scenario.new
|
||||
g = Ginger::Scenario.new("Rails #{v}")
|
||||
g['rails'] = v
|
||||
config.scenarios << g.dup
|
||||
end
|
||||
|
||||
@ -7,21 +7,20 @@ Gem::Specification.new do |s|
|
||||
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-04-12}
|
||||
s.date = %q{2009-06-20}
|
||||
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"]
|
||||
s.files = ["LICENSE", "README.rdoc", "Rakefile", "TODO", "CHANGELOG", "lib/validates_timeliness", "lib/validates_timeliness/core_ext", "lib/validates_timeliness/core_ext/date.rb", "lib/validates_timeliness/core_ext/date_time.rb", "lib/validates_timeliness/core_ext/time.rb", "lib/validates_timeliness/action_view", "lib/validates_timeliness/action_view/instance_tag.rb", "lib/validates_timeliness/locale", "lib/validates_timeliness/locale/en.yml", "lib/validates_timeliness/validation_methods.rb", "lib/validates_timeliness/active_record", "lib/validates_timeliness/active_record/attribute_methods.rb", "lib/validates_timeliness/active_record/multiparameter_attributes.rb", "lib/validates_timeliness/parser.rb", "lib/validates_timeliness/formats.rb", "lib/validates_timeliness/validator.rb", "lib/validates_timeliness/spec", "lib/validates_timeliness/spec/rails", "lib/validates_timeliness/spec/rails/matchers", "lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb", "lib/validates_timeliness.rb", "spec/core_ext", "spec/core_ext/dummy_time_spec.rb", "spec/validator_spec.rb", "spec/action_view", "spec/action_view/instance_tag_spec.rb", "spec/ginger_scenarios.rb", "spec/spec_helper.rb", "spec/formats_spec.rb", "spec/active_record", "spec/active_record/attribute_methods_spec.rb", "spec/active_record/multiparameter_attributes_spec.rb", "spec/time_travel", "spec/time_travel/time_travel.rb", "spec/time_travel/time_extensions.rb", "spec/time_travel/MIT-LICENSE", "spec/parser_spec.rb", "spec/spec", "spec/spec/rails", "spec/spec/rails/matchers", "spec/spec/rails/matchers/validate_timeliness_spec.rb", "spec/resources", "spec/resources/person.rb", "spec/resources/sqlite_patch.rb", "spec/resources/schema.rb", "spec/resources/application.rb"]
|
||||
s.has_rdoc = true
|
||||
s.files = ["LICENSE", "README.rdoc", "Rakefile", "TODO", "CHANGELOG", "lib/validates_timeliness", "lib/validates_timeliness/active_record", "lib/validates_timeliness/active_record/multiparameter_attributes.rb", "lib/validates_timeliness/active_record/attribute_methods.rb", "lib/validates_timeliness/parser.rb", "lib/validates_timeliness/core_ext", "lib/validates_timeliness/core_ext/date.rb", "lib/validates_timeliness/core_ext/time.rb", "lib/validates_timeliness/core_ext/date_time.rb", "lib/validates_timeliness/validator.rb", "lib/validates_timeliness/validation_methods.rb", "lib/validates_timeliness/locale", "lib/validates_timeliness/locale/en.yml", "lib/validates_timeliness/spec", "lib/validates_timeliness/spec/rails", "lib/validates_timeliness/spec/rails/matchers", "lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb", "lib/validates_timeliness/action_view", "lib/validates_timeliness/action_view/instance_tag.rb", "lib/validates_timeliness/formats.rb", "lib/validates_timeliness.rb", "spec/active_record", "spec/active_record/multiparameter_attributes_spec.rb", "spec/active_record/attribute_methods_spec.rb", "spec/formats_spec.rb", "spec/parser_spec.rb", "spec/core_ext", "spec/core_ext/dummy_time_spec.rb", "spec/spec_helper.rb", "spec/ginger_scenarios.rb", "spec/time_travel", "spec/time_travel/time_extensions.rb", "spec/time_travel/time_travel.rb", "spec/time_travel/MIT-LICENSE", "spec/spec", "spec/spec/rails", "spec/spec/rails/matchers", "spec/spec/rails/matchers/validate_timeliness_spec.rb", "spec/validator_spec.rb", "spec/action_view", "spec/action_view/instance_tag_spec.rb", "spec/resources", "spec/resources/schema.rb", "spec/resources/application.rb", "spec/resources/person.rb", "spec/resources/sqlite_patch.rb"]
|
||||
s.homepage = %q{http://github.com/adzap/validates_timeliness}
|
||||
s.require_paths = ["lib"]
|
||||
s.rubyforge_project = %q{validatestime}
|
||||
s.rubygems_version = %q{1.3.1}
|
||||
s.rubygems_version = %q{1.3.3}
|
||||
s.summary = %q{Date and time validation plugin for Rails 2.x which allows custom formats}
|
||||
|
||||
if s.respond_to? :specification_version then
|
||||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
||||
s.specification_version = 2
|
||||
s.specification_version = 3
|
||||
|
||||
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
||||
else
|
||||
|
||||
Loading…
Reference in New Issue
Block a user