simple_enum 2.1.0 → 2.1.1

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: 764053ae9a23795f23ac3d6c9a108d5c1c17f307
4
- data.tar.gz: 7e3bf97b4177c12cf5582b1302dced1b90a90b39
3
+ metadata.gz: 7331e48556b80c03d4dddd1c17d9d6c8b20b134b
4
+ data.tar.gz: 2c392e3587e6a6298d6fb50148283fbfd6c3e334
5
5
  SHA512:
6
- metadata.gz: 5e40c68baf656cb1064153f47eb3cc826375d578988bd6260d5016bdce25e42accf6c3de77cce14adb0b44433f78a9389a4f3b581d54d74335871e635ab08b8b
7
- data.tar.gz: be89ccd3fa051379cc0ea45be3ceec545a14d1a0af4e5a6de5e2afc8bcc182922106e0719c0ebee5a894fdfce19f861abbc0b7bb428bfaa7330de5d89a78bf8a
6
+ metadata.gz: ede4ed642e42d1ba5414692390dc698633a0068dc476afd790016919cd5e22b3d2a2d3515b35e5816b8003ae1fc6d5e8bbb1280ed27876f74363899e9c68d6d9
7
+ data.tar.gz: 0d90bcc8dfe99ddd5b16c3004e280e7a1bd837830302257a54d2361f04b2280c3de330f1fd93c57bda0a414141e391d1452ea2d42a7ed6dc9bb5b4d59c6bdac4
data/README.md CHANGED
@@ -154,7 +154,6 @@ User.females # => #<ActiveRecord::Relation:0x0.....>
154
154
  user.gender_was
155
155
  # => :male
156
156
  ```
157
- - Require translated enum values? See [SimpleEnum::ViewHelpers](https://github.com/lwe/simple_enum/blob/master/lib/simple_enum/view_helpers.rb)
158
157
  - Need to provide custom options for the mongoid field, or skip the automatically generated field?
159
158
 
160
159
  ```ruby
@@ -212,6 +211,29 @@ User.females # => #<ActiveRecord::Relation:0x0.....>
212
211
  SimpleEnum.with = [:accessor, :scope]
213
212
  ```
214
213
 
214
+ ### View Helpers
215
+
216
+ Require translated enum values? See [SimpleEnum::ViewHelpers][VE.rb] for more
217
+ details and functions. _Disclaimer_: these methods are release candidate quality
218
+ so expect them to change in future versions of SimpleEnum.
219
+
220
+ - Translate the current value in a view:
221
+
222
+ ```ruby
223
+ translate_enum user, :gender # => "Frau" # assuming :de and translations exist
224
+ te user, :gender # translate_enum is also aliased to te
225
+ ```
226
+ - Build a select tag with a translated dropdown and symbol as value:
227
+
228
+ ```ruby
229
+ select :user, :gender, enum_option_pairs(User, :gender)
230
+ ```
231
+ - ...and one with the index as value:
232
+
233
+ ```ruby
234
+ select :user, :gender_cd, enum_option_pairs(User, :gender, true)
235
+ ```
236
+
215
237
  ## Best practices
216
238
 
217
239
  Do not use values named after existing, or well known method names, like `new`, `create` etc.
@@ -242,10 +264,12 @@ Contributors
242
264
  - @abrom - `find_by_...` method
243
265
  - @mhuggins - translations fixes
244
266
  - @patbenatar - for helping move towards 2.0 (scopes et all)
245
- - @abacha - translation helpers
267
+ - @abacha - translation helpers, README fixes
246
268
  - and all others: https://github.com/lwe/simple_enum/graphs/contributors thanks
247
269
 
248
270
  License & Copyright
249
271
  -------------------
250
272
 
251
- Copyright (c) 2011-2014 by Lukas Westermann, Licensed under MIT Licence (see LICENSE file)
273
+ Copyright (c) 2011-2014 by Lukas Westermann, Licensed under MIT License (see LICENSE file)
274
+
275
+ [VE.rb]: https://github.com/lwe/simple_enum/blob/master/lib/simple_enum/view_helpers.rb
@@ -3,6 +3,8 @@ require 'i18n'
3
3
  module SimpleEnum
4
4
  module Translation
5
5
  def human_enum_name(enum, key, options = {})
6
+ return '' unless key.present?
7
+
6
8
  defaults = lookup_ancestors.map do |klass|
7
9
  :"#{self.i18n_scope}.enums.#{klass.model_name.i18n_key}.#{enum}.#{key}"
8
10
  end
@@ -1,5 +1,5 @@
1
1
  module SimpleEnum
2
2
 
3
3
  # The current `SimpleEnum` version.
4
- VERSION = "2.1.0"
4
+ VERSION = "2.1.1"
5
5
  end
@@ -13,6 +13,10 @@ describe SimpleEnum::Translation do
13
13
  it 'translates :female to "Mrs."' do
14
14
  expect(subject.human_enum_name(:gender, :female)).to eq 'Mrs.'
15
15
  end
16
+
17
+ it 'returns empty string when key is missing' do
18
+ expect(subject.human_enum_name(:gender, nil)).to eq ''
19
+ end
16
20
  end
17
21
 
18
22
  context '{i18n_scope}.enums.{i18n_key}.gender.{key}' do
@@ -1,7 +1,7 @@
1
1
  module I18nSupport
2
2
  def self.included(base)
3
3
  base.let!(:i18n_previous_backend) { I18n.backend }
4
- base.let(:i18n_backend) { I18n::Backend::KeyValue.new({}) }
4
+ base.let(:i18n_backend) { I18n::Backend::Simple.new() }
5
5
  base.before { I18n.backend = i18n_backend }
6
6
  base.after { I18n.backend = i18n_previous_backend }
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Westermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-28 00:00:00.000000000 Z
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport