eac_rails_utils 0.8.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -0
  3. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper.rb +8 -1
  4. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder.rb +12 -2
  5. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/association_select_field.rb +5 -2
  6. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/common_text_fields.rb +4 -3
  7. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/currency_field.rb +14 -12
  8. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/date_field.rb +3 -1
  9. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/fields_for.rb +3 -1
  10. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/file_field.rb +2 -1
  11. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/radio_select_field.rb +5 -2
  12. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/searchable_association_field.rb +7 -3
  13. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/select_field.rb +3 -1
  14. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/time_field.rb +2 -1
  15. data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/year_month_field.rb +2 -1
  16. data/app/helpers/eac_rails_utils/data_table_helper.rb +13 -0
  17. data/{lib/eac → app/helpers/eac_rails_utils}/data_table_helper/column.rb +6 -3
  18. data/{lib/eac → app/helpers/eac_rails_utils}/data_table_helper/data_table.rb +13 -11
  19. data/{lib/eac → app/helpers/eac_rails_utils}/data_table_helper/setup.rb +3 -2
  20. data/app/helpers/eac_rails_utils/formatter_helper.rb +2 -0
  21. data/app/helpers/eac_rails_utils/links_helper.rb +12 -2
  22. data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper.rb +10 -2
  23. data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper/bootstrap_gui_builder.rb +8 -5
  24. data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper/data_builder.rb +7 -2
  25. data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper/gui_builder.rb +6 -3
  26. data/app/helpers/eac_rails_utils/open_graph_protocol_helper.rb +2 -0
  27. data/{lib/eac → app/validators/eac_rails_utils}/cpf_validator.rb +8 -4
  28. data/{lib/eac → app/validators/eac_rails_utils}/no_presence_validator.rb +3 -3
  29. data/lib/assets/javascripts/jMenu.jquery.min.js +12 -12
  30. data/lib/eac_rails_utils.rb +3 -41
  31. data/lib/eac_rails_utils/engine.rb +3 -0
  32. data/lib/{eac → eac_rails_utils}/htmlbeautifier.rb +3 -1
  33. data/lib/eac_rails_utils/models.rb +9 -0
  34. data/lib/eac_rails_utils/models/attribute_required.rb +43 -0
  35. data/lib/eac_rails_utils/models/fetch_errors.rb +92 -0
  36. data/lib/eac_rails_utils/models/inequality_queries.rb +39 -0
  37. data/lib/eac_rails_utils/models/tableless.rb +97 -0
  38. data/lib/eac_rails_utils/models/test_utils.rb +65 -0
  39. data/lib/eac_rails_utils/patches.rb +9 -0
  40. data/lib/eac_rails_utils/patches/action_controller_base.rb +3 -0
  41. data/lib/eac_rails_utils/version.rb +2 -1
  42. data/test/dummy/Rakefile +3 -1
  43. data/test/dummy/app/models/job.rb +2 -0
  44. data/test/dummy/app/models/user.rb +6 -0
  45. data/test/dummy/config.ru +2 -0
  46. data/test/dummy/config/application.rb +3 -1
  47. data/test/dummy/config/boot.rb +3 -1
  48. data/test/dummy/config/environment.rb +3 -1
  49. data/test/dummy/config/environments/test.rb +2 -0
  50. data/test/dummy/config/routes.rb +2 -0
  51. data/test/dummy/db/migrate/20160415125333_create_users.rb +2 -0
  52. data/test/dummy/db/migrate/20160415143123_create_jobs.rb +2 -0
  53. data/test/dummy/db/migrate/20160415143229_add_job_to_users.rb +2 -0
  54. data/test/{lib/eac → helpers/eac_rails_utils}/common_form_helper_test.rb +4 -2
  55. data/test/{lib/eac/data_table_test_helper.rb → helpers/eac_rails_utils/data_table_test_helper_test.rb} +4 -3
  56. data/test/{app/helpers → helpers}/eac_rails_utils/formatter_helper_test.rb +1 -0
  57. data/test/lib/eac_rails_utils/{patches/model_attribute_required_test.rb → models/attribute_required_test.rb} +3 -0
  58. data/test/lib/eac_rails_utils/models/fetch_errors_test.rb +80 -0
  59. data/test/lib/eac_rails_utils/models/tableless_test.rb +25 -0
  60. data/test/test_helper.rb +3 -1
  61. data/test/{lib/eac → validators}/cpf_validator_test.rb +4 -2
  62. metadata +91 -98
  63. data/lib/eac/data_table_helper.rb +0 -12
  64. data/lib/eac/inequality_queries.rb +0 -36
  65. data/lib/eac/model.rb +0 -87
  66. data/lib/eac/parsers/files_test.rb +0 -63
  67. data/lib/eac/source_target_fixtures.rb +0 -66
  68. data/lib/eac/test_utils.rb +0 -56
  69. data/lib/eac_rails_utils/patches/model_attribute_required.rb +0 -31
  70. data/lib/eac_rails_utils/patches/ofx_parser.rb +0 -42
  71. data/lib/eac_rails_utils/tableless_model.rb +0 -90
  72. data/test/lib/eac/model_test.rb +0 -76
  73. data/test/lib/eac/parsers/files_test_test.rb +0 -27
  74. data/test/lib/eac/parsers/ok_test_files/a.source.yaml +0 -1
  75. data/test/lib/eac/parsers/ok_test_files/a.target.yaml +0 -1
  76. data/test/lib/eac/parsers/ok_test_files/b.source.yaml +0 -1
  77. data/test/lib/eac/parsers/ok_test_files/b.target.yaml +0 -1
  78. data/test/lib/eac/source_target_fixtures_test.rb +0 -41
  79. data/test/lib/eac/source_target_fixtures_test_files/a.source.html +0 -1
  80. data/test/lib/eac/source_target_fixtures_test_files/a.target.yaml +0 -1
  81. data/test/lib/eac/source_target_fixtures_test_files/b.source.html +0 -1
  82. data/test/lib/eac/source_target_fixtures_test_files/c.target.yaml +0 -1
  83. data/test/lib/eac_rails_utils/tableless_model_test.rb +0 -23
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ENV['RAILS_ENV'] = 'test'
2
- require File.expand_path('../../test/dummy/config/environment.rb', __FILE__)
4
+ require File.expand_path('../test/dummy/config/environment.rb', __dir__)
3
5
  require 'rails/test_help'
