rails_scopes 0.0.2 → 0.0.3
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/Gemfile +4 -0
- data/lib/rails_scopes/date_scopes.rb +44 -0
- data/lib/rails_scopes/scopes_combiner.rb +1 -1
- data/lib/rails_scopes.rb +1 -0
- data/rails_scopes.gemspec +1 -1
- data/spec/rails_scopes/date_scopes_spec.rb +62 -0
- data/spec/rails_scopes/scope_combiner_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af0117fd1538ba271b61dc609ea1a8ee0bcb37d9
|
4
|
+
data.tar.gz: 89ea49aa4d02a7d7884db60c86abd5587f9612de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b02eddcad3ba657590da259db430355798d7aea7c831a4734f58f496bcb036687f8dc2c6452dbe2173e7eac3acd34e833fddefcf58109489bb6443defdf2854b
|
7
|
+
data.tar.gz: ae4c248e01d1c188a5e8e0a9809d6384362df356d52f7bde4666efd936259d2afbb8e064109523bc5b4163f66a791410a6f4a85c7f75b6faad46c19354e6c14a
|
data/Gemfile
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
module RailsScopes
|
2
|
+
module DateScopes
|
3
|
+
|
4
|
+
def date_scopes_names(attribute_names)
|
5
|
+
attribute_names.each.map do |name|
|
6
|
+
[ "#{name}_between",
|
7
|
+
"#{name}_less_equal_than",
|
8
|
+
"#{name}_greater_equal_than" ]
|
9
|
+
end.flatten
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_date_scopes_for(attribute_names)
|
13
|
+
attribute_names.each do |attr_name|
|
14
|
+
create_between_scope(attr_name)
|
15
|
+
create_less_equal_scope(attr_name)
|
16
|
+
create_greater_equal_scope(attr_name)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_between_scope(attr_name, scope_name = nil)
|
21
|
+
scope_name ||= "#{attr_name}_between"
|
22
|
+
define_singleton_method(scope_name) do |start_date, end_date|
|
23
|
+
s = format_date(start_date).beginning_of_day
|
24
|
+
e = format_date(end_date).end_of_day
|
25
|
+
where(attr_name => (s..e))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_less_equal_scope(attr_name, scope_name = nil)
|
30
|
+
scope_name ||= "#{attr_name}_less_equal_than"
|
31
|
+
define_singleton_method(scope_name) do |date|
|
32
|
+
where("#{attr_name.to_s} <= ?", format_date(date).end_of_day)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_greater_equal_scope(attr_name, scope_name = nil)
|
37
|
+
scope_name ||= "#{attr_name}_greater_equal_than"
|
38
|
+
define_singleton_method(scope_name) do |date|
|
39
|
+
where("#{attr_name.to_s} >= ?", format_date(date).beginning_of_day)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/rails_scopes.rb
CHANGED
data/rails_scopes.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "rails_scopes"
|
8
|
-
spec.version = "0.0.
|
8
|
+
spec.version = "0.0.3"
|
9
9
|
spec.authors = ["marcelorxs"]
|
10
10
|
spec.email = ["marcelorxs@gmail.com"]
|
11
11
|
spec.summary = "A gem for generating rails active record common scopes"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsScopes::DateScopes do
|
4
|
+
|
5
|
+
let(:example1) do
|
6
|
+
class Example
|
7
|
+
extend RailsScopes::DateScopes
|
8
|
+
|
9
|
+
@dates = [ :payment_date, :expiration_date, :period_start ]
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_reader :dates
|
13
|
+
end
|
14
|
+
|
15
|
+
create_date_scopes_for dates
|
16
|
+
self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:example2) do
|
21
|
+
class Example
|
22
|
+
extend RailsScopes::DateScopes
|
23
|
+
|
24
|
+
create_between_scope :payment_date, :payment_between
|
25
|
+
create_less_equal_scope :payment_date, :payment_end
|
26
|
+
create_greater_equal_scope :payment_date, :payment_start
|
27
|
+
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "RailsScopes::DateScopes" do
|
33
|
+
|
34
|
+
it "extends DateScopes" do
|
35
|
+
example1.should respond_to :date_scopes_names
|
36
|
+
example1.should respond_to :create_between_scope
|
37
|
+
example1.should respond_to :create_date_scopes_for
|
38
|
+
example1.should respond_to :create_less_equal_scope
|
39
|
+
example1.should respond_to :create_greater_equal_scope
|
40
|
+
end
|
41
|
+
|
42
|
+
it "creates scopes for dates" do
|
43
|
+
example1.date_scopes_names(example1.dates).each do |name|
|
44
|
+
example1.should respond_to name
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "create scope for between" do
|
49
|
+
example2.should respond_to :payment_between
|
50
|
+
end
|
51
|
+
|
52
|
+
it "create scope for less/equal" do
|
53
|
+
example2.should respond_to :payment_end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "create scope for greater/equal" do
|
57
|
+
example2.should respond_to :payment_start
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -18,11 +18,11 @@ describe RailsScopes::ScopesCombiner do
|
|
18
18
|
describe "RailsScopes::ScopesCombiner" do
|
19
19
|
|
20
20
|
it "extends ScopesCombiner" do
|
21
|
-
example.should respond_to :
|
21
|
+
example.should respond_to :combined_scopes_names
|
22
22
|
end
|
23
23
|
|
24
24
|
it "creates methods for statuses" do
|
25
|
-
example.
|
25
|
+
example.combined_scopes_names(example.statuses).each do |name|
|
26
26
|
example.should respond_to name
|
27
27
|
end
|
28
28
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_scopes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- marcelorxs
|
@@ -66,8 +66,10 @@ files:
|
|
66
66
|
- Rakefile
|
67
67
|
- config.ru
|
68
68
|
- lib/rails_scopes.rb
|
69
|
+
- lib/rails_scopes/date_scopes.rb
|
69
70
|
- lib/rails_scopes/scopes_combiner.rb
|
70
71
|
- rails_scopes.gemspec
|
72
|
+
- spec/rails_scopes/date_scopes_spec.rb
|
71
73
|
- spec/rails_scopes/scope_combiner_spec.rb
|
72
74
|
- spec/spec_helper.rb
|
73
75
|
homepage: http://github.com/marcelorxaviers/ruby/rails_scopes
|
@@ -95,3 +97,4 @@ signing_key:
|
|
95
97
|
specification_version: 4
|
96
98
|
summary: A gem for generating rails active record common scopes
|
97
99
|
test_files: []
|
100
|
+
has_rdoc:
|