active_record-enum_with_label 0.1.1 → 0.1.2

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: 1641ed4c46867a9e271eae95dc8dec3f8c31a8c3
4
- data.tar.gz: 639de918e7be3ee7794d5667c2ad4a494703753d
3
+ metadata.gz: c7b17fe47a574c80efdc8dc961516654bbd97c84
4
+ data.tar.gz: 6953aebfc44fc4551f45ad9ce7a36a414eb56fd3
5
5
  SHA512:
6
- metadata.gz: 1b4802d7168397c7cf86612c0c3fb10bd1c023f6fa049fde3d4a092816635e9f4971b2edbd45ed6334cfed1ead72de94d1b145686b478ea3478eb958dc433f9b
7
- data.tar.gz: c818844f8326cbad8ae5b599c0bced1c4f4f757b34444f3a153b3ecaa3bb54a60341e539c2efde29cad3e0b36454cff7d473b8e13f10d4f5d36feb3d02bd6ca6
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 :status, {
27
- status_active: '有効',
28
- status_lock: 'ロック',
29
- status_non_activate: '未アクティベート',
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.status_labels # => ['有効', 'ロック', '未アクティベート']
35
- User.create(status: :status_active).status_label # => '有効'
33
+ User.alert_status_labels # => ['なし', 'メール送信', '電話']
34
+ User.create(alert_status: :alert_status_none).alert_status_label # => 'なし'
36
35
 
37
36
  ```
38
37
  ```ruby
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module EnumWithLabel
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -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
- using_keys = hash.values.first.keys
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[status.to_sym][key] }
25
+ self.send(:define_method, "#{name}_#{key}") { hash[public_send(name).to_sym][key] }
26
26
  end
27
27
  end
28
28
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-enum_with_label
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiikko