active_record-enum_with_label 0.1.2 → 0.1.3

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: c7b17fe47a574c80efdc8dc961516654bbd97c84
4
- data.tar.gz: 6953aebfc44fc4551f45ad9ce7a36a414eb56fd3
3
+ metadata.gz: ad5baa8cdf84e233025368d598346b5b7c9fe9c9
4
+ data.tar.gz: a7000192c30c9377df7b88c4b68208546ab43206
5
5
  SHA512:
6
- metadata.gz: 09f12f5affb2b1fed5f712a8eb506c8085a55970230f296d1b6f37e33389d905ee64dc5f8951e5d3034b42838cc40aab17c2c33d1a6338e28948e220402aa566
7
- data.tar.gz: e8fe36c201536a9e4e0513ba66bb9352ae05f30476470e55192c9e26b62ac62630eb81d583f06ecb32e22003ea679d82aab11aef462198b9cffe20fbafdb9047
6
+ metadata.gz: d679c42960e1e28c8f421ccd29a743291dc78d9d9444256339f789ce1e573d7c11a4ae8e4469e42d5aa75d368494f323498cfcc8ad2690a191cd451edb35e53d
7
+ data.tar.gz: d5eb6cef7023bbe69eab14e2cf02e10c7ebd41149bbdfd2e4e48eb7b437ea571b08c65fb93f361bc218596a7bb8c92a5ea88c000e33fafd1a66a72a49fac1046
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ActiveRecord::EnumWithLabel
2
2
 
3
- Add label and more to `ActiveRecord::Base.enum`.
3
+ `ActiveRecord::EnumWithLabel` adds label and more to `ActiveRecord::Base.enum`.
4
4
 
5
5
  ## Installation
6
6
 
@@ -24,14 +24,16 @@ class User < ActiveRecord::Base
24
24
  include ActiveRecord::EnumWithLabel
25
25
 
26
26
  enum_with_label :alert_status, {
27
- alert_status_none: 'なし',
28
- alert_status_mail_sent: 'メール送信',
29
- alert_status_telephoned: '電話',
27
+ alert_status_none: 'なし',
28
+ alert_status_mail_sent: 'メール送信',
29
+ alert_status_telephoned: '電話',
30
30
  }
31
31
  end
32
32
 
33
33
  User.alert_status_labels # => ['なし', 'メール送信', '電話']
34
- User.create(alert_status: :alert_status_none).alert_status_label # => 'なし'
34
+ user = User.create(alert_status: :alert_status_none)
35
+ user.alert_status_label # => 'なし'
36
+ user.alert_status_before_type_cast # => 0
35
37
 
36
38
  ```
37
39
  ```ruby
@@ -43,18 +45,18 @@ class Issue < ActiveRecord::Base
43
45
  label: '不具合', value: 5, icon: :fire
44
46
  },
45
47
  status_feature: {
46
- label: '新機能', value: 10, icon: '+1'
48
+ label: '新機能', value: 10, icon: '+1'
47
49
  },
48
50
  status_question: {
49
- label: '質問', value: 15, icon: 'question_mark'
51
+ label: '質問', value: 15, icon: 'question_mark'
50
52
  },
51
53
  }
52
54
  end
53
55
 
54
- user = Issue.create!(status: :status_bug)
55
- user.status_label # => '不具合'
56
- user.status_value # => 5
57
- user.status_icon # => :fire
56
+ issue = Issue.create!(status: :status_bug)
57
+ issue.status_label # => '不具合'
58
+ issue.status_icon # => :fire
59
+ issue.status_before_type_cast # => 5
58
60
  ```
59
61
 
60
62
  ## Contributing
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["jiikko"]
9
9
  spec.email = ["n905i.1214@gmail.com"]
10
10
 
11
- spec.summary = %q{Add label and more to `ActiveRecord::Base.enum`.}
11
+ spec.summary = %q{ActiveRecord::EnumWithLabel adds label and more to ActiveRecord::Base.enum.}
12
12
  spec.description = spec.summary
13
13
  spec.homepage = 'https://github.com/jiikko/active_record-enum_with_label'
14
14
 
@@ -15,9 +15,11 @@ module ActiveRecord
15
15
  hash.transform_values { |h| { label: h } }
16
16
  )
17
17
  when first_value.is_a?(Hash)
18
- first_value = nil
19
- self.enum(name => hash.keys)
20
- hash.values.first.keys.each do |key|
18
+ self.enum(
19
+ name => (first_value.key?(:value) ? hash.transform_values { |h| h[:value] } : hash.keys)
20
+ )
21
+ first_value.keys.each do |key|
22
+ next if key == :value
21
23
  self.define_singleton_method("#{name}_#{key.to_s.pluralize}") do
22
24
  hash.transform_values { |x| x[key] }.values
23
25
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module EnumWithLabel
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jiikko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-09 00:00:00.000000000 Z
11
+ date: 2017-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Add label and more to `ActiveRecord::Base.enum`.
97
+ description: ActiveRecord::EnumWithLabel adds label and more to ActiveRecord::Base.enum.
98
98
  email:
99
99
  - n905i.1214@gmail.com
100
100
  executables: []
@@ -134,5 +134,5 @@ rubyforge_project:
134
134
  rubygems_version: 2.5.1
135
135
  signing_key:
136
136
  specification_version: 4
137
- summary: Add label and more to `ActiveRecord::Base.enum`.
137
+ summary: ActiveRecord::EnumWithLabel adds label and more to ActiveRecord::Base.enum.
138
138
  test_files: []