eac_rails_utils 0.7.1 → 0.8.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5576c6d46318719526c32fc853b068be7248a7ca1988fb0c85f7e2347218608c
4
- data.tar.gz: 879f0c15bf1340143ae1a98466bad409525a303615524e969b8c3fee294c449e
3
+ metadata.gz: d6110af17107237d774ea52a1ca25220fd711671526b1eeda16db466f62bdca6
4
+ data.tar.gz: 67908bcdc2622d86dc2b9f7960963e2efba51150320542f028d7d433c1190b8d
5
5
  SHA512:
6
- metadata.gz: 90ce76166280dca11d9dd0edde3f06c6e9da6785db2b878c5085958d7531a46dcb6b7afcd74d2b6beec0adf26f627b7978ab689952aa158df4b72bc07910f4ab
7
- data.tar.gz: af578210bee3736e0b1f0048081b7405035a91d275c2ed6751718502ea34b29aaf067f6d0a51f5d1bdc1dec80acd382c685abfcaa987a3a0501b1120b4db55c5
6
+ metadata.gz: 0a183c0e6065f379848fac12323028fc466cf910de11585ca09855a2c915f54aaffc0371424fef0e392a598291986148ba3af6f2d737f46de5d50314f008491e
7
+ data.tar.gz: 5f9fb0839dcbf3db537cfdfc736accde82399f74452c283044a7f7cf97e844e90fd05191c6c7b1d3fb5b94af71c6a8d654ad9ac716980316eb95d122800a0748
@@ -26,10 +26,9 @@ module EacRailsUtils
26
26
  require 'eac/common_form_helper/form_builder/year_month_field'
27
27
  require 'eac/common_form_helper/form_builder'
28
28
  require 'eac/common_form_helper'
29
- require_dependency 'eac/data_table_helper'
29
+ require 'eac/data_table_helper'
30
30
  require 'eac/htmlbeautifier'
31
31
  require 'eac/inequality_queries'
32
- require 'eac/listable'
33
32
  require 'eac/menus_helper'
34
33
  require 'eac/menus_helper/bootstrap_gui_builder'
35
34
  require 'eac/menus_helper/data_builder'
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module EacRailsUtils
3
- VERSION = '0.7.1'
3
+ VERSION = '0.8.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_rails_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - E.A.C.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-21 00:00:00.000000000 Z
11
+ date: 2020-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel-associations
@@ -169,7 +169,6 @@ files:
169
169
  - lib/eac/data_table_helper/setup.rb
170
170
  - lib/eac/htmlbeautifier.rb
171
171
  - lib/eac/inequality_queries.rb
172
- - lib/eac/listable.rb
173
172
  - lib/eac/menus_helper.rb
174
173
  - lib/eac/menus_helper/bootstrap_gui_builder.rb
175
174
  - lib/eac/menus_helper/data_builder.rb
@@ -206,7 +205,6 @@ files:
206
205
  - test/lib/eac/common_form_helper_test.rb
207
206
  - test/lib/eac/cpf_validator_test.rb
208
207
  - test/lib/eac/data_table_test_helper.rb
209
- - test/lib/eac/listable_test.rb
210
208
  - test/lib/eac/model_test.rb
211
209
  - test/lib/eac/parsers/files_test_test.rb
212
210
  - test/lib/eac/parsers/ok_test_files/a.source.yaml
@@ -245,38 +243,37 @@ signing_key:
245
243
  specification_version: 4
246
244
  summary: Código reutilizável para as aplicações Rails da E.A.C..
247
245
  test_files:
248
- - test/dummy/Rakefile
249
- - test/dummy/config.ru
250
- - test/dummy/config/boot.rb
246
+ - test/lib/eac_rails_utils/tableless_model_test.rb
247
+ - test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
248
+ - test/lib/eac/source_target_fixtures_test.rb
249
+ - test/lib/eac/data_table_test_helper.rb
250
+ - test/lib/eac/cpf_validator_test.rb
251
+ - test/lib/eac/model_test.rb
252
+ - test/lib/eac/common_form_helper_test.rb
253
+ - test/lib/eac/source_target_fixtures_test_files/a.target.yaml
254
+ - test/lib/eac/source_target_fixtures_test_files/b.source.html
255
+ - test/lib/eac/source_target_fixtures_test_files/c.target.yaml
256
+ - test/lib/eac/source_target_fixtures_test_files/a.source.html
257
+ - test/lib/eac/parsers/files_test_test.rb
258
+ - test/lib/eac/parsers/ok_test_files/a.target.yaml
259
+ - test/lib/eac/parsers/ok_test_files/b.source.yaml
260
+ - test/lib/eac/parsers/ok_test_files/b.target.yaml
261
+ - test/lib/eac/parsers/ok_test_files/a.source.yaml
262
+ - test/dummy/config/routes.rb
251
263
  - test/dummy/config/database.yml
