flexible_enum 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +40 -0
- data/lib/flexible_enum/scope_configurator.rb +1 -1
- data/lib/flexible_enum/version.rb +1 -1
- data/spec/scopes_spec.rb +0 -7
- data/spec/spec_helper.rb +0 -13
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd44f960187787c1fba3e7e58fc8a10797fb53a4
|
4
|
+
data.tar.gz: 3eb76c05d70ac78f139ba37adc28da37f1c19e77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1bafc6bc31b3fffd78ed8009ad0f34f9042933ae1e51130e08da9e4477d2c5680c61fa095070dda03bf31a87ba1bb7468c7bf8de21af4195280d59c0b715473
|
7
|
+
data.tar.gz: 886b3797babe232b1d82c1c7be6267263c48b372af5db846a14760f5fa374795160a33945f9b77cc1e507b57ffa4d7ef9d13a83d0f7f8cd217b06c4c94bf3e65
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
Current release (in development)
|
2
2
|
--------------------------------
|
3
3
|
|
4
|
+
* ...
|
5
|
+
|
6
|
+
0.4.0
|
7
|
+
-----
|
8
|
+
|
9
|
+
* Revert #4. Scopes provided by flexible_enum no longer attempt to overwrite pre-existing `WHERE` conditions on the enum column. #30
|
10
|
+
|
11
|
+
*Alex Robbin*
|
12
|
+
|
13
|
+
0.3.0
|
14
|
+
-----
|
15
|
+
|
4
16
|
* Adds `[option_name]_details` method to retrieve custom attributes of the
|
5
17
|
current enum option. #24
|
6
18
|
|
data/README.md
CHANGED
@@ -202,6 +202,33 @@ 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
|
+
### Note about default scopes
|
206
|
+
|
207
|
+
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:
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
class User < ActiveRecord::Base
|
211
|
+
flexible_enum :status do
|
212
|
+
active 1
|
213
|
+
inactive 2
|
214
|
+
end
|
215
|
+
|
216
|
+
default_scope -> { where(status: ACTIVE) }
|
217
|
+
end
|
218
|
+
```
|
219
|
+
|
220
|
+
Attempts to use the `User.inactive` scope that FlexibleEnum provides will result in this SQL:
|
221
|
+
|
222
|
+
```sql
|
223
|
+
SELECT * FROM users WHERE users.status = 1 AND users.status = 2
|
224
|
+
```
|
225
|
+
|
226
|
+
You will need to `unscope` the `default_scope` before using a FlexibleEnum-provided scope (as you would have to do for normal Rails scopes that happen to contradict each other).
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
User.unscope(where: :status).inactive
|
230
|
+
```
|
231
|
+
|
205
232
|
## Custom Options
|
206
233
|
|
207
234
|
Configuration parameters passed to attribute options are saved even if they are unknown.
|
@@ -293,6 +320,19 @@ end
|
|
293
320
|
|
294
321
|
Please see [CONTRIBUTING.md](https://github.com/meyouhealth/flexible_enum/blob/master/CONTRIBUTING.md).
|
295
322
|
|
323
|
+
## Releasing
|
324
|
+
|
325
|
+
* On master in a commit named `Version x.y.z` update [version.rb](lib/flexible_enum/version.rb) and [CHANGELOG.md](CHANGELOG.md) with the new version.
|
326
|
+
|
327
|
+
* Run `rake release` to build and release to Rubygems.
|
328
|
+
|
329
|
+
* Run `git push origin master --tags` to push master and the new tag (created automatically in previous step) to Github.
|
330
|
+
|
331
|
+
* Create a Github release including the new change log entries in the description.
|
332
|
+
|
333
|
+
* Thank contributors via Twitter.
|
334
|
+
|
335
|
+
|
296
336
|
## About MeYou Health
|
297
337
|
|
298
338
|
![http://meyouhealth.com/](https://avatars3.githubusercontent.com/u/249181?v=3&s=200)
|
@@ -5,7 +5,7 @@ module FlexibleEnum
|
|
5
5
|
|
6
6
|
elements.each do |element_name, element_config|
|
7
7
|
add_class_method(scope_name(element_name)) do
|
8
|
-
|
8
|
+
where(configurator.attribute_name => element_config[:value])
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/spec/scopes_spec.rb
CHANGED
@@ -17,11 +17,4 @@ describe "scopes" do
|
|
17
17
|
expect(CashRegister.drawer_position_opened).to contain_exactly(opened)
|
18
18
|
expect(CashRegister.drawer_position_closed).to contain_exactly(closed)
|
19
19
|
end
|
20
|
-
|
21
|
-
it "builds scopes that aren't affected by default scopes" do
|
22
|
-
WithDefaultScope.new.tap(&:active!)
|
23
|
-
passive = WithDefaultScope.new.tap(&:passive!)
|
24
|
-
|
25
|
-
expect(WithDefaultScope.passive).to contain_exactly(passive)
|
26
|
-
end
|
27
20
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,10 +21,6 @@ ActiveRecord::Schema.define do
|
|
21
21
|
t.string "manufacturer"
|
22
22
|
t.integer "drawer_position"
|
23
23
|
end
|
24
|
-
|
25
|
-
create_table "with_default_scopes" do |t|
|
26
|
-
t.integer "status"
|
27
|
-
end
|
28
24
|
end
|
29
25
|
|
30
26
|
class CashRegister < ActiveRecord::Base
|
@@ -47,12 +43,3 @@ class CashRegister < ActiveRecord::Base
|
|
47
43
|
sharp "SHCAY"
|
48
44
|
end
|
49
45
|
end
|
50
|
-
|
51
|
-
class WithDefaultScope < ActiveRecord::Base
|
52
|
-
flexible_enum :status do
|
53
|
-
active 0
|
54
|
-
passive 1
|
55
|
-
end
|
56
|
-
|
57
|
-
default_scope { where(status: ACTIVE) }
|
58
|
-
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexible_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Daubert
|
8
8
|
- Alex Robbin
|
9
9
|
- Adam Prescott
|
10
10
|
- Matthew Daubert
|
11
|
-
- Sean Santry
|
12
11
|
- Alex Robbin
|
12
|
+
- Sean Santry
|
13
13
|
- Chad Dressler
|
14
14
|
- Adam Prescott
|
15
15
|
- David Larrabee
|
16
16
|
- Sean Santry
|
17
|
+
- jon.zeppieri
|
17
18
|
- David C. Goldhirsch
|
18
19
|
- Guillermo Guerini
|
19
20
|
- Matthew Daubert
|
20
|
-
- jon.zeppieri
|
21
21
|
autorequire:
|
22
22
|
bindir: bin
|
23
23
|
cert_chain: []
|
24
|
-
date: 2015-
|
24
|
+
date: 2015-09-28 00:00:00.000000000 Z
|
25
25
|
dependencies:
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: activesupport
|
@@ -127,16 +127,16 @@ email:
|
|
127
127
|
- alex.robbin@meyouhealth.com
|
128
128
|
- adam@aprescott.com
|
129
129
|
- mdaubert@gmail.com
|
130
|
-
- sean.santry@meyouhealth.com
|
131
130
|
- alex@robbinsweb.biz
|
131
|
+
- sean.santry@meyouhealth.com
|
132
132
|
- chad@dresslerfamily.com
|
133
133
|
- adam.prescott@meyouhealth.com
|
134
134
|
- david.larrabee@meyouhealth.com
|
135
135
|
- sean@seansantry.com
|
136
|
+
- jon.zeppieri@meyouhealth.com
|
136
137
|
- dgoldhirsch@yahoo.com
|
137
138
|
- guillermo@gguerini.com
|
138
139
|
- mdaubert+github@gmail.com
|
139
|
-
- jon.zeppieri@meyouhealth.com
|
140
140
|
executables: []
|
141
141
|
extensions: []
|
142
142
|
extra_rdoc_files: []
|
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
196
|
rubyforge_project:
|
197
|
-
rubygems_version: 2.4.5
|
197
|
+
rubygems_version: 2.4.5.1
|
198
198
|
signing_key:
|
199
199
|
specification_version: 4
|
200
200
|
summary: Helpers for enum-like fields
|