activerecord-time-scope 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +8 -5
- data/Gemfile +1 -0
- data/README.md +2 -2
- data/VERSION +1 -1
- data/activerecord-time-scope.gemspec +0 -1
- data/lib/active_record/time_scope.rb +3 -1
- data/lib/active_record/time_scope/time_range_proxy.rb +6 -0
- data/spec/spec_helper.rb +2 -2
- data/spec/time_scope/time_range_proxy_spec.rb +60 -0
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 371764ccbdc580176d978b5e7b69ee720b28fe62
|
4
|
+
data.tar.gz: 45dfca027bfc038cdc2cafe771201b24d90b9900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f59e7cb0ef3876bc948b927091b0ec11fb679dbfd20eff57d2f0e48a23e72a80979f4f5947111477351d0e9e6844c366ef7148b22e2f36f0dce6f615224ae14
|
7
|
+
data.tar.gz: a66a5faee07bbded9c3a0ce489e11096ca0b98981c2660b5d6d8a74c804ccd1dff90560b510db44d762b172f9e333d8aeca5bc7d2a394f70c749e4bde56dc48f
|
data/.travis.yml
CHANGED
@@ -6,11 +6,14 @@ rvm:
|
|
6
6
|
- 2.1
|
7
7
|
|
8
8
|
env:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
global:
|
10
|
+
- CODECLIMATE_REPO_TOKEN=9c215b69f33357ece2af42829259ad13f704172c052587a22cefcee2450bcc71
|
11
|
+
matrix:
|
12
|
+
-
|
13
|
+
- ACTIVE_RECORD_VERSION=3.2.0
|
14
|
+
- ACTIVE_RECORD_VERSION=4.0.0
|
15
|
+
- ACTIVE_RECORD_VERSION=4.1.0
|
16
|
+
- ACTIVE_RECORD_VERSION=4.2.0.rc1
|
14
17
|
|
15
18
|
script: "bundle exec rake spec"
|
16
19
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -115,8 +115,8 @@ Copyright (c) 2014 Daisuke Taniwaki. See [LICENSE](LICENSE) for details.
|
|
115
115
|
[build-link]: http://travis-ci.org/dtaniwaki/activerecord-time-scope
|
116
116
|
[deps-image]: https://gemnasium.com/dtaniwaki/activerecord-time-scope.svg
|
117
117
|
[deps-link]: https://gemnasium.com/dtaniwaki/activerecord-time-scope
|
118
|
-
[cov-image]: https://
|
119
|
-
[cov-link]: https://
|
118
|
+
[cov-image]: https://codeclimate.com/github/dtaniwaki/activerecord-time-scope/badges/coverage.svg
|
119
|
+
[cov-link]: https://codeclimate.com/github/dtaniwaki/activerecord-time-scope
|
120
120
|
[gpa-image]: https://codeclimate.com/github/dtaniwaki/activerecord-time-scope.png
|
121
121
|
[gpa-link]: https://codeclimate.com/github/dtaniwaki/activerecord-time-scope
|
122
122
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -31,9 +31,11 @@ module ActiveRecord
|
|
31
31
|
model = self
|
32
32
|
from_name = "#{table_name}.#{from_name}"
|
33
33
|
to_name = "#{table_name}.#{to_name}"
|
34
|
-
|
34
|
+
scope "#{verb}_before", ->(time, opts = {}){ TimeRangeProxy.new(model, from_name, to_name).before(time, opts) }
|
35
35
|
scope "#{verb}_after", ->(time, opts = {}){ TimeRangeProxy.new(model, from_name, to_name).after(time, opts) }
|
36
36
|
scope "#{verb}_within", ->(from, to, from_opts = {}, to_opts = {}){ TimeRangeProxy.new(model, from_name, to_name).within(from, to, from_opts, to_opts) }
|
37
|
+
scope "#{verb}_at", ->(dt, opts = {}){ TimeRangeProxy.new(model, from_name, to_name).at(dt, opts) }
|
38
|
+
scope "#{verb}_on", ->(dt, opts = {}){ TimeRangeProxy.new(model, from_name, to_name).at(dt, opts) }
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
@@ -24,6 +24,12 @@ module ActiveRecord
|
|
24
24
|
to_operator = to_opts[:include_equal].to_s != '' ? '<=' : '<'
|
25
25
|
@model.where("? #{from_operator} #{@column_name1} AND #{@column_name2} #{to_operator} ?", from, to)
|
26
26
|
end
|
27
|
+
|
28
|
+
def at(dt, opts = {})
|
29
|
+
operator = opts[:include_equal].to_s != '' ? '<=' : '<'
|
30
|
+
@model.where("#{@column_name1} #{operator} ? AND ? #{operator} #{@column_name2}", dt, dt)
|
31
|
+
end
|
32
|
+
alias_method :on, :at
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -247,4 +247,64 @@ RSpec.describe ActiveRecord::TimeScope::TimeRangeProxy do
|
|
247
247
|
end
|
248
248
|
end
|
249
249
|
end
|
250
|
+
describe "::wow_at" do
|
251
|
+
shared_examples "at" do
|
252
|
+
before do
|
253
|
+
klass.create! foo: time + 100.days, bar: time + 100.days
|
254
|
+
end
|
255
|
+
let(:options) { {} }
|
256
|
+
let(:a) { false }
|
257
|
+
let(:b) { false }
|
258
|
+
let(:c) { false }
|
259
|
+
let(:d) { false }
|
260
|
+
let(:e) { false }
|
261
|
+
subject { klass.wow_at(time, options) == [model] }
|
262
|
+
# A
|
263
|
+
# .=====.
|
264
|
+
# ......!
|
265
|
+
context "foo < bar < time" do
|
266
|
+
let!(:model) { klass.create! foo: time - 2.days, bar: time - 1.days }
|
267
|
+
it { is_expected.to be a }
|
268
|
+
end
|
269
|
+
# B
|
270
|
+
# .=====.
|
271
|
+
# .....!.
|
272
|
+
context "foo < bar = time" do
|
273
|
+
let!(:model) { klass.create! foo: time - 2.days, bar: time }
|
274
|
+
it { is_expected.to be b }
|
275
|
+
end
|
276
|
+
# C
|
277
|
+
# .=====.
|
278
|
+
# !......
|
279
|
+
context "time < foo < bar" do
|
280
|
+
let!(:model) { klass.create! foo: time + 1.days, bar: time + 2.days }
|
281
|
+
it { is_expected.to be c }
|
282
|
+
end
|
283
|
+
# D
|
284
|
+
# .=====.
|
285
|
+
# .!.....
|
286
|
+
context "time = foo < bar" do
|
287
|
+
let!(:model) { klass.create! foo: time, bar: time + 2.days }
|
288
|
+
it { is_expected.to be d }
|
289
|
+
end
|
290
|
+
# E
|
291
|
+
# .=====.
|
292
|
+
# ...!...
|
293
|
+
context "foo < time < bar" do
|
294
|
+
let!(:model) { klass.create! foo: time - 1.days, bar: time + 1.days }
|
295
|
+
it { is_expected.to be e }
|
296
|
+
end
|
297
|
+
end
|
298
|
+
it_behaves_like "at" do
|
299
|
+
let(:e) { true }
|
300
|
+
end
|
301
|
+
context "with include_equal option" do
|
302
|
+
it_behaves_like "at" do
|
303
|
+
let(:options) { {include_equal: true} }
|
304
|
+
let(:b) { true }
|
305
|
+
let(:d) { true }
|
306
|
+
let(:e) { true }
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
250
310
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-time-scope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daisuke Taniwaki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: coveralls
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
description: Time-Related Scope for ActiveRecord
|
70
56
|
email:
|
71
57
|
- daisuketaniwaki@gmail.com
|
@@ -113,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
99
|
version: '0'
|
114
100
|
requirements: []
|
115
101
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.4.3
|
117
103
|
signing_key:
|
118
104
|
specification_version: 4
|
119
105
|
summary: Time-Related Scope for ActiveRecord
|