252
264
  - test/dummy/config/secrets.yml
253
265
  - test/dummy/config/locales/pt-BR.yml
266
+ - test/dummy/config/environment.rb
267
+ - test/dummy/config/boot.rb
254
268
  - test/dummy/config/application.rb
255
269
  - test/dummy/config/environments/test.rb
256
- - test/dummy/config/environment.rb
257
- - test/dummy/config/routes.rb
270
+ - test/dummy/Rakefile
271
+ - test/dummy/config.ru
272
+ - test/dummy/app/models/user.rb
273
+ - test/dummy/app/models/job.rb
258
274
  - test/dummy/db/schema.rb
275
+ - test/dummy/db/migrate/20160415125333_create_users.rb
259
276
  - test/dummy/db/migrate/20160415143123_create_jobs.rb
260
277
  - test/dummy/db/migrate/20160415143229_add_job_to_users.rb
261
- - test/dummy/db/migrate/20160415125333_create_users.rb
262
- - test/dummy/app/models/job.rb
263
- - test/dummy/app/models/user.rb
264
- - test/test_helper.rb
265
278
  - test/app/helpers/eac_rails_utils/formatter_helper_test.rb
266
- - test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
267
- - test/lib/eac_rails_utils/tableless_model_test.rb
268
- - test/lib/eac/common_form_helper_test.rb
269
- - test/lib/eac/source_target_fixtures_test.rb
270
- - test/lib/eac/parsers/files_test_test.rb
271
- - test/lib/eac/parsers/ok_test_files/a.source.yaml
272
- - test/lib/eac/parsers/ok_test_files/a.target.yaml
273
- - test/lib/eac/parsers/ok_test_files/b.source.yaml
274
- - test/lib/eac/parsers/ok_test_files/b.target.yaml
275
- - test/lib/eac/cpf_validator_test.rb
276
- - test/lib/eac/data_table_test_helper.rb
277
- - test/lib/eac/source_target_fixtures_test_files/c.target.yaml
278
- - test/lib/eac/source_target_fixtures_test_files/b.source.html
279
- - test/lib/eac/source_target_fixtures_test_files/a.target.yaml
280
- - test/lib/eac/source_target_fixtures_test_files/a.source.html
281
- - test/lib/eac/listable_test.rb
282
- - test/lib/eac/model_test.rb
279
+ - test/test_helper.rb
data/lib/eac/listable.rb DELETED
@@ -1,223 +0,0 @@
1
- # frozen_string_literal: true
2
- module Eac
3
- module Listable
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- extend(::Eac::Listable::ClassMethods)
8
- include(::Eac::Listable::InstanceMethods)
9
- end
10
-
11
- module ClassMethods
12
- def lists
13
- @lists ||= ::Eac::Listable::Lists.new(self)
14
- end
15
- end
16
-
17
- module InstanceMethods
18
- LISTABLE_INSTANCE_VALUE_METHODS = %w(label description).freeze
19
-
20
- def method_missing(name, *args, &block)
21
- list, method = parse_method(name)
22
- list && method ? list.instance_value(self).send(method) : super
23
- end
24
-
25
- def respond_to?(name, include_all = false)
26
- list, method = parse_method(name)
27
- list && method ? true : super
28
- end
29
-
30
- private
31
-
32
- def parse_method(method)
33
- self.class.lists.acts_as_listable_items.each do |item, list|
34
- LISTABLE_INSTANCE_VALUE_METHODS.each do |m|
35
- return [list, m] if method.to_s == "#{item}_#{m}"
36
- end
37
- end
38
- [nil, nil]
39
- end
40
- end
41
-
42
- class Lists
43
- attr_reader :source
44
-
45
- def initialize(source)
46
- @source = source
47
- end
48
-
49
- def add_integer(item, *labels)
50
- check_acts_as_listable_new_item(item)
51
- acts_as_listable_items[item] = ::Eac::Listable::IntegerList.new(
52
- self, item, labels
53
- )
54
- end
55
-
56
- def add_string(item, *labels)
57
- check_acts_as_listable_new_item(item)
58
- acts_as_listable_items[item] = ::Eac::Listable::StringList.new(
59
- self, item, labels
60
- )
61
- end
62
-
63
- def method_missing(name, *args, &block)
64
- list = find_list_by_method(name)
65
- list ? list : super
66
- end
67
-
68
- def respond_to?(name, include_all = false)
69
- find_list_by_method(name) || super
70
- end
71
-
72
- def acts_as_listable_items
73
- @acts_as_listable_items ||= ActiveSupport::HashWithIndifferentAccess.new
74
- end
75
-
76
- private
77
-
78
- def check_acts_as_listable_new_item(item)
79
- return unless acts_as_listable_items.key?(item)
80
- raise "Item já adicionado anteriormente: #{item} em #{self} " \
81
- "(#{acts_as_listable_items.keys})"
82
- end
83
-
84
- def find_list_by_method(method)
85
- acts_as_listable_items.each do |item, list|
86
- return list if method.to_sym == item.to_sym
87
- end
88
- nil
89
- end
90
- end
91
-
92
- class List
93
- attr_reader :item
94
-
95
- def initialize(lists, item, labels)
96
- @lists = lists
97
- @item = item
98
- @values = build_values(labels)
99
- apply_constants
100
- end
101
-
102
- def values
103
- @values.values.map(&:value)
104
- end
105
-
106
- def options
107
- @values.values.map { |v| [v.label, v.value] }
108
- end
109
-
110
- def method_missing(name, *args, &block)
111
- list = find_list_by_method(name)
112
- list ? list : super
113
- end
114
-
115
- def respond_to?(name, include_all = false)
116
- find_list_by_method(name) || super
117
- end
118
-
119
- def i18n_key
120
- "eac.listable.#{class_i18n_key}.#{item}"
121
- end
122
-
123
- def instance_value(instance)
124
- v = instance.send(item)
125
- return @values[v] if @values.key?(v)
126
- raise "List value unkown: #{v} (Source: #{@lists.source}, Item: #{item})"
127
- end
128
-
129
- private
130
-
131
- def class_i18n_key
132
- @lists.source.name.underscore.to_sym
133
- end
134
-
135
- def find_list_by_method(method)
136
- @values.values.each do |v|
137
- return v if method.to_s == "value_#{v.key}"
138
- end
139
- nil
140
- end
141
-
142
- def constants
143
- labels.each_with_index.map { |v, i| ["#{item.upcase}_#{v.upcase}", values[i]] }
144
- end
145
-
146
- def apply_constants
147
- @values.values.each do |v|
148
- @lists.source.const_set(v.constant_name, v.value)
149
- end
150
- end
151
-
152
- def build_values(labels)
153
- vs = {}
154
- parse_labels(labels).each do |value, key|
155
- v = Value.new(self, value, key)
156
- vs[v.value] = v
157
- end
158
- vs
159
- end
160
- end
161
-
162
- class Value
163
- attr_reader :value, :key
164
-
165
- def initialize(list, value, key)
166
- @list = list
167
- @value = value
168
- @key = key
169
- end
170
-
171
- def to_s
172
- "I: #{@list.item}, V: #{@value}, K: #{@key}"
173
- end
174
-
175
- def constant_name
176
- "#{@list.item}_#{@key}".gsub(/[^a-z0-9_]/, '_').gsub(/_+/, '_')
177
- .gsub(/(?:\A_|_\z)/, '').upcase
178
- end
179
-
180
- def label
181
- translate('label')
182
- end
183
-
184
- def description
185
- translate('description')
186
- end
187
-
188
- private
189
-
190
- def translate(translate_key)
191
- ::I18n.t("#{@list.i18n_key}.#{@key}.#{translate_key}")
192
- end
193
- end
194
-
195
- class IntegerList < ::Eac::Listable::List
196
- protected
197
-
198
- def parse_labels(labels)
199
- if labels.first.is_a?(Hash)
200
- Hash[labels.first.map { |k, v| [k.to_i, v.to_s] }]
201
- else
202
- Hash[labels.each_with_index.map { |v, i| [i + 1, v.to_s] }]
203
- end
204
- end
205
-
206
- def build_value(index, _key)
207
- index + 1
208
- end
209
- end
210
-
211
- class StringList < ::Eac::Listable::List
212
- protected
213
-
214
- def parse_labels(labels)
215
- if labels.first.is_a?(Hash)
216
- Hash[labels.first.map { |k, v| [k.to_s, v.to_s] }]
217
- else
218
- Hash[labels.map { |v| [v.to_s, v.to_s] }]
219
- end
220
- end
221
- end
222
- end
223
- end
@@ -1,138 +0,0 @@
1
- # encoding: UTF-8
2
- # frozen_string_literal: true
3
- require 'test_helper'
4
-
5
- module Eac
6
- class ListableTest < ActiveSupport::TestCase
7
- class Stub
8
- include ::Eac::Listable
9
-
10
- attr_accessor :inteiro, :code, :cadeia, :type
11
-
12
- lists.add_integer :inteiro, :a, :b, :c
13
- lists.add_integer :code, 7 => :a, 13 => :b
14
- lists.add_string :cadeia, :a, :b, :c
15
- lists.add_string :type, 'Namespace::ClazzA' => :a, 'Namespace::ClazzB' => :b
16
- end
17
-
18
- setup do
19
- I18n.locale = 'pt-BR'
20
- end
21
-
22
- test 'attribute values' do
23
- assert_equal [1, 2, 3], Stub.lists.inteiro.values
24
- assert_equal [7, 13], Stub.lists.code.values
25
- assert_equal %w(a b c), Stub.lists.cadeia.values
26
- assert_equal %w(Namespace::ClazzA Namespace::ClazzB), Stub.lists.type.values
27
- end
28
-
29
- test 'value instance options' do
30
- assert_equal [['Inteiro A', 1], ['Inteiro BB', 2], ['Inteiro CCC', 3]],
31
- Stub.lists.inteiro.options
32
- assert_equal [['Código A', 7], ['Código B', 13]], Stub.lists.code.options
33
- assert_equal [['Cadeia AAA', 'a'], ['Cadeia BB', 'b'], ['Cadeia C', 'c']],
34
- Stub.lists.cadeia.options
35
- assert_equal [['Tipo A', 'Namespace::ClazzA'], ['Tipo B', 'Namespace::ClazzB']], Stub.lists.type.options
36
- end
37
-
38
- test 'constants' do
39
- assert_equal 1, Stub::INTEIRO_A
40
- assert_equal 2, Stub::INTEIRO_B
41
- assert_equal 3, Stub::INTEIRO_C
42
- assert_equal 7, Stub::CODE_A
43
- assert_equal 13, Stub::CODE_B
44
- assert_equal 'a', Stub::CADEIA_A
45
- assert_equal 'b', Stub::CADEIA_B
46
- assert_equal 'c', Stub::CADEIA_C
47
- assert_equal 'Namespace::ClazzA', Stub::TYPE_A
48
- assert_equal 'Namespace::ClazzB', Stub::TYPE_B
49
- end
50
-
51
- test 'values instances' do
52
- assert Stub.lists.is_a?(::Eac::Listable::Lists)
53
- assert Stub.lists.inteiro.value_a.is_a?(::Eac::Listable::Value)
54
- assert Stub.lists.inteiro.value_b.is_a?(::Eac::Listable::Value)
55
- assert Stub.lists.inteiro.value_c.is_a?(::Eac::Listable::Value)
56
- assert Stub.lists.code.value_a.is_a?(::Eac::Listable::Value)
57
- assert Stub.lists.code.value_b.is_a?(::Eac::Listable::Value)
58
- assert Stub.lists.cadeia.value_a.is_a?(::Eac::Listable::Value)
59
- assert Stub.lists.cadeia.value_b.is_a?(::Eac::Listable::Value)
60
- assert Stub.lists.cadeia.value_c.is_a?(::Eac::Listable::Value)
61
- assert Stub.lists.type.value_a.is_a?(::Eac::Listable::Value)
62
- assert Stub.lists.type.value_b.is_a?(::Eac::Listable::Value)
63
- end
64
-
65
- test 'value instance label' do
66
- assert_equal 'Inteiro A', Stub.lists.inteiro.value_a.label
67
- assert_equal 'Inteiro BB', Stub.lists.inteiro.value_b.label
68
- assert_equal 'Inteiro CCC', Stub.lists.inteiro.value_c.label
69
- assert_equal 'Código A', Stub.lists.code.value_a.label
70
- assert_equal 'Código B', Stub.lists.code.value_b.label
71
- assert_equal 'Cadeia AAA', Stub.lists.cadeia.value_a.label
72
- assert_equal 'Cadeia BB', Stub.lists.cadeia.value_b.label
73
- assert_equal 'Cadeia C', Stub.lists.cadeia.value_c.label
74
- assert_equal 'Tipo A', Stub.lists.type.value_a.label
75
- assert_equal 'Tipo B', Stub.lists.type.value_b.label
76
- end
77
-
78
- test 'value instance description' do
79
- assert_equal 'Inteiro A Descr.', Stub.lists.inteiro.value_a.description
80
- assert_equal 'Inteiro BB Descr.', Stub.lists.inteiro.value_b.description
81
- assert_equal 'Inteiro CCC Descr.', Stub.lists.inteiro.value_c.description
82
- assert_equal 'Código A Descr.', Stub.lists.code.value_a.description
83
- assert_equal 'Código B Descr.', Stub.lists.code.value_b.description
84
- assert_equal 'Cadeia AAA Descr.', Stub.lists.cadeia.value_a.description
85
- assert_equal 'Cadeia BB Descr.', Stub.lists.cadeia.value_b.description
86
- assert_equal 'Cadeia C Descr.', Stub.lists.cadeia.value_c.description
87
- assert_equal 'Tipo A Descr.', Stub.lists.type.value_a.description
88
- assert_equal 'Tipo B Descr.', Stub.lists.type.value_b.description
89
- end
90
-
91
- test 'value instance constant name' do
92
- assert_equal 'INTEIRO_A', Stub.lists.inteiro.value_a.constant_name
93
- assert_equal 'INTEIRO_B', Stub.lists.inteiro.value_b.constant_name
94
- assert_equal 'INTEIRO_C', Stub.lists.inteiro.value_c.constant_name
95
- assert_equal 'CODE_B', Stub.lists.code.value_b.constant_name
96
- assert_equal 'CODE_B', Stub.lists.code.value_b.constant_name
97
- assert_equal 'CADEIA_A', Stub.lists.cadeia.value_a.constant_name
98
- assert_equal 'CADEIA_B', Stub.lists.cadeia.value_b.constant_name
99
- assert_equal 'CADEIA_C', Stub.lists.cadeia.value_c.constant_name
100
- assert_equal 'TYPE_A', Stub.lists.type.value_a.constant_name
101
- assert_equal 'TYPE_B', Stub.lists.type.value_b.constant_name
102
- end
103
-
104
- test 'instance label and descriptions' do
105
- i = Stub.new
106
- i.inteiro = Stub::INTEIRO_A
107
- assert_equal 'Inteiro A', i.inteiro_label
108
- assert_equal 'Inteiro A Descr.', i.inteiro_description
109
- i.inteiro = Stub::INTEIRO_B
110
- assert_equal 'Inteiro BB', i.inteiro_label
111
- assert_equal 'Inteiro BB Descr.', i.inteiro_description
112
- i.inteiro = Stub::INTEIRO_C
113
- assert_equal 'Inteiro CCC', i.inteiro_label
114
- assert_equal 'Inteiro CCC Descr.', i.inteiro_description
115
- i.code = Stub::CODE_A
116
- assert_equal 'Código A', i.code_label
117
- assert_equal 'Código A Descr.', i.code_description
118
- i.code = Stub::CODE_B
119
- assert_equal 'Código B', i.code_label
120
- assert_equal 'Código B Descr.', i.code_description
121
- i.cadeia = Stub::CADEIA_A
122
- assert_equal 'Cadeia AAA', i.cadeia_label
123
- assert_equal 'Cadeia AAA Descr.', i.cadeia_description
124
- i.cadeia = Stub::CADEIA_B
125
- assert_equal 'Cadeia BB', i.cadeia_label
126
- assert_equal 'Cadeia BB Descr.', i.cadeia_description
127
- i.cadeia = Stub::CADEIA_C
128
- assert_equal 'Cadeia C', i.cadeia_label
129
- assert_equal 'Cadeia C Descr.', i.cadeia_description
130
- i.type = Stub::TYPE_A
131
- assert_equal 'Tipo A', i.type_label
132
- assert_equal 'Tipo A Descr.', i.type_description
133
- i.type = Stub::TYPE_B
134
- assert_equal 'Tipo B', i.type_label
135
- assert_equal 'Tipo B Descr.', i.type_description
136
- end
137
- end
138
- end