eac_rails_utils 0.10.1 → 0.11.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper.rb +5 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder.rb +10 -2
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/association_select_field.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/common_text_fields.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/currency_field.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/date_field.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/fields_for.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/file_field.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/radio_select_field.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/searchable_association_field.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/select_field.rb +3 -2
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/time_field.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/common_form_helper/form_builder/year_month_field.rb +1 -1
- data/app/helpers/eac_rails_utils/data_table_helper.rb +13 -0
- data/{lib/eac → app/helpers/eac_rails_utils}/data_table_helper/column.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/data_table_helper/data_table.rb +2 -2
- data/{lib/eac → app/helpers/eac_rails_utils}/data_table_helper/setup.rb +2 -2
- data/app/helpers/eac_rails_utils/links_helper.rb +5 -5
- data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper.rb +5 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper/bootstrap_gui_builder.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper/data_builder.rb +1 -1
- data/{lib/eac → app/helpers/eac_rails_utils}/menus_helper/gui_builder.rb +1 -1
- data/{lib/eac → app/validators/eac_rails_utils}/cpf_validator.rb +1 -1
- data/{lib/eac → app/validators/eac_rails_utils}/no_presence_validator.rb +1 -1
- data/config/locales/en.yml +8 -0
- data/config/locales/pt-BR.yml +8 -0
- data/lib/eac_rails_utils.rb +2 -39
- data/lib/eac_rails_utils/engine.rb +2 -0
- data/lib/{eac → eac_rails_utils}/htmlbeautifier.rb +1 -1
- data/lib/eac_rails_utils/models.rb +9 -0
- data/lib/eac_rails_utils/models/attribute_required.rb +43 -0
- data/lib/eac_rails_utils/models/fetch_errors.rb +92 -0
- data/lib/eac_rails_utils/models/inequality_queries.rb +39 -0
- data/lib/eac_rails_utils/models/tableless.rb +97 -0
- data/lib/eac_rails_utils/models/test_utils.rb +65 -0
- data/lib/eac_rails_utils/patches.rb +9 -0
- data/lib/eac_rails_utils/patches/action_controller_base.rb +2 -0
- 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/app/models/user.rb +4 -0
- data/test/dummy/config/application.rb +1 -1
- data/test/{lib/eac → helpers/eac_rails_utils}/common_form_helper_test.rb +2 -2
- data/test/{lib/eac → helpers/eac_rails_utils}/data_table_test_helper_test.rb +2 -2
- data/test/{app/helpers → helpers}/eac_rails_utils/formatter_helper_test.rb +0 -0
- data/test/lib/eac_rails_utils/{patches/model_attribute_required_test.rb → models/attribute_required_test.rb} +1 -0
- data/test/lib/eac_rails_utils/models/fetch_errors_test.rb +80 -0
- data/test/lib/eac_rails_utils/models/tableless_test.rb +25 -0
- data/test/{lib/eac → validators}/cpf_validator_test.rb +2 -2
- metadata +69 -66
- data/lib/eac/data_table_helper.rb +0 -13
- data/lib/eac/inequality_queries.rb +0 -37
- data/lib/eac/model.rb +0 -90
- data/lib/eac/test_utils.rb +0 -61
- data/lib/eac_rails_utils/patches/model_attribute_required.rb +0 -34
- data/lib/eac_rails_utils/patches/ofx_parser.rb +0 -43
- data/lib/eac_rails_utils/tableless_model.rb +0 -92
- data/test/lib/eac/model_test.rb +0 -78
- data/test/lib/eac/source_target_fixtures_test_files/a.source.html +0 -1
- data/test/lib/eac/source_target_fixtures_test_files/a.target.yaml +0 -1
- data/test/lib/eac/source_target_fixtures_test_files/b.source.html +0 -1
- data/test/lib/eac/source_target_fixtures_test_files/c.target.yaml +0 -1
- data/test/lib/eac_rails_utils/tableless_model_test.rb +0 -23
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_record'
|
4
|
-
|
5
|
-
module EacRailsUtils
|
6
|
-
module Patches
|
7
|
-
module ModelAttributeRequired
|
8
|
-
def self.included(base)
|
9
|
-
base.extend ClassMethods
|
10
|
-
base.include InstanceMethods
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
def column_required?(column)
|
15
|
-
m = new
|
16
|
-
m.validate
|
17
|
-
m.errors.key?(column.to_sym)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module InstanceMethods
|
22
|
-
def attribute_required?(column)
|
23
|
-
self.class.column_required?(column)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
[::ActiveRecord::Base, ::ActiveModel::Model].each do |c|
|
31
|
-
next if c.included_modules.include? ::EacRailsUtils::Patches::ModelAttributeRequired
|
32
|
-
|
33
|
-
c.include ::EacRailsUtils::Patches::ModelAttributeRequired
|
34
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'ofx-parser'
|
4
|
-
|
5
|
-
module EacRailsUtils
|
6
|
-
module Patches
|
7
|
-
module OfxParser
|
8
|
-
module OfxParser
|
9
|
-
def self.included(base)
|
10
|
-
base.class_eval do
|
11
|
-
class << self
|
12
|
-
prepend ClassMethods
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
module ClassMethods
|
18
|
-
def build_transaction(transaction)
|
19
|
-
r = super
|
20
|
-
r.currate = (transaction / 'CURRENCY/CURRATE').inner_text
|
21
|
-
r
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
module Transaction
|
27
|
-
attr_accessor :currate, :cursym
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
unless ::OfxParser::OfxParser.included_modules.include?(
|
34
|
-
::EacRailsUtils::Patches::OfxParser::OfxParser
|
35
|
-
)
|
36
|
-
::OfxParser::OfxParser.include ::EacRailsUtils::Patches::OfxParser::OfxParser
|
37
|
-
end
|
38
|
-
|
39
|
-
unless ::OfxParser::Transaction.included_modules.include?(
|
40
|
-
::EacRailsUtils::Patches::OfxParser::Transaction
|
41
|
-
)
|
42
|
-
::OfxParser::Transaction.include ::EacRailsUtils::Patches::OfxParser::Transaction
|
43
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EacRailsUtils
|
4
|
-
class TablelessModel
|
5
|
-
include ActiveModel::Model
|
6
|
-
include Virtus.model
|
7
|
-
include ActiveModel::Associations
|
8
|
-
|
9
|
-
def initialize(values = {})
|
10
|
-
super(build_attributes(values))
|
11
|
-
end
|
12
|
-
|
13
|
-
def attributes=(values)
|
14
|
-
super(build_attributes(values))
|
15
|
-
end
|
16
|
-
|
17
|
-
# need hash like accessor, used internal Rails
|
18
|
-
def [](attr)
|
19
|
-
send(attr)
|
20
|
-
end
|
21
|
-
|
22
|
-
# need hash like accessor, used internal Rails
|
23
|
-
def []=(attr, value)
|
24
|
-
send("#{attr}=", value)
|
25
|
-
end
|
26
|
-
|
27
|
-
def save!
|
28
|
-
save || raise("#{self.class}.save failed: #{errors.messages}")
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def build_attributes(values)
|
34
|
-
AttributesBuilder.new(self.class, values).to_attributes
|
35
|
-
end
|
36
|
-
|
37
|
-
class AttributesBuilder
|
38
|
-
DATE_TIME_FIELDS = %i[year month day hour min sec].freeze
|
39
|
-
|
40
|
-
def initialize(model_class, values)
|
41
|
-
@model_class = model_class
|
42
|
-
@values = {}
|
43
|
-
values.each { |k, v| add(k, v) }
|
44
|
-
end
|
45
|
-
|
46
|
-
def to_attributes
|
47
|
-
@values
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def add(key, value)
|
53
|
-
array_attr = parse_array_attr_key(key)
|
54
|
-
if array_attr
|
55
|
-
array_value_set(array_attr, value)
|
56
|
-
else
|
57
|
-
@values[key] = value
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def parse_array_attr_key(key)
|
62
|
-
m = /\A(.+)\(([0-9]+)(.)\)\z/.match(key)
|
63
|
-
return unless m
|
64
|
-
|
65
|
-
::OpenStruct.new(key: m[1], index: m[2].to_i - 1, converter: array_value_converter(m[3]))
|
66
|
-
end
|
67
|
-
|
68
|
-
def array_value_set(array_attr, value)
|
69
|
-
@values[array_attr.key] ||= {}
|
70
|
-
@values[array_attr.key].merge!(
|
71
|
-
DATE_TIME_FIELDS[array_attr.index] => value.send(array_attr.converter)
|
72
|
-
)
|
73
|
-
end
|
74
|
-
|
75
|
-
def array_value_converter(str_type)
|
76
|
-
case str_type
|
77
|
-
when 'i'
|
78
|
-
'to_i'
|
79
|
-
else
|
80
|
-
raise "Unknown array type: \"#{str_type}\""
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def date_time_attribute?(key)
|
85
|
-
attr = @model_class.attributes[key]
|
86
|
-
return false unless attr
|
87
|
-
|
88
|
-
raise attr.to_s
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
data/test/lib/eac/model_test.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
module Eac
|
6
|
-
class ModelTest < ActiveSupport::TestCase
|
7
|
-
class M1
|
8
|
-
include ActiveModel::Model
|
9
|
-
include Eac::Model
|
10
|
-
attr_accessor :name, :age, :account, :country_id, :other
|
11
|
-
end
|
12
|
-
|
13
|
-
class M2
|
14
|
-
include ActiveModel::Model
|
15
|
-
attr_accessor :name, :myage, :account_id, :country
|
16
|
-
|
17
|
-
validate :my_validate
|
18
|
-
|
19
|
-
def my_validate
|
20
|
-
errors.add(:name, 'NAME_ERROR')
|
21
|
-
errors.add(:myage, 'MYAGE_ERROR')
|
22
|
-
errors.add(:account_id, 'ACCOUNT_ID_ERROR')
|
23
|
-
errors.add(:country, 'COUNTRY_ERROR')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def setup
|
28
|
-
reset_m1
|
29
|
-
reset_m2
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_fetch_column_errors
|
33
|
-
@m1.fetch_column_errors(@m2, :myage, :age)
|
34
|
-
assert_equal @m2.errors[:myage], @m1.errors[:age]
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_fetch_record_errors
|
38
|
-
@m1.fetch_record_errors(@m2)
|
39
|
-
{ name: :name, account_id: :account, country: :country_id }.each do |c2, c1|
|
40
|
-
assert_equal @m2.errors[c2], @m1.errors[c1], "c2: #{c2}, c1: #{c1}"
|
41
|
-
end
|
42
|
-
assert @m1.errors[:age].empty?
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_fetch_record_errors_with_default_column
|
46
|
-
@m1.fetch_record_errors(@m2, default_column: :other)
|
47
|
-
assert_equal @m2.errors[:name], @m1.errors[:name]
|
48
|
-
assert @m1.errors[:age].empty?
|
49
|
-
assert_equal ['Myage: MYAGE_ERROR'], @m1.errors[:other]
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_fetch_record_errors_with_skip_option
|
53
|
-
@m1.fetch_record_errors(@m2, skip: [:name])
|
54
|
-
assert @m1.errors[:name].empty?
|
55
|
-
assert @m1.errors[:age].empty?
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_fetch_record_errors_by_mapping
|
59
|
-
@m1.fetch_record_errors_by_mapping(@m2, name: :name, myage: :age)
|
60
|
-
assert_equal @m2.errors[:name], @m1.errors[:name]
|
61
|
-
assert_equal @m2.errors[:myage], @m1.errors[:age]
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
def reset_m1
|
67
|
-
@m1 = M1.new
|
68
|
-
assert @m1.errors.empty?
|
69
|
-
end
|
70
|
-
|
71
|
-
def reset_m2
|
72
|
-
@m2 = M2.new
|
73
|
-
assert_not @m2.valid?
|
74
|
-
assert_not @m2.errors[:name].empty?
|
75
|
-
assert_not @m2.errors[:myage].empty?
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
module EacRailsUtils
|
6
|
-
class TablelessModelTest < ActiveSupport::TestCase
|
7
|
-
class Stub < ::EacRailsUtils::TablelessModel
|
8
|
-
attribute :tempo, DateTime
|
9
|
-
end
|
10
|
-
|
11
|
-
test 'date time array values' do
|
12
|
-
stub = Stub.new('tempo(1i)' => '9', 'tempo(2i)' => '10', 'tempo(3i)' => '11',
|
13
|
-
'tempo(4i)' => '12', 'tempo(5i)' => '13', 'tempo(6i)' => '14')
|
14
|
-
assert stub.tempo.is_a?(DateTime), "Class: |#{stub.tempo.class}|, Value: |#{stub.tempo}|"
|
15
|
-
assert_equal 9, stub.tempo.year, 'Year'
|
16
|
-
assert_equal 10, stub.tempo.month, 'Month'
|
17
|
-
assert_equal 11, stub.tempo.day, 'Day'
|
18
|
-
assert_equal 12, stub.tempo.hour, 'Hour'
|
19
|
-
assert_equal 13, stub.tempo.minute, 'Minute'
|
20
|
-
assert_equal 14, stub.tempo.second, 'Second'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|