chronological 1.0.0beta2 → 1.0.0beta3
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 +7 -9
- data/lib/chronological/version.rb +1 -1
- data/lib/chronological.rb +4 -4
- data/spec/chronological_spec.rb +4 -4
- data/spec/strategies/relative_spec.rb +24 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -227,20 +227,18 @@ these accessors:
|
|
227
227
|
* `started_on`
|
228
228
|
* `ended_on`
|
229
229
|
|
230
|
-
If you want to override
|
231
|
-
|
232
|
-
`absolute_start_time_field` and/or `absolute_end_time_field` options to
|
233
|
-
`timeframe` like so:
|
230
|
+
If you want to override the fields that Chronological creates to access those
|
231
|
+
values, simply pass in the option with the name of the field you would like.
|
234
232
|
|
235
233
|
#### Example
|
236
234
|
|
237
235
|
```ruby
|
238
236
|
class MyTimeRangeClass
|
239
|
-
timeframe :base_of_offset
|
240
|
-
:starting_offset
|
241
|
-
:ending_offset
|
242
|
-
:
|
243
|
-
:
|
237
|
+
timeframe :base_of_offset => :event_start_time,
|
238
|
+
:starting_offset => :starting_availability_offset
|
239
|
+
:ending_offset => :ending_availability_offset,
|
240
|
+
:starting_time => :custom_start_field
|
241
|
+
:ending_time => :custom_end_field
|
244
242
|
end
|
245
243
|
```
|
246
244
|
|
data/lib/chronological.rb
CHANGED
@@ -9,10 +9,10 @@ module Chronological
|
|
9
9
|
strategy = Chronological::StrategyResolver.resolve(options)
|
10
10
|
|
11
11
|
class_eval do
|
12
|
-
columns_hash[strategy.field_names[:starting_time]] ||= ActiveRecord::ConnectionAdapters::Column.new(strategy.field_names[:starting_time], nil, 'datetime')
|
13
|
-
columns_hash[strategy.field_names[:ending_time]] ||= ActiveRecord::ConnectionAdapters::Column.new(strategy.field_names[:ending_time], nil, 'datetime')
|
14
|
-
columns_hash[strategy.field_names[:starting_date]] ||= ActiveRecord::ConnectionAdapters::Column.new(strategy.field_names[:starting_date], nil, 'date')
|
15
|
-
columns_hash[strategy.field_names[:ending_date]] ||= ActiveRecord::ConnectionAdapters::Column.new(strategy.field_names[:ending_date], nil, 'date')
|
12
|
+
columns_hash[strategy.field_names[:starting_time].to_s] ||= ActiveRecord::ConnectionAdapters::Column.new(strategy.field_names[:starting_time], nil, 'datetime')
|
13
|
+
columns_hash[strategy.field_names[:ending_time].to_s] ||= ActiveRecord::ConnectionAdapters::Column.new(strategy.field_names[:ending_time], nil, 'datetime')
|
14
|
+
columns_hash[strategy.field_names[:starting_date].to_s] ||= ActiveRecord::ConnectionAdapters::Column.new(strategy.field_names[:starting_date], nil, 'date')
|
15
|
+
columns_hash[strategy.field_names[:ending_date].to_s] ||= ActiveRecord::ConnectionAdapters::Column.new(strategy.field_names[:ending_date], nil, 'date')
|
16
16
|
end
|
17
17
|
|
18
18
|
unless strategy.has_absolute_start?
|
data/spec/chronological_spec.rb
CHANGED
@@ -38,19 +38,19 @@ describe Chronological do
|
|
38
38
|
it { ChronologicableStrategyClass.should respond_to :active? }
|
39
39
|
|
40
40
|
it 'tells ActiveRecord that the dynamic starting date field is a datetime' do
|
41
|
-
ChronologicableStrategyClass.columns_hash[
|
41
|
+
ChronologicableStrategyClass.columns_hash['started_at'].type.should eql :datetime
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'tells ActiveRecord that the dynamic ending date field is a datetime' do
|
45
|
-
ChronologicableStrategyClass.columns_hash[
|
45
|
+
ChronologicableStrategyClass.columns_hash['ended_at'].type.should eql :datetime
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'tells ActiveRecord that the dynamic starting date field is a datetime' do
|
49
|
-
ChronologicableStrategyClass.columns_hash[
|
49
|
+
ChronologicableStrategyClass.columns_hash['started_on'].type.should eql :date
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'tells ActiveRecord that the dynamic ending date field is a datetime' do
|
53
|
-
ChronologicableStrategyClass.columns_hash[
|
53
|
+
ChronologicableStrategyClass.columns_hash['ended_on'].type.should eql :date
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -19,6 +19,21 @@ class RelativeChronologicableWithTimeZone < ActiveRecord::Base
|
|
19
19
|
time_zone: :time_zone
|
20
20
|
end
|
21
21
|
|
22
|
+
class RelativeChronologicalWithOverriddenTime < ActiveRecord::Base
|
23
|
+
extend Chronological
|
24
|
+
|
25
|
+
set_table_name 'relative_chronologicables'
|
26
|
+
|
27
|
+
timeframe type: :relative,
|
28
|
+
starting_offset: :starting_offset,
|
29
|
+
ending_offset: :ending_offset,
|
30
|
+
base_of_offset: :base_datetime_utc,
|
31
|
+
starting_time: :foobar_starting_time,
|
32
|
+
ending_time: :foobar_ending_time,
|
33
|
+
starting_date: :foobar_starting_date,
|
34
|
+
ending_date: :foobar_ending_date
|
35
|
+
end
|
36
|
+
|
22
37
|
describe Chronological::RelativeStrategy, :timecop => true do
|
23
38
|
let(:now) { nil }
|
24
39
|
let(:starting_offset) { nil }
|
@@ -48,6 +63,15 @@ describe Chronological::RelativeStrategy, :timecop => true do
|
|
48
63
|
time_zone: time_zone)
|
49
64
|
end
|
50
65
|
|
66
|
+
let(:chronologicable_with_overridden_time) do
|
67
|
+
RelativeChronologicalWithOverriddenTime.new
|
68
|
+
end
|
69
|
+
|
70
|
+
it { chronologicable_with_overridden_time.should respond_to(:foobar_starting_time) }
|
71
|
+
it { chronologicable_with_overridden_time.should respond_to(:foobar_ending_time) }
|
72
|
+
it { chronologicable_with_overridden_time.should respond_to(:foobar_starting_date) }
|
73
|
+
it { chronologicable_with_overridden_time.should respond_to(:foobar_ending_date) }
|
74
|
+
|
51
75
|
before { Timecop.freeze(now) }
|
52
76
|
|
53
77
|
describe '.by_date' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chronological
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.0beta3
|
5
5
|
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-10-
|
13
|
+
date: 2012-10-31 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|