rails_string_enum 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -2
- data/lib/rails_string_enum/string_enum.rb +6 -4
- data/lib/rails_string_enum/version.rb +1 -1
- data/rails_string_enum.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 904f0f1d9b22dff24a5d59a8b4216bf302efbe4b
|
4
|
+
data.tar.gz: 3b1d3020043779055ce71c88faa530a801aa3d73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 289751c7cc14423b2162bebc8cf6a311816c7968470b8f3e1058ebd1089641936114d77477161c15b4940e2e669bfdf9095e3a7f1fa6b8044644ea6487f2c378
|
7
|
+
data.tar.gz: 54791a758953cae381c80f5ec2087ac2354ccac634b1e1b6d27c10439607a9bd7995afe03f5760a305e609216971065b15f8e777465f6775829cae78d8a72291
|
data/README.md
CHANGED
@@ -12,7 +12,10 @@ Add this line to your application's Gemfile:
|
|
12
12
|
Tested on Rails 4.2, ruby 2.2
|
13
13
|
|
14
14
|
#### Broken changes from 0.1 to 0.2
|
15
|
-
`Product::COLOR::GREEN
|
15
|
+
`Product::COLOR::GREEN -> Product::GREEN`
|
16
|
+
|
17
|
+
#### Broken changes from 0.2 to 0.3
|
18
|
+
`added prefix for scopes: Product.red -> Product.only_red or Product.only_reds`
|
16
19
|
|
17
20
|
#### Native postgresql enum (migrations)
|
18
21
|
```ruby
|
@@ -90,7 +93,8 @@ Product::GREEN # => "green"
|
|
90
93
|
|
91
94
|
Product.color_i18n_for('red') # => 'Красный'
|
92
95
|
Product.colors_i18n # => {green: 'Зеленый', red: 'Красный', yellow: 'Желтый'}
|
93
|
-
Product.
|
96
|
+
Product.only_red # if scopes: true
|
97
|
+
Product.only_reds # if scopes: { pluralize: true }
|
94
98
|
```
|
95
99
|
|
96
100
|
|
@@ -3,7 +3,7 @@ module RailsStringEnum
|
|
3
3
|
# product.rb
|
4
4
|
# string_enum :color, %w(red green yellow)
|
5
5
|
# page.rb
|
6
|
-
# string_enum :background, %w(red green), i18n_scope: 'product.color'
|
6
|
+
# string_enum :background, %w(red green), i18n_scope: 'product.color', scopes: { pluralize: true }
|
7
7
|
|
8
8
|
def string_enum(name, enums, scopes: false, i18n_scope: nil)
|
9
9
|
# create constant with all values
|
@@ -22,9 +22,11 @@ module RailsStringEnum
|
|
22
22
|
define_method("#{value}!") { update! name => value }
|
23
23
|
|
24
24
|
if scopes
|
25
|
-
# scope :
|
26
|
-
|
27
|
-
|
25
|
+
# scope :only_red, -> { where color: 'red' }
|
26
|
+
# scope :only_reds, -> { where color: 'red' } # if scopes: { pluralize: true }
|
27
|
+
scope_name = scopes.try(:fetch, :pluralize, nil) ? "only_#{value.to_s.pluralize}" : "only_#{value}"
|
28
|
+
klass.send(:detect_enum_conflict!, name, scope_name, true)
|
29
|
+
klass.scope scope_name, -> { klass.where name => value }
|
28
30
|
end
|
29
31
|
|
30
32
|
# Product::RED #=> "red"
|
data/rails_string_enum.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_string_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ermolaev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|