enumerate_it 1.2.2 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.markdown +9 -0
- data/lib/enumerate_it/class_methods.rb +6 -4
- data/lib/enumerate_it/version.rb +1 -1
- data/spec/enumerate_it_spec.rb +15 -0
- data/spec/support/test_classes.rb +4 -0
- metadata +37 -17
- checksums.yaml +0 -15
data/Gemfile.lock
CHANGED
data/README.markdown
CHANGED
@@ -364,6 +364,15 @@ This will create:
|
|
364
364
|
#=> SELECT "people".* FROM "people" WHERE "people"."relationship_status" = 1
|
365
365
|
```
|
366
366
|
|
367
|
+
The :create_scopes also accepts :prefix option.
|
368
|
+
|
369
|
+
``` ruby
|
370
|
+
class Person < ActiveRecord::Base
|
371
|
+
has_enumeration_for :relationship_status, :with => RelationshipStatus, :create_scopes => { :prefix => true }
|
372
|
+
end
|
373
|
+
|
374
|
+
Person.relationship_status_married.to_sql
|
375
|
+
```
|
367
376
|
|
368
377
|
NOTE: The :create_scopes option can only be used for Rails.version >= 3.0.0.
|
369
378
|
|
@@ -16,7 +16,7 @@ module EnumerateIt
|
|
16
16
|
end
|
17
17
|
|
18
18
|
if options[:create_scopes]
|
19
|
-
create_scopes options[:with], attribute
|
19
|
+
create_scopes options[:with], attribute, options[:create_scopes]
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -47,10 +47,12 @@ module EnumerateIt
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def create_scopes(klass, attribute_name)
|
51
|
-
|
50
|
+
def create_scopes(klass, attribute_name, helpers)
|
51
|
+
prefix_name = "#{attribute_name}_" if helpers.is_a?(Hash) && helpers[:prefix]
|
52
|
+
|
53
|
+
klass.enumeration.keys.each do |key|
|
52
54
|
if respond_to? :scope
|
53
|
-
scope
|
55
|
+
scope "#{prefix_name}#{key}", lambda { where(attribute_name => klass.enumeration[key].first)}
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
data/lib/enumerate_it/version.rb
CHANGED
data/spec/enumerate_it_spec.rb
CHANGED
@@ -268,6 +268,21 @@ describe EnumerateIt do
|
|
268
268
|
}.to_not raise_error
|
269
269
|
end
|
270
270
|
end
|
271
|
+
|
272
|
+
context "with :prefix option" do
|
273
|
+
before do
|
274
|
+
class OtherTestClass
|
275
|
+
extend EnumerateIt
|
276
|
+
has_enumeration_for :foobar, :with => TestEnumerationWithReservedWords, :create_scopes => { :prefix => true }
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
it "creates a scope with prefix for each enumeration value" do
|
281
|
+
TestEnumerationWithReservedWords.enumeration.keys.each do |symbol|
|
282
|
+
OtherTestClass.should respond_to(:"foobar_#{symbol}")
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
271
286
|
end
|
272
287
|
end
|
273
288
|
|
@@ -27,6 +27,10 @@ class TestEnumerationWithList < EnumerateIt::Base
|
|
27
27
|
associate_values :first, :second
|
28
28
|
end
|
29
29
|
|
30
|
+
class TestEnumerationWithReservedWords < EnumerateIt::Base
|
31
|
+
associate_values :new => 1, :no_schedule => 2, :with_schedule => 3, :suspended => 4
|
32
|
+
end
|
33
|
+
|
30
34
|
class Foobar < EnumerateIt::Base
|
31
35
|
associate_values(
|
32
36
|
:bar => 'foo'
|
metadata
CHANGED
@@ -1,99 +1,112 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerate_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Cássio Marques
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-25 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: activesupport
|
16
|
+
type: :runtime
|
15
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
16
19
|
requirements:
|
17
20
|
- - ! '>='
|
18
21
|
- !ruby/object:Gem::Version
|
19
22
|
version: 3.0.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
23
25
|
requirements:
|
24
26
|
- - ! '>='
|
25
27
|
- !ruby/object:Gem::Version
|
26
28
|
version: 3.0.0
|
29
|
+
prerelease: false
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rake
|
32
|
+
type: :development
|
29
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
30
35
|
requirements:
|
31
36
|
- - ! '>='
|
32
37
|
- !ruby/object:Gem::Version
|
33
38
|
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
37
41
|
requirements:
|
38
42
|
- - ! '>='
|
39
43
|
- !ruby/object:Gem::Version
|
40
44
|
version: '0'
|
45
|
+
prerelease: false
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rspec
|
48
|
+
type: :development
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
44
51
|
requirements:
|
45
52
|
- - ! '>='
|
46
53
|
- !ruby/object:Gem::Version
|
47
54
|
version: 2.5.0
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
55
|
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
51
57
|
requirements:
|
52
58
|
- - ! '>='
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: 2.5.0
|
61
|
+
prerelease: false
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: activerecord
|
64
|
+
type: :development
|
57
65
|
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
58
67
|
requirements:
|
59
68
|
- - ! '>='
|
60
69
|
- !ruby/object:Gem::Version
|
61
70
|
version: 3.0.5
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
71
|
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
65
73
|
requirements:
|
66
74
|
- - ! '>='
|
67
75
|
- !ruby/object:Gem::Version
|
68
76
|
version: 3.0.5
|
77
|
+
prerelease: false
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: pry
|
80
|
+
type: :development
|
71
81
|
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
72
83
|
requirements:
|
73
84
|
- - ! '>='
|
74
85
|
- !ruby/object:Gem::Version
|
75
86
|
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
87
|
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
79
89
|
requirements:
|
80
90
|
- - ! '>='
|
81
91
|
- !ruby/object:Gem::Version
|
82
92
|
version: '0'
|
93
|
+
prerelease: false
|
83
94
|
- !ruby/object:Gem::Dependency
|
84
95
|
name: pry-nav
|
96
|
+
type: :development
|
85
97
|
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
86
99
|
requirements:
|
87
100
|
- - ! '>='
|
88
101
|
- !ruby/object:Gem::Version
|
89
102
|
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
103
|
version_requirements: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
93
105
|
requirements:
|
94
106
|
- - ! '>='
|
95
107
|
- !ruby/object:Gem::Version
|
96
108
|
version: '0'
|
109
|
+
prerelease: false
|
97
110
|
description: Enumerations for Ruby with some magic powers!
|
98
111
|
email:
|
99
112
|
- cassiommc@gmail.com
|
@@ -130,26 +143,33 @@ files:
|
|
130
143
|
- spec/support/test_classes.rb
|
131
144
|
homepage: http://github.com/cassiomarques/enumerate_it
|
132
145
|
licenses: []
|
133
|
-
metadata: {}
|
134
146
|
post_install_message:
|
135
147
|
rdoc_options: []
|
136
148
|
require_paths:
|
137
149
|
- lib
|
138
150
|
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
139
152
|
requirements:
|
140
153
|
- - ! '>='
|
141
154
|
- !ruby/object:Gem::Version
|
155
|
+
segments:
|
156
|
+
- 0
|
142
157
|
version: '0'
|
158
|
+
hash: -4367608046587642592
|
143
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
144
161
|
requirements:
|
145
162
|
- - ! '>='
|
146
163
|
- !ruby/object:Gem::Version
|
164
|
+
segments:
|
165
|
+
- 0
|
147
166
|
version: '0'
|
167
|
+
hash: -4367608046587642592
|
148
168
|
requirements: []
|
149
169
|
rubyforge_project:
|
150
|
-
rubygems_version:
|
170
|
+
rubygems_version: 1.8.24
|
151
171
|
signing_key:
|
152
|
-
specification_version:
|
172
|
+
specification_version: 3
|
153
173
|
summary: Ruby Enumerations
|
154
174
|
test_files:
|
155
175
|
- spec/enumerate_it/base_spec.rb
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
Mjk3OWI5YmVhYjVkZWUxN2ZhNzVlMWVkYjRhZDhlNDQwZWY2NjQ4ZQ==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
M2QzNTcwYTQzOTU2ZmQ1MzBjMzc2YWVlMDkwMmE5NjJlNDNlYjRlOA==
|
7
|
-
SHA512:
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
NjQ2OWVhNDVhZjg0MjJmZGRkMzYxODU5MWY1ZTFlYTc3ZDk0ZGFiNjBkYjA5
|
10
|
-
M2E1YTYwOGZjMjU1ZjQyNjcyMTNmODkxMDdhNzEyM2IzYTk3OTg2YmQzODVk
|
11
|
-
YTFmNzA5ZTU0NTYyNmJjZTIwYzYzZTZhZTNjOTk1MzgyNDY3NWQ=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NzIzZjY4YTgwM2FiNGI0MTQxNmZmY2JhYWUyYjk3YzJhYTlkOTY2ZmE1ZjJm
|
14
|
-
ODljNmQwNjVkNTczMjY5NzAzOGI5MjU4ODE4OTY3Yzc1MmQ5OTBjODUyMzI2
|
15
|
-
Y2RjMmNiOTZjY2I2ZGM4NDgzNzllNzY0MWRhNDUzMDFlZmI4NWU=
|