activerecord_chronological_records 0.1.0 → 0.2.0

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.
data/README.md CHANGED
@@ -23,14 +23,14 @@ This will assume you have `start_date` and `end_date` columns on the model. To c
23
23
  Following scopes are defined at class level that return all records matching specific condition:
24
24
 
25
25
  * `Class.current` - records valid at current date
26
- * `Class.at(date)` - records valid at given date
26
+ * `Class.effective_at(date)` - records valid at given date
27
27
 
28
28
  ### Instance methods
29
29
 
30
30
  Following instance methods are defined for navigation between versions or record. Can return nil if no version matches the condition.
31
31
 
32
32
  * `instance.current` - version of instance valid at current date
33
- * `instance.at(date)` - version of instance valid at given date
33
+ * `instance.effective_at(date)` - version of instance valid at given date
34
34
  * `instance.earliest` - first version of record
35
35
  * `instance.latest` - last version of record
36
36
  * `instance.previous` - version before the one method is being called on
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "activerecord_chronological_records"
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Toms Mikoss"]
12
- s.date = "2012-11-12"
12
+ s.date = "2012-11-13"
13
13
  s.description = "Provides a set of helper methods for dealing with chronological records that have common primary key and date columns denoting when the record is active (example: Oracle EBS tables)."
14
14
  s.email = "toms.mikoss@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -7,26 +7,26 @@ module ActiverecordChronologicalRecords
7
7
  end
8
8
 
9
9
  self.instance_eval <<-EOS
10
- def at(date)
11
- where("#{start_column} <= :date AND (#{end_column} >= :date OR #{end_column} IS NULL)", :date => date)
10
+ def effective_at(date)
11
+ where("(#{start_column} <= :date OR #{start_column} IS NULL) AND (#{end_column} >= :date OR #{end_column} IS NULL)", :date => date)
12
12
  end
13
13
 
14
14
  def current
15
- at(Time.now)
15
+ effective_at(Time.now)
16
16
  end
17
17
  EOS
18
18
 
19
19
  self.class_eval <<-EOS
20
- def at(date)
21
- #{self}.at(date).where(:#{primary_key} => self.#{primary_key}).first
20
+ def effective_at(date)
21
+ #{self}.effective_at(date).where(:#{primary_key} => self.#{primary_key}).first
22
22
  end
23
23
 
24
24
  def current
25
- at(Time.now)
25
+ effective_at(Time.now)
26
26
  end
27
27
 
28
28
  def current?
29
- #{start_column}.to_time <= Time.now && #{end_column}.to_time >= Time.now
29
+ (#{start_column}.blank? || #{start_column}.to_time <= Time.now) && (#{end_column}.blank? || #{end_column}.to_time >= Time.now)
30
30
  end
31
31
 
32
32
  def earliest
@@ -38,11 +38,11 @@ EOS
38
38
  end
39
39
 
40
40
  def previous
41
- at(#{start_column} - 1.day)
41
+ effective_at(#{start_column} - 1.day)
42
42
  end
43
43
 
44
44
  def next
45
- at(#{end_column} + 1.day)
45
+ effective_at(#{end_column} + 1.day)
46
46
  end
47
47
  EOS
48
48
  end
@@ -16,14 +16,14 @@ describe "ActiverecordChronologicalRecords" do
16
16
 
17
17
  shared_examples "scopes" do
18
18
  specify { Employee.current.all.should eq [@current_record] }
19
- specify { Employee.at(Date.today).all.should eq [@current_record] }
20
- specify { Employee.at(Date.today - 2.months).all.should eq [@first_record] }
21
- specify { Employee.at(Date.today + 2.months).all.should eq [@last_record] }
19
+ specify { Employee.effective_at(Date.today).all.should eq [@current_record] }
20
+ specify { Employee.effective_at(Date.today - 2.months).all.should eq [@first_record] }
21
+ specify { Employee.effective_at(Date.today + 2.months).all.should eq [@last_record] }
22
22
  end
23
23
 
24
24
  shared_examples "navigation methods" do
25
25
  specify { @first_record.current.should eq @current_record }
26
- specify { @first_record.at(Date.today).should eq @current_record }
26
+ specify { @first_record.effective_at(Date.today).should eq @current_record }
27
27
  specify { @current_record.earliest.should eq @first_record }
28
28
  specify { @current_record.latest.should eq @last_record }
29
29
  specify { @current_record.previous.should eq @first_record }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_chronological_records
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-12 00:00:00.000000000 Z
12
+ date: 2012-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -144,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  segments:
146
146
  - 0
147
- hash: -609177617
147
+ hash: -126950927
148
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements: