eac_rails_utils 0.11.2 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/eac_rails_utils/common_form_helper.rb +6 -2
- data/app/helpers/eac_rails_utils/common_form_helper/form_builder.rb +3 -3
- data/app/helpers/eac_rails_utils/links_helper.rb +5 -5
- data/config/locales/en.yml +8 -0
- data/config/locales/pt-BR.yml +8 -0
- data/lib/eac_rails_utils/models/tableless.rb +10 -0
- data/lib/eac_rails_utils/models/validations.rb +71 -0
- data/lib/eac_rails_utils/patches/active_model_associations.rb +2 -0
- data/lib/eac_rails_utils/version.rb +1 -1
- data/test/dummy/app/assets/config/manifest.js +3 -0
- data/test/dummy/app/models/user.rb +0 -4
- data/test/dummy/bin/rails +6 -0
- data/test/dummy/config/application.rb +1 -1
- data/test/dummy/db/migrate/20160415125333_create_users.rb +3 -1
- data/test/dummy/db/migrate/20160415143123_create_jobs.rb +3 -1
- data/test/dummy/db/migrate/20160415143229_add_job_to_users.rb +3 -1
- metadata +26 -19
- data/lib/eac_rails_utils/models/attribute_required.rb +0 -43
- data/test/helpers/eac_rails_utils/common_form_helper_test.rb +0 -33
- data/test/lib/eac_rails_utils/models/attribute_required_test.rb +0 -42
- data/test/lib/eac_rails_utils/models/tableless_test.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00fd5aed91f9c11d3b6ab34cd532aff0c5ed10da72ba420488a060f93bbd8540
|
4
|
+
data.tar.gz: f66267fb4600635f05bcb15475fe5186c31663e9db4a00494add6e59dc603578
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b6aa1e4febf6826c760daf62ad9c280b3b708beb00800644cffdd88021acdd69ef41262f5ff395616eefa63c240e214a0ef3eb1f4028a1fab5f5f5cfa382acd
|
7
|
+
data.tar.gz: 5f2a4f27e090663895222931a57bdb63eae96a4b679a95a544a47699e7c0a5e733c47968cf13fa3f628c3c90381d3796a8d54989b3f7f38a674cd94454f7936a
|
@@ -1,10 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'action_view/helpers/form_helper'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
4
5
|
|
5
6
|
module EacRailsUtils
|
6
7
|
module CommonFormHelper
|
7
|
-
|
8
|
+
common_concern do
|
9
|
+
include ::ActionView::Helpers::FormHelper
|
10
|
+
end
|
11
|
+
require_sub __FILE__
|
8
12
|
|
9
13
|
def common_form(model_instance, options = {}, &block)
|
10
14
|
submit_label = options.delete(:submit_label)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/require_sub'
|
4
|
-
require 'eac_rails_utils/models/
|
4
|
+
require 'eac_rails_utils/models/validations'
|
5
5
|
|
6
6
|
module EacRailsUtils
|
7
7
|
module CommonFormHelper
|
@@ -93,8 +93,8 @@ module EacRailsUtils
|
|
93
93
|
|
94
94
|
def field_label(field_name, label, required)
|
95
95
|
if required.nil?
|
96
|
-
required = ::EacRailsUtils::Models::
|
97
|
-
.
|
96
|
+
required = ::EacRailsUtils::Models::Validations
|
97
|
+
.column_required?(model_instance, field_name)
|
98
98
|
end
|
99
99
|
@form.label(field_name, label, class: required ? 'required' : 'optional')
|
100
100
|
end
|
@@ -4,24 +4,24 @@ module EacRailsUtils
|
|
4
4
|
module LinksHelper
|
5
5
|
def short_delete_link(object)
|
6
6
|
short_object_link object, '', class: 'delete_link', method: :delete, target: '_blank',
|
7
|
-
title: ::I18n.t('
|
7
|
+
title: ::I18n.t('eac_rails_utils.links.delete_object',
|
8
8
|
label: object.to_s),
|
9
9
|
data: {
|
10
|
-
confirm: ::I18n.t('
|
10
|
+
confirm: ::I18n.t('eac_rails_utils.links.delete_confirm',
|
11
11
|
label: object.to_s)
|
12
12
|
}
|
13
13
|
end
|
14
14
|
|
15
15
|
def short_edit_link(object)
|
16
16
|
short_object_link object, 'edit', class: 'edit_link', target: '_blank',
|
17
|
-
title: ::I18n.t('
|
17
|
+
title: ::I18n.t('eac_rails_utils.links.edit_object',
|
18
18
|
label: object.to_s)
|
19
19
|
end
|
20
20
|
|
21
21
|
def short_goto_link(url)
|
22
22
|
value_or_sign(url, '') do |value|
|
23
23
|
link_to '', value, class: 'goto_link', target: '_blank',
|
24
|
-
title: ::I18n.t('
|
24
|
+
title: ::I18n.t('eac_rails_utils.links.goto_url', url: value.to_s),
|
25
25
|
rel: 'noopener'
|
26
26
|
end
|
27
27
|
end
|
@@ -54,7 +54,7 @@ module EacRailsUtils
|
|
54
54
|
short_object_link object,
|
55
55
|
detail ? 'detail' : nil,
|
56
56
|
class: 'show_link', target: '_blank',
|
57
|
-
title: ::I18n.t('
|
57
|
+
title: ::I18n.t('eac_rails_utils.links.show_object', label: object.to_s)
|
58
58
|
end
|
59
59
|
|
60
60
|
def short_object_link(object, action = nil, options = {})
|
@@ -10,6 +10,16 @@ module EacRailsUtils
|
|
10
10
|
include Virtus.model
|
11
11
|
include ActiveModel::Associations
|
12
12
|
|
13
|
+
class << self
|
14
|
+
def columns
|
15
|
+
attribute_set.each.to_a
|
16
|
+
end
|
17
|
+
|
18
|
+
def columns_names
|
19
|
+
columns.map(&:name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
13
23
|
def initialize(values = {})
|
14
24
|
super(build_attributes(values))
|
15
25
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacRailsUtils
|
6
|
+
module Models
|
7
|
+
module Validations
|
8
|
+
common_concern
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def column_errors(model_or_record, column, value)
|
12
|
+
model = model_class_or_record_to_model(model_or_record)
|
13
|
+
record = model.new
|
14
|
+
model.validators_on(column).each do |validator|
|
15
|
+
next if validator.options[:allow_blank] && value.blank?
|
16
|
+
next if validator.options[:allow_nil] && value.nil?
|
17
|
+
|
18
|
+
validator.validate_each(record, column, value)
|
19
|
+
end
|
20
|
+
record.errors
|
21
|
+
end
|
22
|
+
|
23
|
+
def column_required?(model_or_record, column)
|
24
|
+
!column_valid?(model_or_record, column, nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
def column_valid?(model_or_record, column, value)
|
28
|
+
column_errors(model_or_record, column, value).empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def model_class_or_record_to_model(model_class_or_record)
|
34
|
+
model_class_or_record.is_a?(::Class) ? model_class_or_record : model_class_or_record.class
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module ClassMethods
|
39
|
+
def column_errors(column, value)
|
40
|
+
::EacRailsUtils::Models::Validations.column_errors(self, column, value)
|
41
|
+
end
|
42
|
+
|
43
|
+
def column_required?(column)
|
44
|
+
::EacRailsUtils::Models::Validations.column_required?(self, column)
|
45
|
+
end
|
46
|
+
|
47
|
+
def column_valid?(attribute, value)
|
48
|
+
column_errors(attribute, value).empty?
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def model_class_or_record_to_model(model_class_or_record)
|
54
|
+
model_class_or_record.is_a?(::Class) ? model_class_or_record : model_class_or_record.class
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def attribute_errors(attribute)
|
59
|
+
self.class.column_errors(attribute, send(attribute))
|
60
|
+
end
|
61
|
+
|
62
|
+
def attribute_required?(attribute)
|
63
|
+
self.class.column_required?(attribute)
|
64
|
+
end
|
65
|
+
|
66
|
+
def attribute_valid?(attribute)
|
67
|
+
attribute_errors(attribute).empty?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -27,6 +27,8 @@ module ActiveModel
|
|
27
27
|
module Associations
|
28
28
|
module Hooks
|
29
29
|
def self.init
|
30
|
+
return unless ::Rails.version < '5'
|
31
|
+
|
30
32
|
ActiveSupport.on_load(:active_record) do
|
31
33
|
ActiveRecord::Associations::AssociationScope.prepend(
|
32
34
|
::EacRailsUtils::Patches::ActiveModelAssociations::ScopeExtensionPatch
|
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.
|
4
|
+
version: 0.12.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-
|
11
|
+
date: 2020-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel-associations
|
@@ -44,20 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0.
|
48
|
-
- - ">="
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: 0.33.1
|
47
|
+
version: '0.49'
|
51
48
|
type: :runtime
|
52
49
|
prerelease: false
|
53
50
|
version_requirements: !ruby/object:Gem::Requirement
|
54
51
|
requirements:
|
55
52
|
- - "~>"
|
56
53
|
- !ruby/object:Gem::Version
|
57
|
-
version: '0.
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: 0.33.1
|
54
|
+
version: '0.49'
|
61
55
|
- !ruby/object:Gem::Dependency
|
62
56
|
name: htmlbeautifier
|
63
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,6 +122,20 @@ dependencies:
|
|
128
122
|
- - "~>"
|
129
123
|
- !ruby/object:Gem::Version
|
130
124
|
version: '0.1'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec-rails
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
131
139
|
- !ruby/object:Gem::Dependency
|
132
140
|
name: sqlite3
|
133
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -175,6 +183,8 @@ files:
|
|
175
183
|
- app/helpers/eac_rails_utils/open_graph_protocol_helper.rb
|
176
184
|
- app/validators/eac_rails_utils/cpf_validator.rb
|
177
185
|
- app/validators/eac_rails_utils/no_presence_validator.rb
|
186
|
+
- config/locales/en.yml
|
187
|
+
- config/locales/pt-BR.yml
|
178
188
|
- lib/assets/javascripts/currency_field.js
|
179
189
|
- lib/assets/javascripts/eac_rails_utils.js
|
180
190
|
- lib/assets/javascripts/input_searchable.js
|
@@ -190,18 +200,20 @@ files:
|
|
190
200
|
- lib/eac_rails_utils/engine.rb
|
191
201
|
- lib/eac_rails_utils/htmlbeautifier.rb
|
192
202
|
- lib/eac_rails_utils/models.rb
|
193
|
-
- lib/eac_rails_utils/models/attribute_required.rb
|
194
203
|
- lib/eac_rails_utils/models/fetch_errors.rb
|
195
204
|
- lib/eac_rails_utils/models/inequality_queries.rb
|
196
205
|
- lib/eac_rails_utils/models/tableless.rb
|
197
206
|
- lib/eac_rails_utils/models/test_utils.rb
|
207
|
+
- lib/eac_rails_utils/models/validations.rb
|
198
208
|
- lib/eac_rails_utils/patches.rb
|
199
209
|
- lib/eac_rails_utils/patches/action_controller_base.rb
|
200
210
|
- lib/eac_rails_utils/patches/active_model_associations.rb
|
201
211
|
- lib/eac_rails_utils/version.rb
|
202
212
|
- test/dummy/Rakefile
|
213
|
+
- test/dummy/app/assets/config/manifest.js
|
203
214
|
- test/dummy/app/models/job.rb
|
204
215
|
- test/dummy/app/models/user.rb
|
216
|
+
- test/dummy/bin/rails
|
205
217
|
- test/dummy/config.ru
|
206
218
|
- test/dummy/config/application.rb
|
207
219
|
- test/dummy/config/boot.rb
|
@@ -215,12 +227,9 @@ files:
|
|
215
227
|
- test/dummy/db/migrate/20160415143123_create_jobs.rb
|
216
228
|
- test/dummy/db/migrate/20160415143229_add_job_to_users.rb
|
217
229
|
- test/dummy/db/schema.rb
|
218
|
-
- test/helpers/eac_rails_utils/common_form_helper_test.rb
|
219
230
|
- test/helpers/eac_rails_utils/data_table_test_helper_test.rb
|
220
231
|
- test/helpers/eac_rails_utils/formatter_helper_test.rb
|
221
|
-
- test/lib/eac_rails_utils/models/attribute_required_test.rb
|
222
232
|
- test/lib/eac_rails_utils/models/fetch_errors_test.rb
|
223
|
-
- test/lib/eac_rails_utils/models/tableless_test.rb
|
224
233
|
- test/test_helper.rb
|
225
234
|
- test/validators/cpf_validator_test.rb
|
226
235
|
homepage:
|
@@ -241,8 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
250
|
- !ruby/object:Gem::Version
|
242
251
|
version: '0'
|
243
252
|
requirements: []
|
244
|
-
|
245
|
-
rubygems_version: 2.7.7
|
253
|
+
rubygems_version: 3.0.8
|
246
254
|
signing_key:
|
247
255
|
specification_version: 4
|
248
256
|
summary: Código reutilizável para as aplicações Rails da E.A.C..
|
@@ -263,11 +271,10 @@ test_files:
|
|
263
271
|
- test/dummy/db/migrate/20160415125333_create_users.rb
|
264
272
|
- test/dummy/app/models/job.rb
|
265
273
|
- test/dummy/app/models/user.rb
|
274
|
+
- test/dummy/app/assets/config/manifest.js
|
275
|
+
- test/dummy/bin/rails
|
266
276
|
- test/test_helper.rb
|
267
277
|
- test/validators/cpf_validator_test.rb
|
268
|
-
- test/helpers/eac_rails_utils/common_form_helper_test.rb
|
269
278
|
- test/helpers/eac_rails_utils/data_table_test_helper_test.rb
|
270
279
|
- test/helpers/eac_rails_utils/formatter_helper_test.rb
|
271
|
-
- test/lib/eac_rails_utils/models/attribute_required_test.rb
|
272
|
-
- test/lib/eac_rails_utils/models/tableless_test.rb
|
273
280
|
- test/lib/eac_rails_utils/models/fetch_errors_test.rb
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support/concern'
|
4
|
-
|
5
|
-
module EacRailsUtils
|
6
|
-
module Models
|
7
|
-
module AttributeRequired
|
8
|
-
extend ::ActiveSupport::Concern
|
9
|
-
|
10
|
-
class << self
|
11
|
-
def required?(model_class_or_record, attribute)
|
12
|
-
model = model_class_or_record_to_model(model_class_or_record)
|
13
|
-
record = model.new
|
14
|
-
record.validate
|
15
|
-
record.errors.key?(attribute.to_sym)
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def model_class_or_record_to_model(model_class_or_record)
|
21
|
-
model_class_or_record.is_a?(::Class) ? model_class_or_record : model_class_or_record.class
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
included do
|
26
|
-
extend ClassMethods
|
27
|
-
include InstanceMethods
|
28
|
-
end
|
29
|
-
|
30
|
-
module ClassMethods
|
31
|
-
def column_required?(column)
|
32
|
-
::EacRailsUtils::Models::AttributeRequired.required?(self, column)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
module InstanceMethods
|
37
|
-
def attribute_required?(column)
|
38
|
-
self.class.column_required?(column)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
module EacRailsUtils
|
6
|
-
class CommonFormHelperTest < ActionView::TestCase
|
7
|
-
include ::EacRailsUtils::CommonFormHelper
|
8
|
-
|
9
|
-
setup do
|
10
|
-
reset_test_database
|
11
|
-
end
|
12
|
-
|
13
|
-
test 'test common form' do
|
14
|
-
common_form(User.new) do |f|
|
15
|
-
f.text_field :name
|
16
|
-
f.email_field :email
|
17
|
-
f.password_field :password
|
18
|
-
f.searchable_association_field :job, url: search_jobs_path
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'fields for' do
|
23
|
-
common_form(Job.new) do |f|
|
24
|
-
f.text_field :name
|
25
|
-
f.fields_for :users do |nf|
|
26
|
-
nf.text_field :name
|
27
|
-
nf.email_field :email
|
28
|
-
nf.password_field :password
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
module EacRailsUtils
|
6
|
-
module Patches
|
7
|
-
class ModelAttributeRequiredTest < ActiveSupport::TestCase
|
8
|
-
setup do
|
9
|
-
reset_test_database
|
10
|
-
end
|
11
|
-
|
12
|
-
test 'column with presence validator should be required' do
|
13
|
-
assert User.column_required?(:password)
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'column with format validator should be required' do
|
17
|
-
assert User.column_required?(:email)
|
18
|
-
end
|
19
|
-
|
20
|
-
test 'column without validators should be optional' do
|
21
|
-
assert_not User.column_required?(:name)
|
22
|
-
end
|
23
|
-
|
24
|
-
test 'association with presence validator should be required' do
|
25
|
-
assert User.column_required?(:job)
|
26
|
-
end
|
27
|
-
|
28
|
-
test 'required column in active model' do
|
29
|
-
assert ActiveModelStub.column_required?(:name), 'name is required'
|
30
|
-
assert_not ActiveModelStub.column_required?(:age), 'age is optional'
|
31
|
-
end
|
32
|
-
|
33
|
-
class ActiveModelStub
|
34
|
-
include ActiveModel::Model
|
35
|
-
include ::EacRailsUtils::Models::AttributeRequired
|
36
|
-
|
37
|
-
attr_accessor :name, :age
|
38
|
-
validates :name, presence: true
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
module EacRailsUtils
|
6
|
-
module Models
|
7
|
-
class TablelessTest < ActiveSupport::TestCase
|
8
|
-
class Stub < ::EacRailsUtils::Models::Tableless
|
9
|
-
attribute :tempo, DateTime
|
10
|
-
end
|
11
|
-
|
12
|
-
test 'date time array values' do
|
13
|
-
stub = Stub.new('tempo(1i)' => '9', 'tempo(2i)' => '10', 'tempo(3i)' => '11',
|
14
|
-
'tempo(4i)' => '12', 'tempo(5i)' => '13', 'tempo(6i)' => '14')
|
15
|
-
assert stub.tempo.is_a?(DateTime), "Class: |#{stub.tempo.class}|, Value: |#{stub.tempo}|"
|
16
|
-
assert_equal 9, stub.tempo.year, 'Year'
|
17
|
-
assert_equal 10, stub.tempo.month, 'Month'
|
18
|
-
assert_equal 11, stub.tempo.day, 'Day'
|
19
|
-
assert_equal 12, stub.tempo.hour, 'Hour'
|
20
|
-
assert_equal 13, stub.tempo.minute, 'Minute'
|
21
|
-
assert_equal 14, stub.tempo.second, 'Second'
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|