eac_rails_utils 0.22.1 → 0.22.3

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/eac_rails_utils/common_form_helper/form_builder/association_select_field.rb +1 -1
  3. data/app/helpers/eac_rails_utils/common_form_helper/form_builder/currency_field.rb +1 -1
  4. data/app/helpers/eac_rails_utils/common_form_helper/form_builder/date_field.rb +1 -1
  5. data/app/helpers/eac_rails_utils/common_form_helper/form_builder/radio_select_field.rb +1 -1
  6. data/app/helpers/eac_rails_utils/common_form_helper/form_builder/searchable_association_field.rb +12 -12
  7. data/app/helpers/eac_rails_utils/common_form_helper/form_builder/time_field.rb +1 -1
  8. data/app/helpers/eac_rails_utils/common_form_helper/form_builder.rb +11 -11
  9. data/app/helpers/eac_rails_utils/common_form_helper.rb +3 -3
  10. data/app/helpers/eac_rails_utils/data_table_helper/data_table.rb +1 -1
  11. data/app/helpers/eac_rails_utils/data_table_helper/setup.rb +3 -3
  12. data/app/helpers/eac_rails_utils/links_helper.rb +1 -1
  13. data/app/helpers/eac_rails_utils/menus_helper/bootstrap_gui_builder.rb +14 -14
  14. data/app/helpers/eac_rails_utils/menus_helper/data_builder.rb +3 -3
  15. data/app/helpers/eac_rails_utils/menus_helper/gui_builder.rb +6 -6
  16. data/app/helpers/eac_rails_utils/open_graph_protocol_helper.rb +6 -6
  17. data/app/validators/eac_rails_utils/cpf_validator.rb +1 -1
  18. data/app/validators/eac_rails_utils/immutable_validator.rb +1 -1
  19. data/app/validators/eac_rails_utils/no_presence_validator.rb +1 -1
  20. data/app/validators/eac_rails_utils/yaml_validator.rb +4 -4
  21. data/lib/active_record/associations/builder/has_many_for_active_model.rb +6 -3
  22. data/lib/active_record/associations/has_many_for_active_model_association.rb +6 -6
  23. data/lib/activemodel/associations.rb +1 -1
  24. data/lib/eac_rails_utils/engine.rb +4 -1
  25. data/lib/eac_rails_utils/models/fetch_errors.rb +1 -1
  26. data/lib/eac_rails_utils/models/tableless_associations/override_methods.rb +1 -1
  27. data/lib/eac_rails_utils/models/tableless_associations/railtie.rb +1 -1
  28. data/lib/eac_rails_utils/models/tableless_associations.rb +4 -4
  29. data/lib/eac_rails_utils/models/test_utils.rb +1 -1
  30. data/lib/eac_rails_utils/patches/active_model_associations.rb +2 -2
  31. data/lib/eac_rails_utils/patches/rails_5_2/active_model_association_method_fix.rb +1 -1
  32. data/lib/eac_rails_utils/version.rb +1 -1
  33. metadata +11 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a88b255d31abb1059b16e75e33cb24b9ba2ad64a3d35afd63e27bc1d01dbbbe
4
- data.tar.gz: b50b1587013cb361fe0eb2d7d56ee46dd5bdd87ed6aacf836aee7867ec7c152e
3
+ metadata.gz: 502d1a6b9d9fabc7dd27f46a6d6cde1e7e8636b5b611db680565a40e5084d47e
4
+ data.tar.gz: d1a1161de0a84bd1a5419b34747d1f5bbb70d273a6234d776faf273e8c9f42d1
5
5
  SHA512:
6
- metadata.gz: 1249f9ba2a9598117e86de27b315fdd2f6f0f55330ee39916ea9e03f25c97b9c966a99a476628a1dfda677ea14b518cdf7478ad21eafc41868b4bcf4222fe65e
7
- data.tar.gz: a7def8aa5c32a906ecae3e29b5c42ba669f962c368ad3ae01153de142ce74cc3f3da22f9090cc4d9d97fa359080ed414985be9879b8d3f42ec476e7b6f0dcae9
6
+ metadata.gz: ec590a4a5c4e94fb820412f17da3a2e8ccae156fb516450d61df417213327fb3b64052c4e02967dcb59d7c169172021f0158b07a7f3c7509ee26559ebe40b1a9
7
+ data.tar.gz: 2c06361f27ce85bb7bb7d362e2d0437f4d823f743c7ce6e4f13f72120ed45f787dce16eaed99eee4b71ac341962a34dba00b6866b62130e4c4c87f8696a4d7d0
@@ -44,7 +44,7 @@ module EacRailsUtils
44
44
  model_instance.class.reflect_on_association(field_name)
45
45
  else
