active_record-enum_with_label 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -7
- data/lib/active_record/enum_with_label/version.rb +1 -1
- data/lib/active_record/enum_with_label.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7b17fe47a574c80efdc8dc961516654bbd97c84
|
4
|
+
data.tar.gz: 6953aebfc44fc4551f45ad9ce7a36a414eb56fd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09f12f5affb2b1fed5f712a8eb506c8085a55970230f296d1b6f37e33389d905ee64dc5f8951e5d3034b42838cc40aab17c2c33d1a6338e28948e220402aa566
|
7
|
+
data.tar.gz: e8fe36c201536a9e4e0513ba66bb9352ae05f30476470e55192c9e26b62ac62630eb81d583f06ecb32e22003ea679d82aab11aef462198b9cffe20fbafdb9047
|
data/README.md
CHANGED
@@ -23,16 +23,15 @@ Or install it yourself as:
|
|
23
23
|
class User < ActiveRecord::Base
|
24
24
|
include ActiveRecord::EnumWithLabel
|
25
25
|
|
26
|
-
enum_with_label :
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
},
|
26
|
+
enum_with_label :alert_status, {
|
27
|
+
alert_status_none: 'なし',
|
28
|
+
alert_status_mail_sent: 'メール送信',
|
29
|
+
alert_status_telephoned: '電話',
|
31
30
|
}
|
32
31
|
end
|
33
32
|
|
34
|
-
User.
|
35
|
-
User.create(
|
33
|
+
User.alert_status_labels # => ['なし', 'メール送信', '電話']
|
34
|
+
User.create(alert_status: :alert_status_none).alert_status_label # => 'なし'
|
36
35
|
|
37
36
|
```
|
38
37
|
```ruby
|
@@ -15,14 +15,14 @@ module ActiveRecord
|
|
15
15
|
hash.transform_values { |h| { label: h } }
|
16
16
|
)
|
17
17
|
when first_value.is_a?(Hash)
|
18
|
+
first_value = nil
|
18
19
|
self.enum(name => hash.keys)
|
19
|
-
|
20
|
-
using_keys.each do |key|
|
20
|
+
hash.values.first.keys.each do |key|
|
21
21
|
self.define_singleton_method("#{name}_#{key.to_s.pluralize}") do
|
22
22
|
hash.transform_values { |x| x[key] }.values
|
23
23
|
end
|
24
24
|
self.instance_eval do
|
25
|
-
self.send(:define_method, "#{name}_#{key}") { hash[
|
25
|
+
self.send(:define_method, "#{name}_#{key}") { hash[public_send(name).to_sym][key] }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
else
|