4
6
 
5
7
  module ActiveSupport
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
- module Eac
5
+ module EacRailsUtils
4
6
  class CpfValidatorTest < ActiveSupport::TestCase
5
7
  class M1
6
8
  include ActiveModel::Model
7
9
 
8
10
  attr_accessor :cpf
9
11
 
10
- validates :cpf, 'eac/cpf' => true, allow_nil: true
12
+ validates :cpf, 'eac_rails_utils/cpf' => true, allow_nil: true
11
13
  end
12
14
 
13
15
  def setup
metadata CHANGED
@@ -1,91 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_rails_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.11.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: 2020-02-11 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel-associations
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.2
19
+ version: '0.2'
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: 0.1.2
26
+ version: '0.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rails
28
+ name: bootstrap-sass
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '4.2'
34
31
  - - ">="
35
32
  - !ruby/object:Gem::Version
36
- version: 4.2.1
33
+ version: 3.3.6
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: '4.2'
44
38
  - - ">="
45
39
  - !ruby/object:Gem::Version
46
- version: 4.2.1
40
+ version: 3.3.6
47
41
  - !ruby/object:Gem::Dependency
48
- name: htmlbeautifier
42
+ name: eac_ruby_utils
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.33'
51
48
  - - ">="
52
49
  - !ruby/object:Gem::Version
53
- version: 1.1.1
50
+ version: 0.33.1
54
51
  type: :runtime
55
52
  prerelease: false
56
53
  version_requirements: !ruby/object:Gem::Requirement
57
54
  requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0.33'
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 1.1.1
60
+ version: 0.33.1
61
61
  - !ruby/object:Gem::Dependency
62
- name: bootstrap-sass
62
+ name: htmlbeautifier
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: 3.3.6
67
+ version: 1.1.1
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 3.3.6
74
+ version: 1.1.1
75
75
  - !ruby/object:Gem::Dependency
76
- name: ofx-parser
76
+ name: rails
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: 1.1.0
81
+ version: 4.2.11.1
82
82
  type: :runtime
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: 1.1.0
88
+ version: 4.2.11.1
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: virtus
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -114,6 +114,20 @@ dependencies:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: eac_ruby_gem_support
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '0.1'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '0.1'
117
131
  - !ruby/object:Gem::Dependency
118
132
  name: sqlite3
119
133
  requirement: !ruby/object:Gem::Requirement
@@ -135,9 +149,32 @@ extensions: []
135
149
  extra_rdoc_files: []
136
150
  files:
137
151
  - Rakefile
