enum_ext 0.3.0 → 0.4.4
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 +5 -5
- data/.travis.yml +6 -0
- data/CHANGELOG.md +16 -0
- data/Gemfile.lock +58 -53
- data/README.md +26 -25
- data/enum_ext.gemspec +4 -3
- data/lib/enum_ext.rb +57 -32
- data/lib/enum_ext/version.rb +1 -1
- metadata +28 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 31b1c2e892139a6c351a6eceac3680a3f564175e74a590030923866e2ea1e23c
|
|
4
|
+
data.tar.gz: 43edecda5dbc4f647ab1e405647ae31dbf7c671d9fd16a17a65c6d922bee4dc4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86ee6244b2b81a2d70edae5c5675322feac5c9a7e69b7f141c0ce11f9f4a8eacc10f6ae16b6e5e4ed87f4852dd9a59b9120291e7c86456880908e9afbe4b8f32
|
|
7
|
+
data.tar.gz: 8b2468b334499d88c470b20d397b531ecb39344101c8366faa031ad1e58a70f0cebef70f4479aa67c8c7bd1670cfb8d9dbbf86eb9cdaee6270ea5f0a9f0ad14f
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# 0.4.4
|
|
2
|
+
* ext_enum_sets now can be executed without 'scope' definition present on the base class,
|
|
3
|
+
for instance you can now use with StoreModel's
|
|
4
|
+
|
|
5
|
+
# 0.4.3
|
|
6
|
+
* ext_enum_sets now can go without options just to define with and without scopes
|
|
7
|
+
|
|
8
|
+
# 0.4.2
|
|
9
|
+
* bugfix for localize_enum multiple call
|
|
10
|
+
* test added for 0.4.1 ver funcitonality ( multiple times humanize_enum calls )
|
|
11
|
+
* all assert( a == b ) replaced with assert_equal(a,b)
|
|
12
|
+
|
|
13
|
+
# 0.4.1
|
|
14
|
+
* security dependency issues resolved
|
|
15
|
+
* activerecord version raised
|
|
16
|
+
* humanize_enum could be called multiple times all definitions will be merged, i.e. there is no need to define all localizations in one place at once
|
data/Gemfile.lock
CHANGED
|
@@ -1,82 +1,87 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
enum_ext (0.
|
|
5
|
-
activerecord (>= 4.
|
|
4
|
+
enum_ext (0.4.4)
|
|
5
|
+
activerecord (>= 5.2.4.3)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actionpack (
|
|
11
|
-
actionview (=
|
|
12
|
-
activesupport (=
|
|
13
|
-
rack (~> 2.0)
|
|
14
|
-
rack-test (
|
|
10
|
+
actionpack (6.0.3.4)
|
|
11
|
+
actionview (= 6.0.3.4)
|
|
12
|
+
activesupport (= 6.0.3.4)
|
|
13
|
+
rack (~> 2.0, >= 2.0.8)
|
|
14
|
+
rack-test (>= 0.6.3)
|
|
15
15
|
rails-dom-testing (~> 2.0)
|
|
16
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
|
17
|
-
actionview (
|
|
18
|
-
activesupport (=
|
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
17
|
+
actionview (6.0.3.4)
|
|
18
|
+
activesupport (= 6.0.3.4)
|
|
19
19
|
builder (~> 3.1)
|
|
20
|
-
|
|
20
|
+
erubi (~> 1.4)
|
|
21
21
|
rails-dom-testing (~> 2.0)
|
|
22
|
-
rails-html-sanitizer (~> 1.
|
|
23
|
-
activemodel (
|
|
24
|
-
activesupport (=
|
|
25
|
-
activerecord (
|
|
26
|
-
activemodel (=
|
|
27
|
-
activesupport (=
|
|
28
|
-
|
|
29
|
-
activesupport (5.0.2)
|
|
22
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
23
|
+
activemodel (6.0.3.4)
|
|
24
|
+
activesupport (= 6.0.3.4)
|
|
25
|
+
activerecord (6.0.3.4)
|
|
26
|
+
activemodel (= 6.0.3.4)
|
|
27
|
+
activesupport (= 6.0.3.4)
|
|
28
|
+
activesupport (6.0.3.4)
|
|
30
29
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
31
|
-
i18n (
|
|
30
|
+
i18n (>= 0.7, < 2)
|
|
32
31
|
minitest (~> 5.1)
|
|
33
32
|
tzinfo (~> 1.1)
|
|
34
|
-
|
|
35
|
-
builder (3.2.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
|
34
|
+
builder (3.2.4)
|
|
35
|
+
byebug (11.1.3)
|
|
36
|
+
concurrent-ruby (1.1.7)
|
|
37
|
+
crass (1.0.6)
|
|
38
|
+
erubi (1.10.0)
|
|
39
|
+
i18n (1.8.5)
|
|
40
|
+
concurrent-ruby (~> 1.0)
|
|
41
|
+
loofah (2.8.0)
|
|
42
|
+
crass (~> 1.0.2)
|
|
40
43
|
nokogiri (>= 1.5.9)
|
|
41
|
-
method_source (0.
|
|
42
|
-
mini_portile2 (2.
|
|
43
|
-
minitest (5.
|
|
44
|
-
nokogiri (1.
|
|
45
|
-
mini_portile2 (~> 2.
|
|
46
|
-
rack (2.
|
|
47
|
-
rack-test (
|
|
48
|
-
rack (>= 1.0)
|
|
49
|
-
rails-dom-testing (2.0.
|
|
50
|
-
activesupport (>= 4.2.0
|
|
51
|
-
nokogiri (
|
|
52
|
-
rails-html-sanitizer (1.0
|
|
53
|
-
loofah (~> 2.
|
|
54
|
-
rails-i18n (
|
|
55
|
-
i18n (
|
|
56
|
-
railties (
|
|
57
|
-
railties (
|
|
58
|
-
actionpack (=
|
|
59
|
-
activesupport (=
|
|
44
|
+
method_source (1.0.0)
|
|
45
|
+
mini_portile2 (2.4.0)
|
|
46
|
+
minitest (5.14.2)
|
|
47
|
+
nokogiri (1.10.10)
|
|
48
|
+
mini_portile2 (~> 2.4.0)
|
|
49
|
+
rack (2.2.3)
|
|
50
|
+
rack-test (1.1.0)
|
|
51
|
+
rack (>= 1.0, < 3)
|
|
52
|
+
rails-dom-testing (2.0.3)
|
|
53
|
+
activesupport (>= 4.2.0)
|
|
54
|
+
nokogiri (>= 1.6)
|
|
55
|
+
rails-html-sanitizer (1.3.0)
|
|
56
|
+
loofah (~> 2.3)
|
|
57
|
+
rails-i18n (6.0.0)
|
|
58
|
+
i18n (>= 0.7, < 2)
|
|
59
|
+
railties (>= 6.0.0, < 7)
|
|
60
|
+
railties (6.0.3.4)
|
|
61
|
+
actionpack (= 6.0.3.4)
|
|
62
|
+
activesupport (= 6.0.3.4)
|
|
60
63
|
method_source
|
|
61
64
|
rake (>= 0.8.7)
|
|
62
|
-
thor (>= 0.
|
|
63
|
-
rake (
|
|
64
|
-
sqlite3 (1.
|
|
65
|
-
thor (0.
|
|
65
|
+
thor (>= 0.20.3, < 2.0)
|
|
66
|
+
rake (13.0.1)
|
|
67
|
+
sqlite3 (1.4.2)
|
|
68
|
+
thor (1.0.1)
|
|
66
69
|
thread_safe (0.3.6)
|
|
67
|
-
tzinfo (1.2.
|
|
70
|
+
tzinfo (1.2.8)
|
|
68
71
|
thread_safe (~> 0.1)
|
|
72
|
+
zeitwerk (2.4.2)
|
|
69
73
|
|
|
70
74
|
PLATFORMS
|
|
71
75
|
ruby
|
|
72
76
|
|
|
73
77
|
DEPENDENCIES
|
|
74
|
-
bundler (
|
|
78
|
+
bundler (>= 1.11)
|
|
79
|
+
byebug
|
|
75
80
|
enum_ext!
|
|
76
81
|
minitest
|
|
77
82
|
rails-i18n (>= 4)
|
|
78
|
-
rake (
|
|
83
|
+
rake (>= 10.0)
|
|
79
84
|
sqlite3
|
|
80
85
|
|
|
81
86
|
BUNDLED WITH
|
|
82
|
-
1.
|
|
87
|
+
2.1.4
|
data/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# EnumExt
|
|
2
2
|
|
|
3
|
-
EnumExt extends rails enum
|
|
3
|
+
EnumExt extends rails enum with localization/translation and it's helpers, mass-assign on scopes with bang, advanced sets logic over existing enum.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
Add this line to your application's Gemfile:
|
|
8
8
|
|
|
9
9
|
```ruby
|
|
10
|
-
gem 'enum_ext', '~> 0.
|
|
10
|
+
gem 'enum_ext', '~> 0.3'
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
And then execute:
|
|
@@ -19,7 +19,8 @@ Or install it yourself as:
|
|
|
19
19
|
$ gem install enum_ext
|
|
20
20
|
|
|
21
21
|
## Usage
|
|
22
|
-
To use enum extension extend main model class with EnumExt module,
|
|
22
|
+
To use enum extension extend main model class with EnumExt module,
|
|
23
|
+
and customize your enums the way you need:
|
|
23
24
|
|
|
24
25
|
class SomeModel
|
|
25
26
|
extend EnumExt
|
|
@@ -64,10 +65,10 @@ Or install it yourself as:
|
|
|
64
65
|
end
|
|
65
66
|
```
|
|
66
67
|
|
|
67
|
-
This
|
|
68
|
+
This humanize_enum adds to instance:
|
|
68
69
|
- t_in_cart, t_paid, t_ready_for_shipment
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
and to class:
|
|
71
72
|
- t_statuses - as given or generated values
|
|
72
73
|
- t_statuses_options - translated enum values options for select input
|
|
73
74
|
- t_statuses_options_i - same as above but use int values with translations works for ActiveAdmin filters for instance
|
|
@@ -103,6 +104,8 @@ Or install it yourself as:
|
|
|
103
104
|
request.t_status # >> "paid 3 dollars"
|
|
104
105
|
Request.t_statuses # >> { in_cart: -> { I18n.t("request.status.in_cart") }, .... }
|
|
105
106
|
```
|
|
107
|
+
|
|
108
|
+
Could be called multiple times, all humanization definitions will be merged under the hood.
|
|
106
109
|
|
|
107
110
|
### Translate (translate_enum)
|
|
108
111
|
|
|
@@ -140,21 +143,23 @@ Defines method enum_name_i shortcut for Model.enum_names[elem.enum_name]
|
|
|
140
143
|
in_warehouse: [:ready_for_shipment] # this just for superposition example below
|
|
141
144
|
}
|
|
142
145
|
```
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
146
|
+
it will generate:
|
|
147
|
+
```
|
|
148
|
+
instance:
|
|
149
|
+
- methods: delivery_set?, in_warehouse?
|
|
150
|
+
|
|
151
|
+
class:
|
|
152
|
+
- named scopes: delivery_set, in_warehouse
|
|
153
|
+
- parametrized scopes: with_statuses, without_statuses
|
|
154
|
+
class helpers:
|
|
155
|
+
- delivery_set_statuses (=[:ready_for_shipment, :on_delivery, :delivered] ), in_warehouse_statuses
|
|
156
|
+
- delivery_set_statuses_i (= [3,4,5]), in_warehouse_statuses_i (=[3])
|
|
157
|
+
|
|
158
|
+
class translation helpers ( started with t_... ):
|
|
159
|
+
- t_delivery_set_statuses_options (= [['translation or humanization', :ready_for_shipment] ...] ) for select inputs purposes
|
|
160
|
+
- t_delivery_set_statuses_options_i (= [['translation or humanization', 3] ...]) same as above but with integer as value ( for example to use in Active admin filters )
|
|
161
|
+
```
|
|
162
|
+
|
|
158
163
|
```
|
|
159
164
|
Console:
|
|
160
165
|
request.on_delivery!
|
|
@@ -189,7 +194,7 @@ Defines method enum_name_i shortcut for Model.enum_names[elem.enum_name]
|
|
|
189
194
|
some_scope.update_all(status: Request.statuses[:new_status], update_at: Time.now)
|
|
190
195
|
```
|
|
191
196
|
If you need callbacks you can do like this: some_scope.each(&:new_stat!) but if you don't need callbacks and you
|
|
192
|
-
|
|
197
|
+
have hundreds and thousands of records to change at once you need update_all
|
|
193
198
|
|
|
194
199
|
```
|
|
195
200
|
mass_assign_enum( :status )
|
|
@@ -204,8 +209,6 @@ Defines method enum_name_i shortcut for Model.enum_names[elem.enum_name]
|
|
|
204
209
|
request1.paid? # >> true
|
|
205
210
|
request2.paid? # >> true
|
|
206
211
|
request1.updated_at # >> ~ Time.now
|
|
207
|
-
defined?(Request::MassAssignEnum) # >> true
|
|
208
|
-
|
|
209
212
|
|
|
210
213
|
order.requests.already_paid.count # >> N
|
|
211
214
|
order.requests.delivered.count # >> M
|
|
@@ -214,8 +217,6 @@ Defines method enum_name_i shortcut for Model.enum_names[elem.enum_name]
|
|
|
214
217
|
order.requests.delivered.count # >> N + M
|
|
215
218
|
```
|
|
216
219
|
|
|
217
|
-
|
|
218
|
-
|
|
219
220
|
## Tests
|
|
220
221
|
rake test
|
|
221
222
|
|
data/enum_ext.gemspec
CHANGED
|
@@ -19,11 +19,12 @@ Gem::Specification.new do |spec|
|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
20
|
spec.require_paths = ["lib"]
|
|
21
21
|
|
|
22
|
-
spec.add_dependency 'activerecord',
|
|
22
|
+
spec.add_dependency 'activerecord', ">= 5.2.4.3"
|
|
23
23
|
|
|
24
24
|
spec.add_development_dependency 'minitest'
|
|
25
|
-
spec.add_development_dependency 'bundler', '
|
|
26
|
-
spec.add_development_dependency 'rake', '
|
|
25
|
+
spec.add_development_dependency 'bundler', '>= 1.11'
|
|
26
|
+
spec.add_development_dependency 'rake', '>= 10.0'
|
|
27
27
|
spec.add_development_dependency 'rails-i18n', '>=4'
|
|
28
28
|
spec.add_development_dependency 'sqlite3'
|
|
29
|
+
spec.add_development_dependency 'byebug'
|
|
29
30
|
end
|
data/lib/enum_ext.rb
CHANGED
|
@@ -14,7 +14,7 @@ require 'enum_ext/version'
|
|
|
14
14
|
module EnumExt
|
|
15
15
|
|
|
16
16
|
# defines shortcut for getting integer value of enum.
|
|
17
|
-
# for enum named status will generate:
|
|
17
|
+
# for enum named 'status' will generate:
|
|
18
18
|
# instance.status_i
|
|
19
19
|
def enum_i( enum_name )
|
|
20
20
|
define_method "#{enum_name}_i" do
|
|
@@ -32,7 +32,7 @@ module EnumExt
|
|
|
32
32
|
# For this call:
|
|
33
33
|
# ext_enum_sets :status, {
|
|
34
34
|
# delivery_set: [:ready_for_shipment, :on_delivery, :delivered] # for shipping department for example
|
|
35
|
-
# in_warehouse: [:ready_for_shipment]
|
|
35
|
+
# in_warehouse: [:ready_for_shipment] # this scope is just for superposition example below
|
|
36
36
|
# }
|
|
37
37
|
#
|
|
38
38
|
# it will generate:
|
|
@@ -69,27 +69,26 @@ module EnumExt
|
|
|
69
69
|
# ext_enum_sets :status, {
|
|
70
70
|
# outside_wharehouse: ( delivery_set_statuses - in_warehouse_statuses )... any other array operations like &, + and so can be used
|
|
71
71
|
# }
|
|
72
|
-
def ext_enum_sets( enum_name, options )
|
|
72
|
+
def ext_enum_sets( enum_name, options = {} )
|
|
73
73
|
enum_plural = enum_name.to_s.pluralize
|
|
74
74
|
|
|
75
75
|
self.instance_eval do
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
# with_enums scope
|
|
77
|
+
scope "with_#{enum_plural}", -> (sets_arr) {
|
|
78
|
+
where( enum_name => self.send( enum_plural ).slice(
|
|
79
|
+
*sets_arr.map{|set_name| self.try( "#{set_name}_#{enum_plural}" ) || set_name }.flatten.uniq.map(&:to_s) ).values )
|
|
80
|
+
} if !respond_to?("with_#{enum_plural}") && respond_to?(:scope)
|
|
79
81
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
} unless respond_to?("with_#{enum_plural}")
|
|
85
|
-
|
|
86
|
-
# without_enums scope
|
|
87
|
-
scope "without_#{enum_plural}", -> (sets_arr) {
|
|
88
|
-
where.not( id: self.send("with_#{enum_plural}", sets_arr) )
|
|
89
|
-
} unless respond_to?("without_#{enum_plural}")
|
|
82
|
+
# without_enums scope
|
|
83
|
+
scope "without_#{enum_plural}", -> (sets_arr) {
|
|
84
|
+
where.not( id: self.send("with_#{enum_plural}", sets_arr) )
|
|
85
|
+
} if !respond_to?("without_#{enum_plural}") && respond_to?(:scope)
|
|
90
86
|
|
|
87
|
+
options.each do |set_name, enum_vals|
|
|
88
|
+
# set_name scope
|
|
89
|
+
scope set_name, -> { where( enum_name => self.send( enum_plural ).slice( *enum_vals.map(&:to_s) ).values ) } if respond_to?(:scope)
|
|
91
90
|
|
|
92
|
-
|
|
91
|
+
# class.enum_set_values
|
|
93
92
|
define_singleton_method( "#{set_name}_#{enum_plural}" ) do
|
|
94
93
|
enum_vals
|
|
95
94
|
end
|
|
@@ -181,13 +180,22 @@ module EnumExt
|
|
|
181
180
|
# }
|
|
182
181
|
# end
|
|
183
182
|
#
|
|
183
|
+
# Could be called multiple times, all humanization definitions will be merged under the hood:
|
|
184
|
+
# humanize_enum :status, {
|
|
185
|
+
# payed: I18n.t("scope.#{status}")
|
|
186
|
+
# }
|
|
187
|
+
# humanize_enum :status, {
|
|
188
|
+
# billed: I18n.t("scope.#{status}")
|
|
189
|
+
# }
|
|
190
|
+
#
|
|
191
|
+
#
|
|
184
192
|
# Example with block:
|
|
185
193
|
#
|
|
186
194
|
# humanize_enum :status do
|
|
187
195
|
# I18n.t("scope.#{status}")
|
|
188
196
|
# end
|
|
189
197
|
#
|
|
190
|
-
# in select:
|
|
198
|
+
# in views select:
|
|
191
199
|
# f.select :status, Request.t_statuses_options
|
|
192
200
|
#
|
|
193
201
|
# in select in Active Admin filter
|
|
@@ -208,11 +216,28 @@ module EnumExt
|
|
|
208
216
|
|
|
209
217
|
self.instance_eval do
|
|
210
218
|
|
|
219
|
+
#t_enum
|
|
220
|
+
define_method "t_#{enum_name}" do
|
|
221
|
+
t = block || @@localizations.try(:with_indifferent_access)[send(enum_name)]
|
|
222
|
+
if t.try(:lambda?)
|
|
223
|
+
t.try(:arity) == 1 && t.call( self ) || t.try(:call)
|
|
224
|
+
elsif t.is_a?(Proc)
|
|
225
|
+
instance_eval(&t)
|
|
226
|
+
else
|
|
227
|
+
t
|
|
228
|
+
end.to_s
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
@@localizations ||= {}.with_indifferent_access
|
|
232
|
+
# if localization is abscent than block must be given
|
|
233
|
+
@@localizations.merge!(
|
|
234
|
+
localizations.try(:with_indifferent_access) ||
|
|
235
|
+
localizations ||
|
|
236
|
+
send(enum_plural).keys.map{|en| [en, Proc.new{ self.new({ enum_name => en }).send("t_#{enum_name}") }] }.to_h.with_indifferent_access
|
|
237
|
+
)
|
|
211
238
|
#t_enums
|
|
212
239
|
define_singleton_method( "t_#{enum_plural}" ) do
|
|
213
|
-
|
|
214
|
-
localizations.try(:with_indifferent_access) || localizations ||
|
|
215
|
-
send(enum_plural).keys.map {|en| [en, self.new( {enum_name => en} ).send("t_#{enum_name}")] }.to_h.with_indifferent_access
|
|
240
|
+
@@localizations
|
|
216
241
|
end
|
|
217
242
|
|
|
218
243
|
#t_enums_options
|
|
@@ -225,16 +250,8 @@ module EnumExt
|
|
|
225
250
|
send("t_#{enum_plural}_options_raw_i", send("t_#{enum_plural}") )
|
|
226
251
|
end
|
|
227
252
|
|
|
228
|
-
#
|
|
229
|
-
|
|
230
|
-
t = block || localizations.try(:with_indifferent_access)[send(enum_name)]
|
|
231
|
-
if t.try(:lambda?)
|
|
232
|
-
t.try(:arity) == 1 && t.call( self ) || t.try(:call)
|
|
233
|
-
elsif t.is_a?(Proc)
|
|
234
|
-
instance_eval(&t)
|
|
235
|
-
else
|
|
236
|
-
t
|
|
237
|
-
end.to_s
|
|
253
|
+
define_method "t_#{enum_name}=" do |new_val|
|
|
254
|
+
send("#{enum_name}=", new_val)
|
|
238
255
|
end
|
|
239
256
|
|
|
240
257
|
#protected?
|
|
@@ -258,7 +275,6 @@ module EnumExt
|
|
|
258
275
|
key_val
|
|
259
276
|
end
|
|
260
277
|
end
|
|
261
|
-
|
|
262
278
|
end
|
|
263
279
|
end
|
|
264
280
|
alias localize_enum humanize_enum
|
|
@@ -278,4 +294,13 @@ module EnumExt
|
|
|
278
294
|
end
|
|
279
295
|
end
|
|
280
296
|
|
|
297
|
+
# human_attribute_name is redefined for automation like this:
|
|
298
|
+
# p #{object.class.human_attribute_name( attr_name )}:
|
|
299
|
+
# p object.send(attr_name)
|
|
300
|
+
def human_attribute_name( name, options = {} )
|
|
301
|
+
# if name starts from t_ and there is a column with the last part then ...
|
|
302
|
+
name[0..1] == 't_' && column_names.include?(name[2..-1]) ? super( name[2..-1], options ) : super( name, options )
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
|
|
281
306
|
end
|
data/lib/enum_ext/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: enum_ext
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- alekseyl
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 5.2.4.3
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
26
|
+
version: 5.2.4.3
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: minitest
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -42,28 +42,28 @@ dependencies:
|
|
|
42
42
|
name: bundler
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
47
|
version: '1.11'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '1.11'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: rake
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- - "
|
|
59
|
+
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '10.0'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- - "
|
|
66
|
+
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '10.0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
@@ -94,6 +94,20 @@ dependencies:
|
|
|
94
94
|
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: byebug
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
97
111
|
description: Enum extension, ads enum sets, mass-assign, localization, and some sugar
|
|
98
112
|
helpers.
|
|
99
113
|
email:
|
|
@@ -103,6 +117,8 @@ extensions: []
|
|
|
103
117
|
extra_rdoc_files: []
|
|
104
118
|
files:
|
|
105
119
|
- ".gitignore"
|
|
120
|
+
- ".travis.yml"
|
|
121
|
+
- CHANGELOG.md
|
|
106
122
|
- Gemfile
|
|
107
123
|
- Gemfile.lock
|
|
108
124
|
- LICENSE.txt
|
|
@@ -117,7 +133,7 @@ homepage: https://github.com/alekseyl/enum_ext
|
|
|
117
133
|
licenses:
|
|
118
134
|
- MIT
|
|
119
135
|
metadata: {}
|
|
120
|
-
post_install_message:
|
|
136
|
+
post_install_message:
|
|
121
137
|
rdoc_options: []
|
|
122
138
|
require_paths:
|
|
123
139
|
- lib
|
|
@@ -132,9 +148,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
132
148
|
- !ruby/object:Gem::Version
|
|
133
149
|
version: '0'
|
|
134
150
|
requirements: []
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
signing_key:
|
|
151
|
+
rubygems_version: 3.1.2
|
|
152
|
+
signing_key:
|
|
138
153
|
specification_version: 4
|
|
139
154
|
summary: Enum extension, ads enum sets, mass-assign, localization, and some sugar
|
|
140
155
|
helpers.
|