eac_rails_utils 0.22.2 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) 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 +4 -2
  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/uri_validator.rb +14 -0
  21. data/app/validators/eac_rails_utils/yaml_validator.rb +4 -4
  22. data/lib/active_record/associations/builder/has_many_for_active_model.rb +6 -3
  23. data/lib/active_record/associations/has_many_for_active_model_association.rb +6 -6
  24. data/lib/activemodel/associations.rb +1 -1
  25. data/lib/eac_rails_utils/engine.rb +4 -1
  26. data/lib/eac_rails_utils/models/fetch_errors.rb +1 -1
  27. data/lib/eac_rails_utils/models/tableless_associations/override_methods.rb +1 -1
  28. data/lib/eac_rails_utils/models/tableless_associations/railtie.rb +1 -1
  29. data/lib/eac_rails_utils/models/tableless_associations.rb +3 -3
  30. data/lib/eac_rails_utils/models/test_utils.rb +1 -1
  31. data/lib/eac_rails_utils/patches/active_model_associations.rb +2 -2
  32. data/lib/eac_rails_utils/patches/rails_5_2/active_model_association_method_fix.rb +1 -1
  33. data/lib/eac_rails_utils/version.rb +1 -1
  34. metadata +10 -42
  35. data/lib/eac_rails_utils/htmlbeautifier.rb +0 -27
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '096e1328b734ccfab79690e9ca698890b50c24edb64eed9031e703a9ebe73a23'
4
- data.tar.gz: a50b9109efb4f930a112c72c6681fef83539433d469adb4acea25fde231790ca
3
+ metadata.gz: b0ab91f74f6a656bab19d9e3fa4205943442f4c43a706b6c38bb37e1cb8cf580
4
+ data.tar.gz: 552cac7832c619d0f7a6e7f31025b695fdaecd3ce70eb22c2835ba2483b6d4b6
5
5
  SHA512:
6
- metadata.gz: 0d94028a4405b995ccd494f1654ec0fe89183c7984fc135957b6b96c50701926250d0c9f04a062c7704b2fac49191a1e72d2bf468ddc0fcbc063cf717bd274cd
7
- data.tar.gz: 3607deb9c25681a9c33bc4160c88d1d139995a676d59362d0066fed68465d1dd70d3a171581406291fbad6764210274fd78bb5cdf981ab5c1785b7b26b730bfa
6
+ metadata.gz: 68233af01e090a2e474bac06f735a373fc976016f25dbc998cc612ae972517f530375e755b1716ab95cb0ec974ade30a4393abe99e0a546d817630ec45d30f7e
7
+ data.tar.gz: 12460dced27d15eaf70d5e8248cb1c57f7a6c65fb57173017c9a9bb6dfc983c3ba4c765ce3cd04979cf46f1420156c765757e3807e4f0dc02edadcd0486aae32
@@ -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,8 +5,10 @@ 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] ||
9
- 'CPF inválido (9 caracteres, somente dígitos)')
8
+ record.errors.add(
9
+ attribute,
10
+ options[:message] || 'CPF inválido (9 caracteres, somente dígitos)'
11
+ )
10
12
  end
11
13
 
12
14
  class Cpf
@@ -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.add(attribute, options[:message] || 'must be blank')
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'addressable'
4
+
5
+ module EacRailsUtils
6
+ class UriValidator < ActiveModel::EachValidator
7
+ def validate_each(record, attribute, value)
8
+ r = ::Addressable::URI.parse(value)
9
+ raise ::Addressable::URI::InvalidURIError, 'No scheme' if r.scheme.blank?
10
+ rescue ::Addressable::URI::InvalidURIError => e
11
+ record.errors.add(attribute, options[:message] || e.message)
12
+ end
13
+ end
14
+ 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
@@ -26,12 +26,12 @@ module EacRailsUtils
26
26
  # define association like ActiveRecord