152
+ - app/helpers/eac_rails_utils/common_form_helper.rb
153
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder.rb
154
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/association_select_field.rb
155
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/common_text_fields.rb
156
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/currency_field.rb
157
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/date_field.rb
158
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/fields_for.rb
159
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/file_field.rb
160
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb
161
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/searchable_association_field.rb
162
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/select_field.rb
163
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/time_field.rb
164
+ - app/helpers/eac_rails_utils/common_form_helper/form_builder/year_month_field.rb
165
+ - app/helpers/eac_rails_utils/data_table_helper.rb
166
+ - app/helpers/eac_rails_utils/data_table_helper/column.rb
167
+ - app/helpers/eac_rails_utils/data_table_helper/data_table.rb
168
+ - app/helpers/eac_rails_utils/data_table_helper/setup.rb
138
169
  - app/helpers/eac_rails_utils/formatter_helper.rb
139
170
  - app/helpers/eac_rails_utils/links_helper.rb
171
+ - app/helpers/eac_rails_utils/menus_helper.rb
172
+ - app/helpers/eac_rails_utils/menus_helper/bootstrap_gui_builder.rb
173
+ - app/helpers/eac_rails_utils/menus_helper/data_builder.rb
174
+ - app/helpers/eac_rails_utils/menus_helper/gui_builder.rb
140
175
  - app/helpers/eac_rails_utils/open_graph_protocol_helper.rb
176
+ - app/validators/eac_rails_utils/cpf_validator.rb
177
+ - app/validators/eac_rails_utils/no_presence_validator.rb
141
178
  - lib/assets/javascripts/currency_field.js
142
179
  - lib/assets/javascripts/eac_rails_utils.js
143
180
  - lib/assets/javascripts/input_searchable.js
@@ -149,43 +186,18 @@ files:
149
186
  - lib/assets/stylesheets/eac_rails_utils.scss
150
187
  - lib/assets/stylesheets/jmenu.scss
151
188
  - lib/assets/stylesheets/jquery.dataTables.min.css
152
- - lib/eac/common_form_helper.rb
153
- - lib/eac/common_form_helper/form_builder.rb
154
- - lib/eac/common_form_helper/form_builder/association_select_field.rb
155
- - lib/eac/common_form_helper/form_builder/common_text_fields.rb
156
- - lib/eac/common_form_helper/form_builder/currency_field.rb
157
- - lib/eac/common_form_helper/form_builder/date_field.rb
158
- - lib/eac/common_form_helper/form_builder/fields_for.rb
159
- - lib/eac/common_form_helper/form_builder/file_field.rb
160
- - lib/eac/common_form_helper/form_builder/radio_select_field.rb
161
- - lib/eac/common_form_helper/form_builder/searchable_association_field.rb
162
- - lib/eac/common_form_helper/form_builder/select_field.rb
163
- - lib/eac/common_form_helper/form_builder/time_field.rb
164
- - lib/eac/common_form_helper/form_builder/year_month_field.rb
165
- - lib/eac/cpf_validator.rb
166
- - lib/eac/data_table_helper.rb
167
- - lib/eac/data_table_helper/column.rb
168
- - lib/eac/data_table_helper/data_table.rb
169
- - lib/eac/data_table_helper/setup.rb
170
- - lib/eac/htmlbeautifier.rb
171
- - lib/eac/inequality_queries.rb
172
- - lib/eac/menus_helper.rb
173
- - lib/eac/menus_helper/bootstrap_gui_builder.rb
174
- - lib/eac/menus_helper/data_builder.rb
175
- - lib/eac/menus_helper/gui_builder.rb
176
- - lib/eac/model.rb
177
- - lib/eac/no_presence_validator.rb
178
- - lib/eac/parsers/files_test.rb
179
- - lib/eac/source_target_fixtures.rb
180
- - lib/eac/test_utils.rb
181
189
  - lib/eac_rails_utils.rb
182
190
  - lib/eac_rails_utils/engine.rb
191
+ - lib/eac_rails_utils/htmlbeautifier.rb
192
+ - lib/eac_rails_utils/models.rb
193
+ - lib/eac_rails_utils/models/attribute_required.rb
194
+ - lib/eac_rails_utils/models/fetch_errors.rb
195
+ - lib/eac_rails_utils/models/inequality_queries.rb
196
+ - lib/eac_rails_utils/models/tableless.rb
197
+ - lib/eac_rails_utils/models/test_utils.rb
198
+ - lib/eac_rails_utils/patches.rb
183
199
  - lib/eac_rails_utils/patches/action_controller_base.rb
184
- - lib/eac_rails_utils/patches/model_attribute_required.rb
185
- - lib/eac_rails_utils/patches/ofx_parser.rb
186
- - lib/eac_rails_utils/tableless_model.rb
187
200
  - lib/eac_rails_utils/version.rb
