mirror of
https://github.com/ditkrg/validates_timeliness.git
synced 2026-01-25 23:33:00 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acd10f7b64 | ||
|
|
68b2579ca0 | ||
|
|
7a784a6c54 | ||
|
|
907fd3e439 |
@@ -1,3 +1,7 @@
|
|||||||
|
= 3.0.8 [2011-12-24]
|
||||||
|
* Remove deprecated InstanceMethods module when using AS::Concern
|
||||||
|
* Update Mongoid shim for v2.3 compatability.
|
||||||
|
|
||||||
= 3.0.7 [2011-09-21]
|
= 3.0.7 [2011-09-21]
|
||||||
* Fix ActiveRecord before_type_cast extension for non-dirty attributes.
|
* Fix ActiveRecord before_type_cast extension for non-dirty attributes.
|
||||||
* Don't override AR before_type_cast for >= 3.1.0 which now has it's own implementation for date/time attributes.
|
* Don't override AR before_type_cast for >= 3.1.0 which now has it's own implementation for date/time attributes.
|
||||||
|
|||||||
2
Gemfile
2
Gemfile
@@ -11,7 +11,7 @@ gem 'ruby-debug', :platforms => [:ruby_18, :jruby]
|
|||||||
gem 'ruby-debug19', :platforms => [:ruby_19]
|
gem 'ruby-debug19', :platforms => [:ruby_19]
|
||||||
|
|
||||||
group :mongoid do
|
group :mongoid do
|
||||||
gem 'mongoid', '2.2.0'
|
gem 'mongoid', '~> 2.3.0'
|
||||||
gem 'bson_ext'
|
gem 'bson_ext'
|
||||||
gem 'system_timer', :platforms => [:ruby_18]
|
gem 'system_timer', :platforms => [:ruby_18]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -65,15 +65,12 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
def _timeliness_raw_value_for(attr_name)
|
||||||
def _timeliness_raw_value_for(attr_name)
|
@timeliness_cache && @timeliness_cache[attr_name.to_s]
|
||||||
@timeliness_cache && @timeliness_cache[attr_name.to_s]
|
|
||||||
end
|
|
||||||
|
|
||||||
def _clear_timeliness_cache
|
|
||||||
@timeliness_cache = {}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def _clear_timeliness_cache
|
||||||
|
@timeliness_cache = {}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ module ValidatesTimeliness
|
|||||||
|
|
||||||
class TimelinessDateTime
|
class TimelinessDateTime
|
||||||
attr_accessor :year, :month, :day, :hour, :min, :sec
|
attr_accessor :year, :month, :day, :hour, :min, :sec
|
||||||
|
|
||||||
def initialize(year, month, day, hour, min, sec)
|
def initialize(year, month, day, hour, min, sec)
|
||||||
@year, @month, @day, @hour, @min, @sec = year, month, day, hour, min, sec
|
@year, @month, @day, @hour, @min, @sec = year, month, day, hour, min, sec
|
||||||
end
|
end
|
||||||
|
|
||||||
# adapted from activesupport/lib/active_support/core_ext/date_time/calculations.rb, line 36 (3.0.7)
|
# adapted from activesupport/lib/active_support/core_ext/date_time/calculations.rb, line 36 (3.0.7)
|
||||||
def change(options)
|
def change(options)
|
||||||
TimelinessDateTime.new(
|
TimelinessDateTime.new(
|
||||||
@@ -30,35 +30,32 @@ module ValidatesTimeliness
|
|||||||
options[:min] || (options[:hour] ? 0 : min),
|
options[:min] || (options[:hour] ? 0 : min),
|
||||||
options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec)
|
options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec)
|
||||||
)
|
)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module InstanceMethods
|
|
||||||
def datetime_selector_with_timeliness(*args)
|
|
||||||
@timeliness_date_or_time_tag = true
|
|
||||||
datetime_selector_without_timeliness(*args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def value_with_timeliness(object)
|
|
||||||
unless @timeliness_date_or_time_tag && @template_object.params[@object_name]
|
|
||||||
return value_without_timeliness(object)
|
|
||||||
end
|
|
||||||
|
|
||||||
@template_object.params[@object_name]
|
|
||||||
|
|
||||||
pairs = @template_object.params[@object_name].select {|k,v| k =~ /^#{@method_name}\(/ }
|
|
||||||
return value_without_timeliness(object) if pairs.empty?
|
|
||||||
|
|
||||||
values = [nil] * 6
|
|
||||||
pairs.map do |(param, value)|
|
|
||||||
position = param.scan(/\((\d+)\w+\)/).first.first
|
|
||||||
values[position.to_i-1] = value.to_i
|
|
||||||
end
|
|
||||||
|
|
||||||
TimelinessDateTime.new(*values)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def datetime_selector_with_timeliness(*args)
|
||||||
|
@timeliness_date_or_time_tag = true
|
||||||
|
datetime_selector_without_timeliness(*args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def value_with_timeliness(object)
|
||||||
|
unless @timeliness_date_or_time_tag && @template_object.params[@object_name]
|
||||||
|
return value_without_timeliness(object)
|
||||||
|
end
|
||||||
|
|
||||||
|
@template_object.params[@object_name]
|
||||||
|
|
||||||
|
pairs = @template_object.params[@object_name].select {|k,v| k =~ /^#{@method_name}\(/ }
|
||||||
|
return value_without_timeliness(object) if pairs.empty?
|
||||||
|
|
||||||
|
values = [nil] * 6
|
||||||
|
pairs.map do |(param, value)|
|
||||||
|
position = param.scan(/\((\d+)\w+\)/).first.first
|
||||||
|
values[position.to_i-1] = value.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
TimelinessDateTime.new(*values)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -30,13 +30,10 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
def reload(*args)
|
||||||
def reload(*args)
|
_clear_timeliness_cache
|
||||||
_clear_timeliness_cache
|
super
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ module ValidatesTimeliness
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reload
|
||||||
|
_clear_timeliness_cache
|
||||||
|
super
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -39,9 +43,12 @@ module Mongoid::Document
|
|||||||
include ValidatesTimeliness::AttributeMethods
|
include ValidatesTimeliness::AttributeMethods
|
||||||
include ValidatesTimeliness::ORM::Mongoid
|
include ValidatesTimeliness::ORM::Mongoid
|
||||||
|
|
||||||
def reload_with_timeliness
|
# Pre-2.3 reload
|
||||||
_clear_timeliness_cache
|
if instance_methods.include?('reload')
|
||||||
reload_without_timeliness
|
def reload_with_timeliness
|
||||||
|
_clear_timeliness_cache
|
||||||
|
reload_without_timeliness
|
||||||
|
end
|
||||||
|
alias_method_chain :reload, :timeliness
|
||||||
end
|
end
|
||||||
alias_method_chain :reload, :timeliness
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module ValidatesTimeliness
|
module ValidatesTimeliness
|
||||||
VERSION = '3.0.7'
|
VERSION = '3.0.8'
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -69,22 +69,22 @@ describe ValidatesTimeliness, 'Mongoid' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "for a date column" do
|
context "for a date column" do
|
||||||
it 'should store a Time value after parsing string' do
|
it 'should store a Date value after parsing string' do
|
||||||
r = Article.new
|
r = Article.new
|
||||||
r.publish_date = '2010-01-01'
|
r.publish_date = '2010-01-01'
|
||||||
|
|
||||||
r.publish_date.should be_kind_of(Time)
|
r.publish_date.should be_kind_of(Date)
|
||||||
r.publish_date.should == Date.new(2010, 1, 1)
|
r.publish_date.should == Date.new(2010, 1, 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "for a datetime column" do
|
context "for a datetime column" do
|
||||||
it 'should parse string into Time value' do
|
it 'should parse string into DateTime value' do
|
||||||
r = Article.new
|
r = Article.new
|
||||||
r.publish_datetime = '2010-01-01 12:00'
|
r.publish_datetime = '2010-01-01 12:00'
|
||||||
|
|
||||||
r.publish_datetime.should be_kind_of(Time)
|
r.publish_datetime.should be_kind_of(DateTime)
|
||||||
r.publish_datetime.should == Time.utc(2010,1,1,12,0)
|
r.publish_datetime.should == DateTime.new(2010,1,1,12,0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -108,6 +108,6 @@ end
|
|||||||
|
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
puts "Mongoid specs skipped. Mongoid not installed"
|
puts "Mongoid specs skipped. Mongoid not installed"
|
||||||
rescue StandardError
|
rescue StandardError => e
|
||||||
puts "Mongoid specs skipped. MongoDB connection failed."
|
puts "Mongoid specs skipped. MongoDB connection failed with error: #{e.message}"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
|
|||||||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||||
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
|
s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
|
||||||
|
|
||||||
s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.3"])
|
s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.4"])
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user