flexible_enum 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +14 -3
- data/Appraisals +4 -0
- data/CHANGELOG.md +10 -0
- data/README.md +18 -0
- data/flexible_enum.gemspec +2 -1
- data/gemfiles/rails_5.0.gemfile +7 -0
- data/lib/flexible_enum/scope_configurator.rb +6 -0
- data/lib/flexible_enum/version.rb +1 -1
- data/spec/scopes_spec.rb +15 -0
- data/spec/spec_helper.rb +1 -1
- metadata +24 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 261435611285df8117f8eb4507968098af93009c
|
4
|
+
data.tar.gz: b1cfddfb7d6e0829f8864ff2794619a2bb58bf59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8768a09ca2910c8d36ebb3eb155702158ed6f74cce6d8f9b4e0a02a0d0248c648839c06c4fa4ee3ab39d74ce0b1eead390459c7701b882ac5dfcac8041417419
|
7
|
+
data.tar.gz: b30f0f5dbbe17899be3e5b2beb7602d11fc310bc25c1a6dfed034357a5433d37ef1bf8688941ff8da7297559f80c697f40daca53ed66c4bf13cb2a86ab394607
|
data/.travis.yml
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
---
|
2
2
|
language: ruby
|
3
|
-
rvm:
|
4
|
-
|
5
|
-
|
3
|
+
rvm:
|
4
|
+
- 2.1.8
|
5
|
+
- 2.2.4
|
6
|
+
- 2.3.0
|
7
|
+
gemfile:
|
8
|
+
- gemfiles/rails_4.1.gemfile
|
9
|
+
- gemfiles/rails_4.2.gemfile
|
10
|
+
- gemfiles/rails_5.0.gemfile
|
11
|
+
script: bundle exec rspec spec
|
12
|
+
matrix:
|
13
|
+
fast_finish: true
|
14
|
+
exclude:
|
15
|
+
- rvm: 2.1.8
|
16
|
+
gemfile: gemfiles/rails_5.0.gemfile
|
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -202,6 +202,24 @@ CashRegister.drawer_position_opened # => CashRegister.where(drawer_position: 0)
|
|
202
202
|
CashRegister.drawer_position_closed # => CashRegister.where(drawer_position: 1)
|
203
203
|
```
|
204
204
|
|
205
|
+
Inverse scopes can be added by setting the :inverse configuration parameter:
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
class Car < ActiveRecord::Base
|
209
|
+
flexible_enum :fuel_type do
|
210
|
+
gasoline 0
|
211
|
+
diesel 1
|
212
|
+
electric 2, inverse: :carbon_emitter
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
gas = Car.create(fuel_type: Car::GASOLINE)
|
217
|
+
diesel = Car.create(fuel_type: Car::DIESEL)
|
218
|
+
electric = Car.create(fuel_type: Car::ELECTRIC)
|
219
|
+
|
220
|
+
Car.carbon_emitter # => [gasoline, diesel]
|
221
|
+
```
|
222
|
+
|
205
223
|
### Note about default scopes
|
206
224
|
|
207
225
|
Be careful when using default scopes on FlexibleEnum columns. Since FlexibleEnum provides scopes for enum values, setting a `default_scope` on a FlexibleEnum column will result in conflicts. For example, given this model:
|
data/flexible_enum.gemspec
CHANGED
@@ -21,8 +21,9 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.test_files = spec.files.grep(%r{^spec/})
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.add_dependency "activesupport", "
|
24
|
+
spec.add_dependency "activesupport", ">= 4.1"
|
25
25
|
|
26
|
+
spec.add_development_dependency "activerecord"
|
26
27
|
spec.add_development_dependency "appraisal"
|
27
28
|
spec.add_development_dependency "bundler", "~> 1.3"
|
28
29
|
spec.add_development_dependency "fury"
|
@@ -7,6 +7,12 @@ module FlexibleEnum
|
|
7
7
|
add_class_method(scope_name(element_name)) do
|
8
8
|
where(configurator.attribute_name => element_config[:value])
|
9
9
|
end
|
10
|
+
|
11
|
+
if element_config[:inverse]
|
12
|
+
add_class_method(scope_name(element_config[:inverse])) do
|
13
|
+
where.not(configurator.attribute_name => element_config[:value])
|
14
|
+
end
|
15
|
+
end
|
10
16
|
end
|
11
17
|
end
|
12
18
|
|
data/spec/scopes_spec.rb
CHANGED
@@ -10,6 +10,14 @@ describe "scopes" do
|
|
10
10
|
expect(CashRegister.unknown).to be_empty
|
11
11
|
end
|
12
12
|
|
13
|
+
it "builds scopes for inverse elements" do
|
14
|
+
unknowns = CashRegister.create!(status: CashRegister::UNKNOWN)
|
15
|
+
actives = CashRegister.create!(status: CashRegister::ACTIVE)
|
16
|
+
alarms = CashRegister.create!(status: CashRegister::ALARM)
|
17
|
+
|
18
|
+
expect(CashRegister.known).to contain_exactly(actives, alarms)
|
19
|
+
end
|
20
|
+
|
13
21
|
it "builds scopes with prefixed names for each namespaced element" do
|
14
22
|
opened = CashRegister.new.tap(&:open!)
|
15
23
|
closed = CashRegister.new.tap(&:close!)
|
@@ -17,4 +25,11 @@ describe "scopes" do
|
|
17
25
|
expect(CashRegister.drawer_position_opened).to contain_exactly(opened)
|
18
26
|
expect(CashRegister.drawer_position_closed).to contain_exactly(closed)
|
19
27
|
end
|
28
|
+
|
29
|
+
it "builds inverse scopes with prefixed names for each namespaced element" do
|
30
|
+
opened = CashRegister.new.tap(&:open!)
|
31
|
+
closed = CashRegister.new.tap(&:close!)
|
32
|
+
|
33
|
+
expect(CashRegister.drawer_position_not_open).to contain_exactly(closed)
|
34
|
+
end
|
20
35
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexible_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Daubert
|
8
8
|
- Alex Robbin
|
9
|
-
- Adam Prescott
|
10
9
|
- Matthew Daubert
|
10
|
+
- Adam Prescott
|
11
11
|
- Alex Robbin
|
12
12
|
- Sean Santry
|
13
13
|
- Chad Dressler
|
14
14
|
- Adam Prescott
|
15
|
+
- Zach Fletcher
|
15
16
|
- David Larrabee
|
16
17
|
- Sean Santry
|
17
18
|
- jon.zeppieri
|
@@ -21,22 +22,36 @@ authors:
|
|
21
22
|
autorequire:
|
22
23
|
bindir: bin
|
23
24
|
cert_chain: []
|
24
|
-
date:
|
25
|
+
date: 2016-04-15 00:00:00.000000000 Z
|
25
26
|
dependencies:
|
26
27
|
- !ruby/object:Gem::Dependency
|
27
28
|
name: activesupport
|
28
29
|
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- - "
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '4.1'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
36
|
version_requirements: !ruby/object:Gem::Requirement
|
36
37
|
requirements:
|
37
|
-
- - "
|
38
|
+
- - ">="
|
38
39
|
- !ruby/object:Gem::Version
|
39
40
|
version: '4.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
40
55
|
- !ruby/object:Gem::Dependency
|
41
56
|
name: appraisal
|
42
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,12 +140,13 @@ description: Helpers for enum-like fields
|
|
125
140
|
email:
|
126
141
|
- matt.daubert@meyouhealth.com
|
127
142
|
- alex.robbin@meyouhealth.com
|
128
|
-
- adam@aprescott.com
|
129
143
|
- mdaubert@gmail.com
|
144
|
+
- adam@aprescott.com
|
130
145
|
- alex@robbinsweb.biz
|
131
146
|
- sean.santry@meyouhealth.com
|
132
147
|
- chad@dresslerfamily.com
|
133
148
|
- adam.prescott@meyouhealth.com
|
149
|
+
- zach.fletcher@meyouhealth.com
|
134
150
|
- david.larrabee@meyouhealth.com
|
135
151
|
- sean@seansantry.com
|
136
152
|
- jon.zeppieri@meyouhealth.com
|
@@ -153,6 +169,7 @@ files:
|
|
153
169
|
- flexible_enum.gemspec
|
154
170
|
- gemfiles/rails_4.1.gemfile
|
155
171
|
- gemfiles/rails_4.2.gemfile
|
172
|
+
- gemfiles/rails_5.0.gemfile
|
156
173
|
- lib/flexible_enum.rb
|
157
174
|
- lib/flexible_enum/abstract_configurator.rb
|
158
175
|
- lib/flexible_enum/configuration.rb
|
@@ -194,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
211
|
version: '0'
|
195
212
|
requirements: []
|
196
213
|
rubyforge_project:
|
197
|
-
rubygems_version: 2.
|
214
|
+
rubygems_version: 2.5.1
|
198
215
|
signing_key:
|
199
216
|
specification_version: 4
|
200
217
|
summary: Helpers for enum-like fields
|