188
- - test/app/helpers/eac_rails_utils/formatter_helper_test.rb
189
201
  - test/dummy/Rakefile
190
202
  - test/dummy/app/models/job.rb
191
203
  - test/dummy/app/models/user.rb
@@ -202,23 +214,14 @@ files:
202
214
  - test/dummy/db/migrate/20160415143123_create_jobs.rb
203
215
  - test/dummy/db/migrate/20160415143229_add_job_to_users.rb
204
216
  - test/dummy/db/schema.rb
205
- - test/lib/eac/common_form_helper_test.rb
206
- - test/lib/eac/cpf_validator_test.rb
207
- - test/lib/eac/data_table_test_helper.rb
208
- - test/lib/eac/model_test.rb
209
- - test/lib/eac/parsers/files_test_test.rb
210
- - test/lib/eac/parsers/ok_test_files/a.source.yaml
211
- - test/lib/eac/parsers/ok_test_files/a.target.yaml
212
- - test/lib/eac/parsers/ok_test_files/b.source.yaml
213
- - test/lib/eac/parsers/ok_test_files/b.target.yaml
214
- - test/lib/eac/source_target_fixtures_test.rb
215
- - test/lib/eac/source_target_fixtures_test_files/a.source.html
216
- - test/lib/eac/source_target_fixtures_test_files/a.target.yaml
217
- - test/lib/eac/source_target_fixtures_test_files/b.source.html
218
- - test/lib/eac/source_target_fixtures_test_files/c.target.yaml
219
- - test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
220
- - test/lib/eac_rails_utils/tableless_model_test.rb
217
+ - test/helpers/eac_rails_utils/common_form_helper_test.rb
218
+ - test/helpers/eac_rails_utils/data_table_test_helper_test.rb
219
+ - test/helpers/eac_rails_utils/formatter_helper_test.rb
220
+ - test/lib/eac_rails_utils/models/attribute_required_test.rb
221
+ - test/lib/eac_rails_utils/models/fetch_errors_test.rb
222
+ - test/lib/eac_rails_utils/models/tableless_test.rb
221
223
  - test/test_helper.rb
224
+ - test/validators/cpf_validator_test.rb
222
225
  homepage:
223
226
  licenses: []
224
227
  metadata: {}
@@ -243,37 +246,27 @@ signing_key:
243
246
  specification_version: 4
244
247
  summary: Código reutilizável para as aplicações Rails da E.A.C..
245
248
  test_files:
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
249
+ - test/dummy/Rakefile
250
+ - test/dummy/config.ru
251
+ - test/dummy/config/boot.rb
263
252
  - test/dummy/config/database.yml
264
253
  - test/dummy/config/secrets.yml
265
254
  - test/dummy/config/locales/pt-BR.yml
266
- - test/dummy/config/environment.rb
267
- - test/dummy/config/boot.rb
268
255
  - test/dummy/config/application.rb
269
256
  - test/dummy/config/environments/test.rb
270
- - test/dummy/Rakefile
271
- - test/dummy/config.ru
272
- - test/dummy/app/models/user.rb
273
- - test/dummy/app/models/job.rb
257
+ - test/dummy/config/environment.rb
258
+ - test/dummy/config/routes.rb
274
259
  - test/dummy/db/schema.rb
275
- - test/dummy/db/migrate/20160415125333_create_users.rb
276
260
  - test/dummy/db/migrate/20160415143123_create_jobs.rb
277
261
  - test/dummy/db/migrate/20160415143229_add_job_to_users.rb
278
- - test/app/helpers/eac_rails_utils/formatter_helper_test.rb
262
+ - test/dummy/db/migrate/20160415125333_create_users.rb
263
+ - test/dummy/app/models/job.rb
264
+ - test/dummy/app/models/user.rb
279
265
  - test/test_helper.rb
