active_record-enum_with_label 0.1.2 → 0.1.3
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 +13 -11
- data/active_record-enum_with_label.gemspec +1 -1
- data/lib/active_record/enum_with_label.rb +5 -3
- data/lib/active_record/enum_with_label/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad5baa8cdf84e233025368d598346b5b7c9fe9c9
|
4
|
+
data.tar.gz: a7000192c30c9377df7b88c4b68208546ab43206
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d679c42960e1e28c8f421ccd29a743291dc78d9d9444256339f789ce1e573d7c11a4ae8e4469e42d5aa75d368494f323498cfcc8ad2690a191cd451edb35e53d
|
7
|
+
data.tar.gz: d5eb6cef7023bbe69eab14e2cf02e10c7ebd41149bbdfd2e4e48eb7b437ea571b08c65fb93f361bc218596a7bb8c92a5ea88c000e33fafd1a66a72a49fac1046
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActiveRecord::EnumWithLabel
|
2
2
|
|
3
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
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)
|
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
|
-
|
48
|
+
label: '新機能', value: 10, icon: '+1'
|
47
49
|
},
|
48
50
|
status_question: {
|
49
|
-
|
51
|
+
label: '質問', value: 15, icon: 'question_mark'
|
50
52
|
},
|
51
53
|
}
|
52
54
|
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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{
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
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.
|
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-
|
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:
|
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:
|
137
|
+
summary: ActiveRecord::EnumWithLabel adds label and more to ActiveRecord::Base.enum.
|
138
138
|
test_files: []
|