validates_timeliness 3.0.7 → 3.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,7 @@
1
+ = 3.0.8 [2011-12-24]
2
+ * Remove deprecated InstanceMethods module when using AS::Concern
3
+ * Update Mongoid shim for v2.3 compatability.
4
+
1
5
  = 3.0.7 [2011-09-21]
2
6
  * Fix ActiveRecord before_type_cast extension for non-dirty attributes.
3
7
  * Don't override AR before_type_cast for >= 3.1.0 which now has it's own implementation for date/time attributes.
@@ -65,15 +65,12 @@ module ValidatesTimeliness
65
65
  end
66
66
  end
67
67
 
68
- module InstanceMethods
69
- def _timeliness_raw_value_for(attr_name)
70
- @timeliness_cache && @timeliness_cache[attr_name.to_s]
71
- end
72
-
73
- def _clear_timeliness_cache
74
- @timeliness_cache = {}
75
- end
68
+ def _timeliness_raw_value_for(attr_name)
69
+ @timeliness_cache && @timeliness_cache[attr_name.to_s]
76
70
  end
77
71
 
72
+ def _clear_timeliness_cache
73
+ @timeliness_cache = {}
74
+ end
78
75
  end
79
76
  end
@@ -15,11 +15,11 @@ module ValidatesTimeliness
15
15
 
16
16
  class TimelinessDateTime
17
17
  attr_accessor :year, :month, :day, :hour, :min, :sec
18
-
18
+
19
19
  def initialize(year, month, day, hour, min, sec)
20
20
  @year, @month, @day, @hour, @min, @sec = year, month, day, hour, min, sec
21
21
  end
22
-
22
+
23
23
  # adapted from activesupport/lib/active_support/core_ext/date_time/calculations.rb, line 36 (3.0.7)
24
24
  def change(options)
25
25
  TimelinessDateTime.new(
@@ -30,35 +30,32 @@ module ValidatesTimeliness
30
30
  options[:min] || (options[:hour] ? 0 : min),
31
31
  options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec)
32
32
  )
33
- end
33
+ end
34
34
  end
35
35
 
36
- module InstanceMethods
37
- def datetime_selector_with_timeliness(*args)
38
- @timeliness_date_or_time_tag = true
39
- datetime_selector_without_timeliness(*args)
40
- end
36
+ def datetime_selector_with_timeliness(*args)
37
+ @timeliness_date_or_time_tag = true
38
+ datetime_selector_without_timeliness(*args)
39
+ end
41
40
 
42
- def value_with_timeliness(object)
43
- unless @timeliness_date_or_time_tag && @template_object.params[@object_name]
44
- return value_without_timeliness(object)
45
- end
46
-
47
- @template_object.params[@object_name]
41
+ def value_with_timeliness(object)
42
+ unless @timeliness_date_or_time_tag && @template_object.params[@object_name]
43
+ return value_without_timeliness(object)
44
+ end
48
45
 
