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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8f5d799d80ef60d8cb5fddd1fb78e8e0993fae0
4
- data.tar.gz: 06de1d230ba2e95529ce9690c8f635268bd01971
3
+ metadata.gz: 904f0f1d9b22dff24a5d59a8b4216bf302efbe4b
4
+ data.tar.gz: 3b1d3020043779055ce71c88faa530a801aa3d73
5
5
  SHA512:
6
- metadata.gz: 57c1721baad65c2452550bbd173824bdbf38f641728b1c3e34e76753a464650072caaac6b0bbee379280027934bef1677705285fb09988a728065834079710b3
7
- data.tar.gz: f991aa54e4dcb8c8a57d42a6c4c08fda106a07327627df471d9f34f7ad89764be1721120ecf6394b59d7fbf2a506049a630d78e799abca4a11911f2fed3f0b3f
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 => Product::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.red # if scopes: true
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 :red, -> { where color: 'red' }
26
- klass.send(:detect_enum_conflict!, name, value, true)
27
- klass.scope value, -> { klass.where name => value }
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"
@@ -1,3 +1,3 @@
1
1
  module RailsStringEnum
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
 
25
25
  spec.add_dependency "activerecord", "~> 4.2"
26
-
26
+
27
27
  spec.required_ruby_version = '~> 2.0'
28
28
  end
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.2.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-12 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler