transient 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -1
- data/VERSION +1 -1
- data/lib/transient/active_record_extensions.rb +34 -17
- data/transient.gemspec +4 -4
- metadata +45 -17
data/History.txt
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
= 1.0.2 2010
|
1
|
+
= 1.0.2 2010-03-18
|
2
2
|
|
3
3
|
* Fixed bug where the effective_at date when implicitly set was not UTC.
|
4
|
+
* Started using the method calls (self.effective_at) as opposed to the self[:effective_at] whenever possible.
|
5
|
+
* Renamed the effective_at method to expires_at.
|
4
6
|
|
5
7
|
|
6
8
|
= 1.0.1 2009-12-29
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
@@ -22,36 +22,53 @@ module Transient
|
|
22
22
|
|
23
23
|
module InstanceMethods
|
24
24
|
def self.included( base ) #:nodoc:
|
25
|
+
base.instance_eval do
|
26
|
+
def is_active_record_3?
|
27
|
+
respond_to? :where
|
28
|
+
end
|
29
|
+
|
30
|
+
def scope_method_name
|
31
|
+
is_active_record_3? ?
|
32
|
+
:scope :
|
33
|
+
:named_scope
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
25
37
|
base.validates_presence_of :effective_at
|
26
38
|
#base.validates_presence_of :expiring_at
|
27
39
|
|
28
|
-
base.
|
29
|
-
|
40
|
+
base.send( base.scope_method_name, :effective,
|
41
|
+
lambda { { :conditions => ["effective_at <= ? AND (expiring_at IS NULL OR expiring_at > ?)",
|
42
|
+
DateTime.now.utc, DateTime.now.utc] } } )
|
30
43
|
|
31
|
-
base.
|
44
|
+
if base.is_active_record_3?
|
45
|
+
base.before_validation :check_and_set_effective_at, :on => :create
|
46
|
+
else
|
47
|
+
base.before_validation_on_create :check_and_set_effective_at
|
48
|
+
end
|
32
49
|
|
33
50
|
protected
|
34
|
-
|
51
|
+
|
35
52
|
def check_and_set_effective_at
|
36
53
|
self.effective_at = Time.zone.now if self.effective_at.nil?
|
37
54
|
end
|
38
|
-
|
55
|
+
|
39
56
|
public
|
40
57
|
|
41
|
-
# Validates this record's effective dates occur in correct sequence (ie. effective_at is before
|
42
|
-
# expiring_at).
|
58
|
+
# Validates this record's effective dates occur in correct sequence (ie. effective_at is before
|
59
|
+
# expiring_at).
|
43
60
|
#
|
44
|
-
def validate
|
61
|
+
def validate
|
45
62
|
return unless self.effective_at && self.expiring_at
|
46
63
|
|
47
|
-
unless self.effective_at.to_datetime <= self.
|
64
|
+
unless self.effective_at.to_datetime <= self.expires_at.to_datetime
|
48
65
|
self.errors.add( :effective_through, "effective at should be earlier than expiring at" )
|
49
66
|
end
|
50
67
|
|
51
|
-
super
|
68
|
+
super unless self.class.is_active_record_3?
|
52
69
|
end
|
53
70
|
|
54
|
-
# The date this record expires. Returns DateTime.end_of for records that have a
|
71
|
+
# The date this record expires. Returns DateTime.end_of for records that have a
|
55
72
|
# nil value in the database.
|
56
73
|
#
|
57
74
|
def expires_at
|
@@ -61,7 +78,7 @@ module Transient
|
|
61
78
|
# The range this record is effective wihtin.
|
62
79
|
#
|
63
80
|
def effective_through
|
64
|
-
self.effective_at.to_datetime..self.
|
81
|
+
self.effective_at.to_datetime..self.expires_at.to_datetime
|
65
82
|
end
|
66
83
|
|
67
84
|
# Sets the range this record is effective within.
|
@@ -86,7 +103,7 @@ module Transient
|
|
86
103
|
# Returns true if this record is expired, otherwise false.
|
87
104
|
#
|
88
105
|
def expired?
|
89
|
-
self.
|
106
|
+
self.expires_at.to_datetime < DateTime.now
|
90
107
|
end
|
91
108
|
|
92
109
|
# Expires and saves this record.
|
@@ -98,7 +115,7 @@ module Transient
|
|
98
115
|
after_expire! if self.respond_to?( :after_expire! )
|
99
116
|
end
|
100
117
|
|
101
|
-
# Returns true if this record is not yet effective, but will become effective at some point in the
|
118
|
+
# Returns true if this record is not yet effective, but will become effective at some point in the
|
102
119
|
# future, otherwise false.
|
103
120
|
#
|
104
121
|
def future?
|
@@ -122,9 +139,9 @@ module Transient
|
|
122
139
|
module SingleActive
|
123
140
|
def self.included( base ) #:nodoc:
|
124
141
|
base.before_create :expire_current_active
|
125
|
-
|
142
|
+
|
126
143
|
private
|
127
|
-
|
144
|
+
|
128
145
|
def expire_current_active
|
129
146
|
#if self.transient_options[:check_exists]
|
130
147
|
# exists_conditions = {}
|
@@ -132,7 +149,7 @@ module Transient
|
|
132
149
|
# #cur = self.class.current.find( :first, :conditions => exists_conditions )
|
133
150
|
# return true if self.class.current.exists?( exists_conditions )
|
134
151
|
#end
|
135
|
-
|
152
|
+
|
136
153
|
conditions = {}
|
137
154
|
self.transient_options[:single_active].each { |attr| conditions.merge!( attr.to_sym => attributes[attr] ) }
|
138
155
|
old = self.class.effective.first( :conditions => conditions )
|
data/transient.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{transient}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["C. Jason Harrelson (midas)"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-04-20}
|
13
13
|
s.description = %q{Provides an API for making any ActiveRecord object transient. In addition, provides functionality for models where only a single instance of the model can be current at one time.}
|
14
14
|
s.email = %q{jason@lookforwardenterprises.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
s.homepage = %q{http://github.com/midas/transient}
|
42
42
|
s.rdoc_options = ["--charset=UTF-8"]
|
43
43
|
s.require_paths = ["lib"]
|
44
|
-
s.rubygems_version = %q{1.3.
|
44
|
+
s.rubygems_version = %q{1.3.7}
|
45
45
|
s.summary = %q{Provides an API for making any ActiveRecord object transient.}
|
46
46
|
s.test_files = [
|
47
47
|
"spec/date_time_extensions_spec.rb",
|
@@ -56,7 +56,7 @@ Gem::Specification.new do |s|
|
|
56
56
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
57
57
|
s.specification_version = 3
|
58
58
|
|
59
|
-
if Gem::Version.new(Gem::
|
59
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
60
|
s.add_runtime_dependency(%q<activerecord>, [">= 2.3"])
|
61
61
|
s.add_runtime_dependency(%q<activesupport>, [">= 2.3"])
|
62
62
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 19
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- C. Jason Harrelson (midas)
|
@@ -9,39 +15,55 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2011-04-20 00:00:00 -05:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: activerecord
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 3
|
23
33
|
version: "2.3"
|
24
|
-
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: activesupport
|
27
|
-
|
28
|
-
|
29
|
-
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
30
41
|
requirements:
|
31
42
|
- - ">="
|
32
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 5
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 3
|
33
48
|
version: "2.3"
|
34
|
-
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
35
51
|
- !ruby/object:Gem::Dependency
|
36
52
|
name: rspec
|
37
|
-
|
38
|
-
|
39
|
-
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
40
56
|
requirements:
|
41
57
|
- - ">="
|
42
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 13
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 2
|
63
|
+
- 9
|
43
64
|
version: 1.2.9
|
44
|
-
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
45
67
|
description: Provides an API for making any ActiveRecord object transient. In addition, provides functionality for models where only a single instance of the model can be current at one time.
|
46
68
|
email: jason@lookforwardenterprises.com
|
47
69
|
executables: []
|
@@ -82,21 +104,27 @@ rdoc_options:
|
|
82
104
|
require_paths:
|
83
105
|
- lib
|
84
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
85
108
|
requirements:
|
86
109
|
- - ">="
|
87
110
|
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
112
|
+
segments:
|
113
|
+
- 0
|
88
114
|
version: "0"
|
89
|
-
version:
|
90
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
91
117
|
requirements:
|
92
118
|
- - ">="
|
93
119
|
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
94
123
|
version: "0"
|
95
|
-
version:
|
96
124
|
requirements: []
|
97
125
|
|
98
126
|
rubyforge_project:
|
99
|
-
rubygems_version: 1.3.
|
127
|
+
rubygems_version: 1.3.7
|
100
128
|
signing_key:
|
101
129
|
specification_version: 3
|
102
130
|
summary: Provides an API for making any ActiveRecord object transient.
|