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 +4 -4
- data/README.md +27 -3
- data/lib/simple_enum/translation.rb +2 -0
- data/lib/simple_enum/version.rb +1 -1
- data/spec/simple_enum/translation_spec.rb +4 -0
- data/spec/support/i18n_support.rb +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: 7331e48556b80c03d4dddd1c17d9d6c8b20b134b
|
4
|
+
data.tar.gz: 2c392e3587e6a6298d6fb50148283fbfd6c3e334
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
data/lib/simple_enum/version.rb
CHANGED
@@ -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::
|
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.
|
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-
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|