266
+ - test/validators/cpf_validator_test.rb
267
+ - test/helpers/eac_rails_utils/common_form_helper_test.rb
268
+ - test/helpers/eac_rails_utils/data_table_test_helper_test.rb
269
+ - test/helpers/eac_rails_utils/formatter_helper_test.rb
270
+ - test/lib/eac_rails_utils/models/attribute_required_test.rb
271
+ - test/lib/eac_rails_utils/models/tableless_test.rb
272
+ - test/lib/eac_rails_utils/models/fetch_errors_test.rb
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
- require_dependency 'eac/data_table_helper/column'
3
- require_dependency 'eac/data_table_helper/setup'
4
- require_dependency 'eac/data_table_helper/data_table'
5
-
6
- module Eac
7
- module DataTableHelper
8
- def data_table(dataset, &block)
9
- ::Eac::DataTableHelper::DataTable.new(self, dataset, &block).output
10
- end
11
- end
12
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
- module Eac
3
- # == Example:
4
- #
5
- # Note: model Product has a attribute "foo" Date, Time or Number:
6
- #
7
- # class Product
8
- # include ::Eac::InequalityQueries
9
- #
10
- # add_inequality_queries(:foo)
11
- # end
12
- #
13
- # This add the following scopes:
14
- #
15
- # Product.by_foo_gt(value) # Equivalent to Product.where("foo > ?", value)
16
- # Product.by_foo_gteq(value) # Equivalent to Product.where("foo >= ?", value)
17
- # Product.by_foo_lt(value) # Equivalent to Product.where("foo < ?", value)
18
- # Product.by_foo_lteq(value) # Equivalent to Product.where("foo <= ?", value)
19
- module InequalityQueries
20
- class << self
21
- def included(base)
22
- base.extend(ClassMethods)
23
- end
24
- end
25
-
26
- module ClassMethods
27
- def add_inequality_queries(attribute)
28
- %w(gt gteq lt lteq).each do |ineq|
29
- scope "by_#{attribute}_#{ineq}", lambda { |v|
30
- where(arel_table[attribute].send(ineq, v))
31
- }
32
- end
33
- end
34
- end
35
- end
36
- end
@@ -1,87 +0,0 @@
1
- module Eac
2
- module Model
3
- # Adiciona as mensagens de erro de record. As mensagens de uma coluna X em record
4
- # serão adicionadas na coluna X em self. Se options[:default_column] for especificado
5
- # as mensagens da coluna X de record em que X não existe em self serão adicionadas
6
- # na coluna options[:default_column].
7
- # Um array de colunas pode ser passado em options[:skip] de colunas em record que não
8
- # terão suas falhas adicionadas.
9
- def fetch_record_errors(record, options = {})
10
- record.errors.keys.each do |column|
11
- fetch_column_errors(record, column, column, options)
12
- end
13
- end
14
-
15
- # Similar a fetch_record_errors, mas torna possível especificar, através de mapping,
16
- # colunas-alvo em self com nomes diferentes das colunas-fonte em record.
17
- # mapping tem o formato { record_column => self_column }.
18
- def fetch_record_errors_by_mapping(record, mapping, options = {})
19
- mapping.each do |record_column, self_column|
20
- fetch_column_errors(record, record_column, self_column, options)
21
- end
22
- end
23
-
24
- def fetch_column_errors(record, record_column, self_column, options = {})
25
- return if options[:skip] && options[:skip].include?(record_column)
26
- record.errors[record_column].each do |message|
27
- fetch_error_column_message(self_column, message, options[:default_column],
28
- "#{record.class.human_attribute_name(record_column)}: ")
29
- end
30
- end
31
-
32
- # Verifica se uma coluna existe.
33
- def column?(column)
34
- respond_to?(column) && respond_to?("#{column}=")
35
- end
36
-
37
- def save_or_raise
38
- unless save
39
- fail "Falha ao tentar salvar #{self.class.name}: #{errors_to_string}"
40
- end
41
- self
42
- end
43
-
44
- private
45
-
46
- def fetch_error_column_message(column, message, default_column, default_column_message_prefix)
47
- build_self_columns_messages(column, message, default_column,
48
- default_column_message_prefix).each do |k, v|
49
- if column?(k)
50
- add_error_message(k, v)
51
- break
52
- end
53
- end
54
- end
55
-
56
- # Adiciona uma mensagem de erro a uma coluna somente se a coluna
57
- # ainda não a possui
58
- def add_error_message(column, message)
59
- return if errors[column].include?(message)
60
- errors.add(column, message)
61
- end
62
-
63
- # Produz uma lista de campos-mensagens, em ordem de preferência,
64
- # que podem receber uma mensagem de falha.
65
- def build_self_columns_messages(column, message, default_column,
66
- default_column_message_prefix)
67
- r = { column => message }
68
- m = /^(.+)_id$/.match(column)
69
- if m
70
- r[m[1]] = message
71
- else
72
- r["#{column}_id"] = message
73
- end
74
- r[default_column] = "#{default_column_message_prefix}#{message}" if default_column
75
- r
76
- end
77
-
78
- def errors_to_string
79
- b = ''
80
- errors.messages.each do |field, messages|
81
- b += ' / ' if b != ''
82
- b += field.to_s + ': ' + messages.to_s
83
- end
84
- b
85
- end
86
- end
87
- end