46
46
  raise "#{model_instance.class} não possui um método \"reflect_on_association\". " \
47
- "Defina explicitamente a opção :#{key}"
47
+ "Defina explicitamente a opção :#{key}"
48
48
  end
49
49
  end
50
50
 
@@ -20,7 +20,7 @@ module EacRailsUtils
20
20
  def javascript_currency_mask(hidden_id, visible_id)
21
21
  helper.content_tag :script do
22
22
  helper.raw("new CurrencyField('#{hidden_id}', '#{visible_id}', " \
23
- "#{mask_money_options});")
23
+ "#{mask_money_options});")
24
24
  end
25
25
  end
26
26
 
@@ -12,7 +12,7 @@ module EacRailsUtils
12
12
  :order, :include_blank, :default, :selected, :disabled,
13
13
  :prompt, :with_css_classes)
14
14
  field(field_name, options) do
15
- @helper.content_tag(:div, @form.date_select(field_name, field_options),
15
+ @helper.content_tag(:div, @form.date_select(field_name, field_options), # rubocop:disable Rails/HelperInstanceVariable
16
16
  class: 'form-control-complex')
17
17
  end
18
18
  end
@@ -39,7 +39,7 @@ module EacRailsUtils
39
39
  end
40
40
 
41
41
  raise "#{model_instance.class} não possui um método \"reflect_on_association\". " \
42
- "Defina explicitamente a opção :#{key}"
42
+ "Defina explicitamente a opção :#{key}"
43
43
  end
44
44
  end
45
45
  end
@@ -5,23 +5,23 @@ module EacRailsUtils
5
5
  class FormBuilder
6
6
  class SearchableAssociationField
7
7
  def initialize(form_builder, field_name, options)
8
- @form_builder = form_builder
9
- @field_name = field_name
10
- @options = options
8
+ @form_builder = form_builder # rubocop:disable Rails/HelperInstanceVariable
9
+ @field_name = field_name # rubocop:disable Rails/HelperInstanceVariable
10
+ @options = options # rubocop:disable Rails/HelperInstanceVariable
11
11
  end
12
12
 
13
13
  def hidden_input
14
- @form_builder.form.hidden_field(hidden_input_name, id: hidden_input_id)
14
+ @form_builder.form.hidden_field(hidden_input_name, id: hidden_input_id) # rubocop:disable Rails/HelperInstanceVariable
15
15
  end
16
16
 
17
17
  def visible_input
18
- @form_builder.helper.text_field_tag(visible_input_name, '', id: visible_input_id,
18
+ @form_builder.helper.text_field_tag(visible_input_name, '', id: visible_input_id, # rubocop:disable Rails/HelperInstanceVariable
19
19
  class: 'form-control')
20
20
  end
21
21
 
22
22
  def javascript_tag
23
- @form_builder.helper.content_tag(:script) do
24
- @form_builder.helper.raw("new InputSearchable(#{json_options});")
23
+ @form_builder.helper.content_tag(:script) do # rubocop:disable Rails/HelperInstanceVariable
24
+ @form_builder.helper.raw("new InputSearchable(#{json_options});") # rubocop:disable Rails/HelperInstanceVariable
25
25
  end
26
26
  end
27
27
 
@@ -32,7 +32,7 @@ module EacRailsUtils
32
32
  end
33
33
 
34
34
  def hidden_input_name
35
- "#{@field_name}_id"
35
+ "#{@field_name}_id" # rubocop:disable Rails/HelperInstanceVariable
36
36
  end
37
37
 
38
38
  def visible_input_id
@@ -40,11 +40,11 @@ module EacRailsUtils
40
40
  end
41
41
 
42
42
  def visible_input_name
43
- "#{@field_name}_search"
43
+ "#{@field_name}_search" # rubocop:disable Rails/HelperInstanceVariable
44
44
  end
45
45
 
46
46
  def association_column
47
- @form_builder.model_instance&.send(@field_name)
47
+ @form_builder.model_instance&.send(@field_name) # rubocop:disable Rails/HelperInstanceVariable
48
48
  end
49
49
 
50
50
  def initial_id
@@ -61,11 +61,11 @@ module EacRailsUtils
61
61
  end
62
62
 
63
63
  def params
64
- @form_builder.helper.params
64
+ @form_builder.helper.params # rubocop:disable Rails/HelperInstanceVariable
65
65
  end
66
66
 
67
67
  def url
68
- @options[:url]
68
+ @options[:url] # rubocop:disable Rails/HelperInstanceVariable
69
69
  end
70
70
 
71
71
  def json_options
@@ -12,7 +12,7 @@ module EacRailsUtils
12
12
  :order, :include_blank, :default, :selected, :disabled,
13
13
  :prompt, :with_css_classes)
14
14
  field(field_name, options) do
15
- @helper.content_tag(:div, @form.time_select(field_name, field_options),
15
+ @helper.content_tag(:div, @form.time_select(field_name, field_options), # rubocop:disable Rails/HelperInstanceVariable
16
16
  class: 'form-control-complex')
17
17
  end
18
18
  end
@@ -21,9 +21,9 @@ module EacRailsUtils
21
21
  attr_reader :form, :helper, :field_errors_showed
22
22
 
23
23
  def initialize(form, helper)
24
- @form = form
25
- @helper = helper
26
- @field_errors_showed = Set.new
24
+ @form = form # rubocop:disable Rails/HelperInstanceVariable
25
+ @helper = helper # rubocop:disable Rails/HelperInstanceVariable
26
+ @field_errors_showed = Set.new # rubocop:disable Rails/HelperInstanceVariable
27
27
  end
28
28
 
29
29
  def association_select_field(field_name, options = {})
@@ -36,15 +36,15 @@ module EacRailsUtils
36
36
  end
37
37
 
38
38
  def hidden_field(field_name, options = {})
39
- @form.hidden_field(field_name, options)
39
+ @form.hidden_field(field_name, options) # rubocop:disable Rails/HelperInstanceVariable
40
40
  end
41
41
 
42
42
  def check_box_field(field_name, options = {})
43
- field(field_name, options) { @form.check_box(field_name, options) }
43
+ field(field_name, options) { @form.check_box(field_name, options) } # rubocop:disable Rails/HelperInstanceVariable
44
44
  end
45
45
 
46
46
  def file_field(field_name, options = {})
47
- field(field_name, options) { @form.file_field(field_name, options) }
47
+ field(field_name, options) { @form.file_field(field_name, options) } # rubocop:disable Rails/HelperInstanceVariable
48
48
  end
49
49
 
50
50
  def searchable_association_field(field_name, options = {})
@@ -57,7 +57,7 @@ module EacRailsUtils
57
57
  private
58
58
 
59
59
  def field(field_name, options)
60
- @helper.content_tag(:div, class: 'form-group') do
60
+ @helper.content_tag(:div, class: 'form-group') do # rubocop:disable Rails/HelperInstanceVariable
61
61
  s = field_label(field_name, options[:label], options[:required])
62
62
  s << ' '
63
63
  s << yield()
@@ -80,7 +80,7 @@ module EacRailsUtils
80
80
 
81
81
  s = ActiveSupport::SafeBuffer.new
82
82
  model_instance.errors.messages[field_name].each { |error| s << field_error(error) }
83
- @field_errors_showed.add(field_name)
83
+ @field_errors_showed.add(field_name) # rubocop:disable Rails/HelperInstanceVariable
84
84
  s
85
85
  end
86
86
 
@@ -90,7 +90,7 @@ module EacRailsUtils
90
90
  end
91
91
 
92
92
  def field_error(error_message)
93
- @helper.content_tag(:div, class: 'error') do
93
+ @helper.content_tag(:div, class: 'error') do # rubocop:disable Rails/HelperInstanceVariable
94
94
  error_message
95
95
  end
96
96
  end
@@ -98,9 +98,9 @@ module EacRailsUtils
98
98
  def field_label(field_name, label, required)
99
99
  if required.nil?
100
100
  required = ::EacRailsUtils::Models::Validations
101
- .column_required?(model_instance, field_name)
101
+ .column_required?(model_instance, field_name)
102
102
  end
103
- @form.label(field_name, label, class: required ? 'required' : 'optional')
103
+ @form.label(field_name, label, class: required ? 'required' : 'optional') # rubocop:disable Rails/HelperInstanceVariable
104
104
  end
105
105
  end
106
106
  end
@@ -37,10 +37,10 @@ module EacRailsUtils
37
37
 
38
38
  def errors_not_showed(model_instance, field_errors_showed)
39
39
  s = ActiveSupport::SafeBuffer.new
40
- model_instance.errors.each do |k, v|
41
- next if field_errors_showed.include?(k)
40
+ model_instance.errors.each do |error|
41
+ next if field_errors_showed.include?(error.attribute)
42
42
 
43
- s << content_tag(:div, "#{k}: #{v}", class: 'error')
43
+ s << content_tag(:div, "#{error.attribute}: #{error.message}", class: 'error')
44
44
  end
45
45
  s
46
46
  end
@@ -41,7 +41,7 @@ module EacRailsUtils
41
41
  view.javascript_tag <<~JS_CODE
42
42
  $(document).ready(function () {
43
43
  $('##{id}').DataTable({
44
- paging: #{@setup.paging ? 'true' : 'false'}
44
+ paging: #{setup.paging ? 'true' : 'false'} # rubocop:disable Rails/HelperInstanceVariable
45
45
  });
46
46
  });
47
47
  JS_CODE
@@ -7,14 +7,14 @@ module EacRailsUtils
7
7
  attr_accessor :paging
8
8
 
9
9
  def initialize
10
- @columns = []
11
- @paging = true
10
+ @columns = [] # rubocop:disable Rails/HelperInstanceVariable
11
+ @paging = true # rubocop:disable Rails/HelperInstanceVariable
12
12
  end
13
13
 
14
14
  # @return [EacRailsUtils::DataTableHelper::Column]
15
15
  def column(*args, &block)
16
16
  column = ::EacRailsUtils::DataTableHelper::Column.new(args, block)
17
- @columns << column
17
+ @columns << column # rubocop:disable Rails/HelperInstanceVariable
18
18
  column
19
19
  end
20
20
  end
@@ -45,7 +45,7 @@ module EacRailsUtils
45
45
  current_class = current_class.superclass
46
46
  end
47
47
  raise "Path not found for {object: #{object.class}, action: \"#{action}\"}" \
48
- "(Tried: #{tried_paths})"
48
+ "(Tried: #{tried_paths})"
49
49
  end
50
50
 
51
51
  private
@@ -5,14 +5,14 @@ module EacRailsUtils
5
5
  # http://bootsnipp.com/snippets/featured/multi-level-dropdown-menu-bs3
6
6
  class BootstrapGuiBuilder
7
7
  def initialize(view, options = {})
8
- @view = view
9
- @options = options
8
+ @view = view # rubocop:disable Rails/HelperInstanceVariable
9
+ @options = options # rubocop:disable Rails/HelperInstanceVariable
10
10
  end
11
11
 
12
12
  def build(entries)
13
13
  raise 'Argument "entries" is not a array' unless entries.is_a?(Array)
14
14
 
15
- @view.content_tag(:ul, class: "nav navbar-nav #{@options[:class]}".strip) do
15
+ @view.content_tag(:ul, class: "nav navbar-nav #{@options[:class]}".strip) do # rubocop:disable Rails/HelperInstanceVariable
16
16
  menu_entries(entries)
17
17
  end
18
18
  end
@@ -44,38 +44,38 @@ module EacRailsUtils
44
44
  end
45
45
 
46
46
  def menu_group_root(entry)
47
- @view.content_tag(:li, class: 'dropdown') do
47
+ @view.content_tag(:li, class: 'dropdown') do # rubocop:disable Rails/HelperInstanceVariable
48
48
  menu_group_root_button(entry) << menu_group_root_children(entry)
49
49
  end
50
50
  end
51
51
 
52
52
  def menu_group_root_button(entry)
53
- @view.content_tag(:a, :role => 'button', 'data-toggle' => 'dropdown',
54
- :class => "btn #{@options[:button_class]}",
53
+ @view.content_tag(:a, :role => 'button', 'data-toggle' => 'dropdown', # rubocop:disable Rails/HelperInstanceVariable
54
+ :class => "btn #{@options[:button_class]}", # rubocop:disable Rails/HelperInstanceVariable
55
55
  :'data-target' => '#') do
56
- ActiveSupport::SafeBuffer.new(entry[:label]) << ' ' << @view.tag(:span, class: 'caret')
56
+ ActiveSupport::SafeBuffer.new(entry[:label]) << ' ' << @view.tag(:span, class: 'caret') # rubocop:disable Rails/HelperInstanceVariable
57
57
  end
58
58
  end
59
59
 
60
60
  def menu_group_root_children(entry)
61
- @view.content_tag(:ul, class: 'dropdown-menu multi-level', role: 'menu',
61
+ @view.content_tag(:ul, class: 'dropdown-menu multi-level', role: 'menu', # rubocop:disable Rails/HelperInstanceVariable
62
62
  'aria-labelledby': 'dropdownMenu') do
63
63
  menu_entries(entry[:children])
64
64
  end
65
65
  end
66
66
 
67
67
  def menu_group_sub(entry)
68
- @view.content_tag(:li, class: 'dropdown-submenu') do
69
- @view.link_to(entry[:label], '#', tabindex: -1) <<
70
- @view.content_tag(:ul, class: 'dropdown-menu') do
68
+ @view.content_tag(:li, class: 'dropdown-submenu') do # rubocop:disable Rails/HelperInstanceVariable
69
+ @view.link_to(entry[:label], '#', tabindex: -1) << # rubocop:disable Rails/HelperInstanceVariable
70
+ @view.content_tag(:ul, class: 'dropdown-menu') do # rubocop:disable Rails/HelperInstanceVariable
71
71
  menu_entries(entry[:children])
72
72
  end
73
73
  end
74
74
  end
75
75
 
76
76
  def menu_item(entry)
77
- @view.content_tag(:li) do
78
- @view.link_to(entry[:label], entry[:path], menu_item_options(entry))
77
+ @view.content_tag(:li) do # rubocop:disable Rails/HelperInstanceVariable
78
+ @view.link_to(entry[:label], entry[:path], menu_item_options(entry)) # rubocop:disable Rails/HelperInstanceVariable
79
79
  end
80
80
  end
81
81
 
@@ -85,7 +85,7 @@ module EacRailsUtils
85
85
  options[:method] = options[:link_method]
86
86
  options.delete(:link_method)
87
87
  end
88
- options[:class] = (@options[:button_class]).to_s.strip if entry[:level].zero?
88
+ options[:class] = (@options[:button_class]).to_s.strip if entry[:level].zero? # rubocop:disable Rails/HelperInstanceVariable
89
89
  options
90
90
  end
91
91
  end
@@ -4,7 +4,7 @@ module EacRailsUtils
4
4
  module MenusHelper
5
5
  class DataBuilder
6
6
  def initialize(view)
7
- @view = view
7
+ @view = view # rubocop:disable Rails/HelperInstanceVariable
8
8
  end
9
9
 
10
10
  def build(entries)
@@ -51,8 +51,8 @@ module EacRailsUtils
51
51
  end
52
52
 
53
53
  def can_access_path?(path, method)
54
- if @view.respond_to?(:'can_by_path?')
55
- @view.can_by_path?(path, method)
54
+ if @view.respond_to?(:can_by_path?) # rubocop:disable Rails/HelperInstanceVariable
55
+ @view.can_by_path?(path, method) # rubocop:disable Rails/HelperInstanceVariable
56
56
  else
57
57
  true
58
58
  end
@@ -4,13 +4,13 @@ module EacRailsUtils
4
4
  module MenusHelper
5
5
  class GuiBuilder
6
6
  def initialize(view)
7
- @view = view
7
+ @view = view # rubocop:disable Rails/HelperInstanceVariable
8
8
  end
9
9
 
10
10
  def build(entries, options = {})
11
11
  raise 'Argument "entries" is not a array' unless entries.is_a?(Array)
12
12
 
13
- @view.content_tag(:ul, options) do
13
+ @view.content_tag(:ul, options) do # rubocop:disable Rails/HelperInstanceVariable
14
14
  b = ActiveSupport::SafeBuffer.new
15
15
  entries.map { |v| menu_entry(v) }.each { |e| b << e }
16
16
  b
@@ -30,14 +30,14 @@ module EacRailsUtils
30
30
  end
31
31
 
32
32
  def menu_group(label, children)
33
- @view.content_tag(:li) do
34
- @view.link_to(label) << build(children)
33
+ @view.content_tag(:li) do # rubocop:disable Rails/HelperInstanceVariable
34
+ @view.link_to(label) << build(children) # rubocop:disable Rails/HelperInstanceVariable
35
35
  end
36
36
  end
37
37
 
38
38
  def menu_item(label, path, options)
39
- @view.content_tag(:li) do
40
- @view.link_to(label, path, menu_item_link_options(options))
39
+ @view.content_tag(:li) do # rubocop:disable Rails/HelperInstanceVariable
40
+ @view.link_to(label, path, menu_item_link_options(options)) # rubocop:disable Rails/HelperInstanceVariable
41
41
  end
42
42
  end
43
43
 
@@ -28,18 +28,18 @@ module EacRailsUtils
28
28
  attr_reader :view
29
29
 
30
30
  def initialize(view)
31
- @view = view
32
- @children = ::ActiveSupport::HashWithIndifferentAccess.new
31
+ @view = view # rubocop:disable Rails/HelperInstanceVariable
32
+ @children = ::ActiveSupport::HashWithIndifferentAccess.new # rubocop:disable Rails/HelperInstanceVariable
33
33
  end
34
34
 
35
35
  def child(child_suffix)
36
- @children[child_suffix] ||= Entry.new(view, self, child_suffix)
36
+ @children[child_suffix] ||= Entry.new(view, self, child_suffix) # rubocop:disable Rails/HelperInstanceVariable
37
37
  end
38
38
 
39
39
  def children_tags
40
40
  view.capture do
41
41
  view.concat tag
42
- @children.values.each do |child|
42
+ @children.values.each do |child| # rubocop:disable Rails/HelperInstanceVariable
43
43
  view.concat(child.children_tags)
44
44
  view.concat("\n")
45
45
  end
@@ -60,8 +60,8 @@ module EacRailsUtils
60
60
 
61
61
  def initialize(view, parent, suffix)
62
62
  super view
63
- @parent = parent
64
- @suffix = suffix
63
+ @parent = parent # rubocop:disable Rails/HelperInstanceVariable
64
+ @suffix = suffix # rubocop:disable Rails/HelperInstanceVariable
65
65
  end
66
66
 
67
67
  def components
@@ -5,7 +5,7 @@ module EacRailsUtils
5
5
  def validate_each(record, attribute, value)
6
6
  return if Cpf.new(value).valid?
7
7
 
8
- record.errors[attribute] << (options[:message] ||
8
+ record.errors[attribute] << (options[:message] || # rubocop:disable Rails/DeprecatedActiveModelErrorsMethods
9
9
  'CPF inválido (9 caracteres, somente dígitos)')
10
10
  end
11
11
 
@@ -8,7 +8,7 @@ module EacRailsUtils
8
8
  return if record.new_record?
9
9
  return unless record.send("#{attribute}_changed?")
10
10
 
11
- record.errors[attribute] << (options[:message] || DEFAULT_MESSAGE)
11
+ record.errors[attribute] << (options[:message] || DEFAULT_MESSAGE) # rubocop:disable Rails/DeprecatedActiveModelErrorsMethods
12
12
  end
13
13
  end
14
14
  end
@@ -6,7 +6,7 @@ module EacRailsUtils
6
6
  def validate_each(record, attribute, _value)
7
7
  return if record.send(attribute).blank?
8
8
 
9
- record.errors[attribute] << (options[:message] || 'must be blank')
9
+ record.errors[attribute] << (options[:message] || 'must be blank') # rubocop:disable Rails/DeprecatedActiveModelErrorsMethods
10
10
  end
11
11
  end
12
12
  end
@@ -16,23 +16,23 @@ module EacRailsUtils
16
16
 
17
17
  return if ::EacRubyUtils::Yaml.yaml?(string_value)
18
18
 
19
- record.errors[attribute] << (options[:message] || DEFAULT_INVALID_YAML_MESSAGE)
19
+ record.errors.add(attribute, options[:message] || DEFAULT_INVALID_YAML_MESSAGE)
20
20
  end
21
21
 
22
22
  protected
23
23
 
24
24
  # @param value [Object]
25
25
  # @return [String, nil]
26
- def stringfy_value(value) # rubocop:disable Metrics/AbcSize
26
+ def stringfy_value(value)
27
27
  unless value.respond_to?(:to_s)
28
- record.errors[attribute] << (options[:message] || DEFAULT_TO_S_UNAVAILABLE_MESSAGE)
28
+ record.errors.add(attribute, options[:message] || DEFAULT_TO_S_UNAVAILABLE_MESSAGE)
29
29
  return nil
30
30
  end
31
31
 
32
32
  r = value.to_s
33
33
  return r if value.is_a?(::String)
34
34
 
35
- record.errors[attribute] << (options[:message] || DEFAULT_NOT_A_STRING_MESSAGE)
35
+ record.errors.add(attribute, options[:message] || DEFAULT_NOT_A_STRING_MESSAGE)
36
36
  nil
37
37
  end
38
38
  end
@@ -1,10 +1,12 @@
1
1
  module ActiveRecord::Associations::Builder
2
2
  class HasManyForActiveModel < HasMany
3
3
  if ActiveRecord.version >= Gem::Version.new("5.0.0.beta")
4
- AR_CALLBACK_METHODS = %i(define_callback before_validation after_validation before_save after_save before_update after_update)
4
+ AR_CALLBACK_METHODS = %i(define_callback before_validation after_validation before_save
5
+ after_save before_update after_update)
5
6
 
6
7
  def self.valid_options(_options)
7
- super + [:active_model, :target_ids] - [:through, :dependent, :source, :source_type, :counter_cache, :as]
8
+ super + [:active_model,
9
+ :target_ids] - [:through, :dependent, :source, :source_type, :counter_cache, :as]
8
10
  end
9
11
 
10
12
  def self.define_callbacks(model, reflection)
@@ -14,7 +16,8 @@ module ActiveRecord::Associations::Builder
14
16
  end
15
17
  else
16
18
  def valid_options
17
- super + [:active_model, :target_ids] - [:through, :dependent, :source, :source_type, :counter_cache, :as]
19
+ super + [:active_model,
20
+ :target_ids] - [:through, :dependent, :source, :source_type, :counter_cache, :as]
18
21
  end
19
22
  end
20
23
  end
@@ -1,6 +1,6 @@
1
1
  module ActiveRecord::Associations
2
2
  class HasManyForActiveModelAssociation < HasManyAssociation
3
- # remove conditions: owner.new_record?, foreign_key_present?
3
+ # remove conditions: owner.new_record?, foreign_key_present?
4
4
  def find_target?
5
5
  !loaded? && klass
6
6
  end
@@ -20,7 +20,7 @@ module ActiveRecord::Associations
20
20
  end
21
21
 
22
22
  # full replace simplely
23
- def replace(other_array)
23
+ def replace(other_array) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
24
24
  original_target = load_target.dup
25
25
  other_array.each { |val| raise_on_type_mismatch!(val) }
26
26
  target_ids = reflection.options[:target_ids]
@@ -32,7 +32,7 @@ module ActiveRecord::Associations
32
32
  end
33
33
 
34
34
  other_array.each do |record|
35
- if index = @target.index(record)
35
+ if (index = @target.index(record))
36
36
  @target[index] = record
37
37
  else
38
38
  @target << record
@@ -41,7 +41,7 @@ module ActiveRecord::Associations
41
41
  end
42
42
 
43
43
  # no need transaction
44
- def concat(*records)
44
+ def concat(*records) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
45
45
  load_target
46
46
  flatten_records = records.flatten
47
47
  flatten_records.each { |val| raise_on_type_mismatch!(val) }
@@ -50,7 +50,7 @@ module ActiveRecord::Associations
50
50
  owner[target_ids].concat(flatten_records.map(&:id))
51
51
 
52
52
  flatten_records.each do |record|
53
- if index = @target.index(record)
53
+ if (index = @target.index(record))
54
54
  @target[index] = record
55
55
  else
56
56
  @target << record
@@ -62,7 +62,7 @@ module ActiveRecord::Associations
62
62
 
63
63
  private
64
64
 
65
- def get_records
65
+ def get_records # rubocop:disable Naming/AccessorMethodName
66
66
  return scope.to_a if reflection.scope_chain.any?(&:any?)
67
67
 
68
68
  target_ids = reflection.options[:target_ids]
@@ -7,7 +7,7 @@ require "eac_rails_utils/models/tableless_associations/hooks"
7
7
  # Load Railtie
8
8
  begin
9
9
  require "rails"
10
- rescue LoadError
10
+ rescue LoadError # rubocop:disable Lint/SuppressedException
11
11
  end
12
12
 
13
13
  if defined?(Rails)
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_rails_utils/engine_helper'
3
4
  require 'nested_form_fields'
4
5
 
5
6
  module EacRailsUtils
6
- class Engine < ::Rails::Engine; end
7
+ class Engine < ::Rails::Engine
8
+ include ::EacRailsUtils::EngineHelper
9
+ end
7
10
  end
@@ -10,7 +10,7 @@ module EacRailsUtils
10
10
  # Um array de colunas pode ser passado em options[:skip] de colunas em record que não
11
11
  # terão suas falhas adicionadas.
12
12
  def fetch_record_errors(record, options = {})
13
- record.errors.keys.each do |column|
13
+ record.errors.keys.each do |column| # rubocop:disable Rails/DeprecatedActiveModelErrorsMethods
14
14
  fetch_column_errors(record, column, column, options)
15
15
  end
16
16
  end
@@ -69,7 +69,7 @@ module EacRailsUtils
69
69
  end
70
70
 
71
71
  # use by association accessor
72
- def association(name) #:nodoc:
72
+ def association(name) # :nodoc:
73
73
  association = association_instance_get(name)
74
74
 
75
75
  if association.nil?
@@ -3,7 +3,7 @@
3
3
  module EacRailsUtils
4
4
  module Models
5
5
  module TablelessAssociations
6
- class Railtie < ::Rails::Railtie #:nodoc:
6
+ class Railtie < ::Rails::Railtie # :nodoc:
7
7
  initializer 'activemodel-associations' do |_|
8
8
  EacRailsUtils::Models::TablelessAssociations::Hooks.init
9
9
  end
@@ -24,14 +24,14 @@ module EacRailsUtils
24
24
 
25
25
  module ClassMethods
26
26
  # define association like ActiveRecord
27
- def belongs_to(name, scope = nil, options = {})
27
+ def belongs_to(name, scope = nil, **options)
28
28
  reflection = ActiveRecord::Associations::Builder::BelongsTo
29
- .build(self, name, scope, options)
29
+ .build(self, name, scope, options)
30
30
  ActiveRecord::Reflection.add_reflection self, name, reflection
31
31
  end
32
32
 
33
33
  # define association like ActiveRecord
34
- def has_many(name, scope = nil, options = {}, &extension) # rubocop:disable Naming/PredicateName
34
+ def has_many(name, scope = nil, **options, &extension) # rubocop:disable Naming/PredicateName, Metrics/MethodLength
35
35
  options.reverse_merge!(active_model: true, target_ids: "#{name.to_s.singularize}_ids")
36
36
  if scope.is_a?(Hash)
37
37
  options.merge!(scope)
@@ -39,7 +39,7 @@ module EacRailsUtils
39
39
  end
40
40
 
41
41
  reflection = ActiveRecord::Associations::Builder::HasManyForActiveModel
42
- .build(self, name, scope, options, &extension)
42
+ .build(self, name, scope, options, &extension)
43
43
  ActiveRecord::Reflection.add_reflection self, name, reflection
44
44
 
45
45
  mixin = generated_association_methods
@@ -22,7 +22,7 @@ module EacRailsUtils
22
22
  assert record.errors[c].empty?,
23
23
  "Column: #{c} should not have errors (#{record.errors[c]})"
24
24
  end
25
- fields_with_error. each do |c|
25
+ fields_with_error.each do |c|
26
26
  assert_not record.errors[c].empty?, "Column: #{c} should have errors"
27
27
  end
28
28
  end
@@ -14,7 +14,7 @@ module EacRailsUtils
14
14
  init_rails_5_2 if ::EacRailsUtils::Patches::Rails52.enabled?
15
15
  end
16
16
 
17
- def init_rails_4
17
+ def init_rails_4 # rubocop:disable Naming/VariableNumber
18
18
  ActiveSupport.on_load(:active_record) do
19
19
  ActiveRecord::Associations::AssociationScope.prepend(
20
20
  ::EacRailsUtils::Patches::Rails4::ActiveRecordAssociationsAssociationScope
@@ -22,7 +22,7 @@ module EacRailsUtils
22
22
  end
23
23
  end
24
24
 
25
- def init_rails_5_2
25
+ def init_rails_5_2 # rubocop:disable Naming/VariableNumber
26
26
  rails_5_2_fix_activemodel_associations_methods
27
27
  end
28
28
 
@@ -12,7 +12,7 @@ module EacRailsUtils
12
12
  end
13
13
 
14
14
  def original_method_new_name
15
- "original_#{method_name}".to_sym
15
+ :"original_#{method_name}"
16
16
  end
17
17
 
18
18
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRailsUtils
4
- VERSION = '0.22.1'
4
+ VERSION = '0.22.3'
5
5
  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.22.1
4
+ version: 0.22.3
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: 2023-10-09 00:00:00.000000000 Z
11
+ date: 2024-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bootstrap-sass
@@ -36,20 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0.119'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 0.119.2
39
+ version: '0.121'
43
40
  type: :runtime
44
41
  prerelease: false
45
42
  version_requirements: !ruby/object:Gem::Requirement
46
43
  requirements:
47
44
  - - "~>"
48
45
  - !ruby/object:Gem::Version
49
- version: '0.119'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 0.119.2
46
+ version: '0.121'
53
47
  - !ruby/object:Gem::Dependency
54
48
  name: htmlbeautifier
55
49
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +53,7 @@ dependencies:
59
53
  version: '1.4'
60
54
  - - ">="
61
55
  - !ruby/object:Gem::Version
62
- version: 1.4.2
56
+ version: 1.4.3
63
57
  type: :runtime
64
58
  prerelease: false
65
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -69,7 +63,7 @@ dependencies:
69
63
  version: '1.4'
70
64
  - - ">="
71
65
  - !ruby/object:Gem::Version
72
- version: 1.4.2
66
+ version: 1.4.3
73
67
  - !ruby/object:Gem::Dependency
74
68
  name: rails
75
69
  requirement: !ruby/object:Gem::Requirement
@@ -124,20 +118,20 @@ dependencies:
124
118
  requirements:
125
119
  - - "~>"
126
120
  - !ruby/object:Gem::Version
127
- version: '0.4'
121
+ version: '0.9'
128
122
  - - ">="
129
123
  - !ruby/object:Gem::Version
130
- version: 0.4.1
124
+ version: 0.9.2
131
125
  type: :development
132
126
  prerelease: false
133
127
  version_requirements: !ruby/object:Gem::Requirement
134
128
  requirements:
135
129
  - - "~>"
136
130
  - !ruby/object:Gem::Version
137
- version: '0.4'
131
+ version: '0.9'
138
132
  - - ">="
139
133
  - !ruby/object:Gem::Version
140
- version: 0.4.1
134
+ version: 0.9.2
141
135
  description:
142
136
  email:
143
137
  executables: []
@@ -254,7 +248,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
254
248
  requirements:
255
249
  - - ">="
256
250
  - !ruby/object:Gem::Version
257
- version: '0'
251
+ version: '2.7'
258
252
  required_rubygems_version: !ruby/object:Gem::Requirement
259
253
  requirements:
260
254
  - - ">="