49
- pairs = @template_object.params[@object_name].select {|k,v| k =~ /^#{@method_name}\(/ }
50
- return value_without_timeliness(object) if pairs.empty?
46
+ @template_object.params[@object_name]
51
47
 
52
- values = [nil] * 6
53
- pairs.map do |(param, value)|
54
- position = param.scan(/\((\d+)\w+\)/).first.first
55
- values[position.to_i-1] = value.to_i
56
- end
48
+ pairs = @template_object.params[@object_name].select {|k,v| k =~ /^#{@method_name}\(/ }
49
+ return value_without_timeliness(object) if pairs.empty?
57
50
 
58
- TimelinessDateTime.new(*values)
51
+ values = [nil] * 6
52
+ pairs.map do |(param, value)|
53
+ position = param.scan(/\((\d+)\w+\)/).first.first
54
+ values[position.to_i-1] = value.to_i
59
55
  end
60
- end
61
56
 
57
+ TimelinessDateTime.new(*values)
58
+ end
62
59
  end
63
60
  end
64
61
  end
@@ -30,13 +30,10 @@ module ValidatesTimeliness
30
30
  end
31
31
  end
32
32
 
33
- module InstanceMethods
34
- def reload(*args)
35
- _clear_timeliness_cache
36
- super
37
- end
33
+ def reload(*args)
34
+ _clear_timeliness_cache
35
+ super
38
36
  end
39
-
40
37
  end
41
38
  end
42
39
  end
@@ -31,6 +31,10 @@ module ValidatesTimeliness
31
31
  end
32
32
  end
33
33
 
34
+ def reload
35
+ _clear_timeliness_cache
36
+ super
37
+ end
34
38
  end
35
39
  end
36
40
  end
@@ -39,9 +43,12 @@ module Mongoid::Document
39
43
  include ValidatesTimeliness::AttributeMethods
40
44
  include ValidatesTimeliness::ORM::Mongoid
41
45
 
42
- def reload_with_timeliness
43
- _clear_timeliness_cache
44
- reload_without_timeliness
46
+ # Pre-2.3 reload
47
+ if instance_methods.include?('reload')
48
+ def reload_with_timeliness
49
+ _clear_timeliness_cache
50
+ reload_without_timeliness
51
+ end
52
+ alias_method_chain :reload, :timeliness
45
53
  end
46
- alias_method_chain :reload, :timeliness
47
54
  end
@@ -1,3 +1,3 @@
1
1
  module ValidatesTimeliness
2
- VERSION = '3.0.7'
2
+ VERSION = '3.0.8'
3
3
  end
@@ -69,22 +69,22 @@ describe ValidatesTimeliness, 'Mongoid' do
69
69
  end
70
70
 
71
71
  context "for a date column" do
72
- it 'should store a Time value after parsing string' do
72
+ it 'should store a Date value after parsing string' do
73
73
  r = Article.new
74
74
  r.publish_date = '2010-01-01'
75
75
 
76
- r.publish_date.should be_kind_of(Time)
76
+ r.publish_date.should be_kind_of(Date)
77
77
  r.publish_date.should == Date.new(2010, 1, 1)
78
78
  end
79
79
  end
80
80
 
81
81
  context "for a datetime column" do
82
- it 'should parse string into Time value' do
82
+ it 'should parse string into DateTime value' do
83
83
  r = Article.new
84
84
  r.publish_datetime = '2010-01-01 12:00'
85
85
 
86
- r.publish_datetime.should be_kind_of(Time)
87
- r.publish_datetime.should == Time.utc(2010,1,1,12,0)
86
+ r.publish_datetime.should be_kind_of(DateTime)
87
+ r.publish_datetime.should == DateTime.new(2010,1,1,12,0)
88
88
  end
89
89
  end
90
90
  end
@@ -108,6 +108,6 @@ end
108
108
 
109
109
  rescue LoadError
110
110
  puts "Mongoid specs skipped. Mongoid not installed"
111
- rescue StandardError
112
- puts "Mongoid specs skipped. MongoDB connection failed."
111
+ rescue StandardError => e
112
+ puts "Mongoid specs skipped. MongoDB connection failed with error: #{e.message}"
113
113
  end
@@ -16,5 +16,5 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.extra_rdoc_files = ["README.rdoc", "CHANGELOG.rdoc", "LICENSE"]
18
18
 
19
- s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.3"])
19
+ s.add_runtime_dependency(%q<timeliness>, ["~> 0.3.4"])
20
20
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_timeliness
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 7
10
- version: 3.0.7
9
+ - 8
10
+ version: 3.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Meehan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-21 00:00:00 +10:00
18
+ date: 2011-12-24 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 21
29
+ hash: 27
30
30
  segments:
31
31
  - 0
32
32
  - 3
33
- - 3
34
- version: 0.3.3
33
+ - 4
34
+ version: 0.3.4
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  description: Adds validation methods to ActiveModel for validating dates and times. Works with multiple ORMS.