eac_rails_utils 0.11.0 → 0.11.5
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/select_field.rb +2 -1
- 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 +1 -1
- data/lib/eac_rails_utils/patches/active_model_associations.rb +40 -0
- data/lib/eac_rails_utils/version.rb +1 -1
- data/test/dummy/app/assets/config/manifest.js +3 -0
- 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 +24 -6
- data/test/helpers/eac_rails_utils/common_form_helper_test.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e74de3cf5f5df2ebc5dbf47d99ccf3adb446b60debbc0ae0ba4bdc0341b0702
|
4
|
+
data.tar.gz: 1fc1a3c6b2f1e28cca60ee396a69dcd682e739390c321c3b0ca6a4bb74aa19a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2227dab9cbab9704b6a227a29873c2d9db7de472cbe78e0546728ca171dff4b6e9af70b412b984ccfbf5c608bb501d03ba9ee23ac796877bf5759cd71bf542d
|
7
|
+
data.tar.gz: bc70bf917704e2c28f0d2a0fedeacdee1d09e48384f1ffd8fd5ed180b6d24ff77f1257c2081ea449999236c0a9a2c862e4f2897cc56904e036798489b6116476
|
@@ -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)
|
@@ -7,7 +7,8 @@ module EacRailsUtils
|
|
7
7
|
def select_field(field_name, options = {})
|
8
8
|
options = options.dup
|
9
9
|
field(field_name, options) do
|
10
|
-
form.select(field_name, select_options(field_name, options)
|
10
|
+
form.select(field_name, select_options(field_name, options),
|
11
|
+
options, options[:html] || {})
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -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 = {})
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_model/associations/hooks'
|
4
|
+
require 'activemodel/associations'
|
5
|
+
|
6
|
+
module EacRailsUtils
|
7
|
+
module Patches
|
8
|
+
module ActiveModelAssociations
|
9
|
+
module ScopeExtensionPatch
|
10
|
+
def add_constraints(scope, owner, association_klass, *extra_args)
|
11
|
+
if extra_args.any?
|
12
|
+
refl = extra_args.first
|
13
|
+
if refl.options[:active_model]
|
14
|
+
target_ids = refl.options[:target_ids]
|
15
|
+
return scope.where(id: owner[target_ids])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
super
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module ActiveModel
|
27
|
+
module Associations
|
28
|
+
module Hooks
|
29
|
+
def self.init
|
30
|
+
return unless ::Rails.version < '5'
|
31
|
+
|
32
|
+
ActiveSupport.on_load(:active_record) do
|
33
|
+
ActiveRecord::Associations::AssociationScope.prepend(
|
34
|
+
::EacRailsUtils::Patches::ActiveModelAssociations::ScopeExtensionPatch
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
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.11.
|
4
|
+
version: 0.11.5
|
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-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel-associations
|
@@ -128,6 +128,20 @@ dependencies:
|
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0.1'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: rspec-rails
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
131
145
|
- !ruby/object:Gem::Dependency
|
132
146
|
name: sqlite3
|
133
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -175,6 +189,8 @@ files:
|
|
175
189
|
- app/helpers/eac_rails_utils/open_graph_protocol_helper.rb
|
176
190
|
- app/validators/eac_rails_utils/cpf_validator.rb
|
177
191
|
- app/validators/eac_rails_utils/no_presence_validator.rb
|
192
|
+
- config/locales/en.yml
|
193
|
+
- config/locales/pt-BR.yml
|
178
194
|
- lib/assets/javascripts/currency_field.js
|
179
195
|
- lib/assets/javascripts/eac_rails_utils.js
|
180
196
|
- lib/assets/javascripts/input_searchable.js
|
@@ -197,10 +213,13 @@ files:
|
|
197
213
|
- lib/eac_rails_utils/models/test_utils.rb
|
198
214
|
- lib/eac_rails_utils/patches.rb
|
199
215
|
- lib/eac_rails_utils/patches/action_controller_base.rb
|
216
|
+
- lib/eac_rails_utils/patches/active_model_associations.rb
|
200
217
|
- lib/eac_rails_utils/version.rb
|
201
218
|
- test/dummy/Rakefile
|
219
|
+
- test/dummy/app/assets/config/manifest.js
|
202
220
|
- test/dummy/app/models/job.rb
|
203
221
|
- test/dummy/app/models/user.rb
|
222
|
+
- test/dummy/bin/rails
|
204
223
|
- test/dummy/config.ru
|
205
224
|
- test/dummy/config/application.rb
|
206
225
|
- test/dummy/config/boot.rb
|
@@ -214,7 +233,6 @@ files:
|
|
214
233
|
- test/dummy/db/migrate/20160415143123_create_jobs.rb
|
215
234
|
- test/dummy/db/migrate/20160415143229_add_job_to_users.rb
|
216
235
|
- test/dummy/db/schema.rb
|
217
|
-
- test/helpers/eac_rails_utils/common_form_helper_test.rb
|
218
236
|
- test/helpers/eac_rails_utils/data_table_test_helper_test.rb
|
219
237
|
- test/helpers/eac_rails_utils/formatter_helper_test.rb
|
220
238
|
- test/lib/eac_rails_utils/models/attribute_required_test.rb
|
@@ -240,8 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
240
258
|
- !ruby/object:Gem::Version
|
241
259
|
version: '0'
|
242
260
|
requirements: []
|
243
|
-
|
244
|
-
rubygems_version: 2.7.7
|
261
|
+
rubygems_version: 3.0.8
|
245
262
|
signing_key:
|
246
263
|
specification_version: 4
|
247
264
|
summary: Código reutilizável para as aplicações Rails da E.A.C..
|
@@ -262,9 +279,10 @@ test_files:
|
|
262
279
|
- test/dummy/db/migrate/20160415125333_create_users.rb
|
263
280
|
- test/dummy/app/models/job.rb
|
264
281
|
- test/dummy/app/models/user.rb
|
282
|
+
- test/dummy/app/assets/config/manifest.js
|
283
|
+
- test/dummy/bin/rails
|
265
284
|
- test/test_helper.rb
|
266
285
|
- test/validators/cpf_validator_test.rb
|
267
|
-
- test/helpers/eac_rails_utils/common_form_helper_test.rb
|
268
286
|
- test/helpers/eac_rails_utils/data_table_test_helper_test.rb
|
269
287
|
- test/helpers/eac_rails_utils/formatter_helper_test.rb
|
270
288
|
- test/lib/eac_rails_utils/models/attribute_required_test.rb
|
@@ -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
|