27
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.2'
4
+ VERSION = '0.23.0'
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.2
4
+ version: 0.23.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: 2023-10-11 00:00:00.000000000 Z
11
+ date: 2024-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bootstrap-sass
@@ -36,54 +36,28 @@ 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
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '0.119'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 0.119.2
53
- - !ruby/object:Gem::Dependency
54
- name: htmlbeautifier
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '1.4'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 1.4.2
39
+ version: '0.121'
63
40
  type: :runtime
64
41
  prerelease: false
65
42
  version_requirements: !ruby/object:Gem::Requirement
66
43
  requirements:
67
44
  - - "~>"
68
45
  - !ruby/object:Gem::Version
69
- version: '1.4'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 1.4.2
46
+ version: '0.121'
73
47
  - !ruby/object:Gem::Dependency
74
48
  name: rails
75
49
  requirement: !ruby/object:Gem::Requirement
76
50
  requirements:
77
51
  - - ">="
78
52
  - !ruby/object:Gem::Version
79
- version: 4.2.11
53
+ version: 5.2.8.1
80
54
  type: :runtime
81
55
  prerelease: false
82
56
  version_requirements: !ruby/object:Gem::Requirement
83
57
  requirements:
84
58
  - - ">="
85
59
  - !ruby/object:Gem::Version
86
- version: 4.2.11
60
+ version: 5.2.8.1
87
61
  - !ruby/object:Gem::Dependency
88
62
  name: virtus
89
63
  requirement: !ruby/object:Gem::Requirement
@@ -124,20 +98,14 @@ dependencies:
124
98
  requirements:
125
99
  - - "~>"
126
100
  - !ruby/object:Gem::Version
127
- version: '0.4'
128
- - - ">="
129
- - !ruby/object:Gem::Version
130
- version: 0.4.1
101
+ version: '0.10'
131
102
  type: :development
132
103
  prerelease: false
133
104
  version_requirements: !ruby/object:Gem::Requirement
134
105
  requirements:
135
106
  - - "~>"
136
107
  - !ruby/object:Gem::Version
137
- version: '0.4'
138
- - - ">="
139
- - !ruby/object:Gem::Version
140
- version: 0.4.1
108
+ version: '0.10'
141
109
  description:
142
110
  email:
143
111
  executables: []
@@ -193,6 +161,7 @@ files:
193
161
  - app/validators/eac_rails_utils/cpf_validator.rb
194
162
  - app/validators/eac_rails_utils/immutable_validator.rb
195
163
  - app/validators/eac_rails_utils/no_presence_validator.rb
164
+ - app/validators/eac_rails_utils/uri_validator.rb
196
165
  - app/validators/eac_rails_utils/yaml_validator.rb
197
166
  - config/initializers/assets.rb
198
167
  - config/initializers/json.rb
@@ -204,7 +173,6 @@ files:
204
173
  - lib/eac_rails_utils.rb
205
174
  - lib/eac_rails_utils/engine.rb
206
175
  - lib/eac_rails_utils/engine_helper.rb
207
- - lib/eac_rails_utils/htmlbeautifier.rb
208
176
  - lib/eac_rails_utils/menus.rb
209
177
  - lib/eac_rails_utils/menus/action.rb
210
178
  - lib/eac_rails_utils/menus/group.rb
@@ -254,7 +222,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
254
222
  requirements:
255
223
  - - ">="
256
224
  - !ruby/object:Gem::Version
257
- version: '0'
225
+ version: '2.7'
258
226
  required_rubygems_version: !ruby/object:Gem::Requirement
259
227
  requirements:
260
228
  - - ">="
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'htmlbeautifier'
4
-
5
- module EacRailsUtils
6
- class Htmlbeautifier
7
- def self.beautify(string)
8
- ::HtmlBeautifier.beautify(string, tab_stops: 2) + "\n"
9
- end
10
-
11
- def self.file_beautified?(file)
12
- input = File.read(file)
13
- input == beautify(input)
14
- end
15
-
16
- def self.beautify_file(file)
17
- input = File.read(file)
18
- output = beautify(input)
19
- if input == output
20
- false
21
- else
22
- File.write(file, output)
23
- true
24
- end
25
- end
26
- end
27
- end