eac_rails_utils 0.0.1 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83531ca45814c757bf6ecb89e2142cc1db74fc8a
4
- data.tar.gz: 39a55f7c96408f0a0b74a8623007d00758c50874
3
+ metadata.gz: 19ccc8fc5f3f8b878422a8327af8faaa61e98075
4
+ data.tar.gz: f8081169339acbf890d7a9c981ed561cfacb5474
5
5
  SHA512:
6
- metadata.gz: f127ef8d3d6616c4031a9e7afe1b27b260f2ef84eafe76d00eaef38382ef864b73b6aeb6ca9ff80648700a64ff946b6ff38c36012b189b7e1239e6dd11fccbd9
7
- data.tar.gz: 8b408f5083e55480c1febb2b6377dc36d24964749cb4b2d05ac878f8c13babd7c341f078d2792e1f961549575f8b449874941821e622d0cfb3a99bad148a3db8
6
+ metadata.gz: b43a7c8a372dd670a2ad9ff13c66905859d3f2f367845f65faf52d76a548512c6589946572bc7f1ab3ea86880f4ccb4cc95d5d447f3981e7255c334212ca51eb
7
+ data.tar.gz: a28be360f63ca74287b1756263c05f638e76903d636e136547ca55997675a8ae6ca25b1e2cf921107a77ea280f05508e72bb3615637e433c81251440bc4b3c76
@@ -75,4 +75,4 @@ InputSearchable.prototype._setValue = function (item) {
75
75
  this._selectedItem = null;
76
76
  }
77
77
  this._applyColor();
78
- };
78
+ };
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Eac
2
3
  module CommonFormHelper
3
4
  class FormBuilder
@@ -7,6 +8,7 @@ module Eac
7
8
  include DateField
8
9
  include RadioSelectField
9
10
  include FieldsFor
11
+ include YearMonthField
10
12
 
11
13
  attr_reader :form, :helper, :field_errors_showed
12
14
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Eac
2
3
  module CommonFormHelper
3
4
  class FormBuilder
@@ -6,8 +7,10 @@ module Eac
6
7
  class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
7
8
  def #{t}_field(field_name, options = {}) # def text_field(field_name, options = {})
8
9
  field(field_name, options) do # field(field_name, options) do
10
+ input_options = options[:input_options] || {}
11
+ input_options[:class] ||= 'form-control'
9
12
  @form.#{t}_field(field_name, # @form.text_field(field_name,
10
- class: 'form-control') # class: 'form-control')
13
+ input_options) # class: 'form-control')
11
14
  end # end
12
15
  end # end
13
16
  RUBY_EVAL
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ module Eac
3
+ module CommonFormHelper
4
+ class FormBuilder
5
+ module YearMonthField
6
+ def year_month_field(field_name, options = {})
7
+ field(field_name, options) do
8
+ month_field(field_name) << ' / ' << year_field(field_name,
9
+ options[:years] || default_years)
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def year_field(field_name, years)
16
+ form.select("#{field_name}_year", years.map { |y| [y, y] })
17
+ end
18
+
19
+ def month_field(field_name)
20
+ form.select("#{field_name}_month", (1..12).map { |y| [y.to_s.rjust(2, '0'), y] })
21
+ end
22
+
23
+ def default_years
24
+ current_year = Time.zone.now.year
25
+ ((current_year - 5)..current_year)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ module Eac
3
+ # == Example:
4
+ #
5
+ # Note: model Product has a attribute "foo" Date, Time or Number:
6
+ #
7
+ # class Product
8
+ # include ::Eac::InequalityQueries
9
+ #
10
+ # add_inequality_queries(:foo)
11
+ # end
12
+ #
13
+ # This add the following scopes:
14
+ #
15
+ # Product.by_foo_gt(value) # Equivalent to Product.where("foo > ?", value)
16
+ # Product.by_foo_gteq(value) # Equivalent to Product.where("foo >= ?", value)
17
+ # Product.by_foo_lt(value) # Equivalent to Product.where("foo < ?", value)
18
+ # Product.by_foo_lteq(value) # Equivalent to Product.where("foo <= ?", value)
19
+ module InequalityQueries
20
+ class << self
21
+ def included(base)
22
+ base.extend(ClassMethods)
23
+ end
24
+ end
25
+
26
+ module ClassMethods
27
+ def add_inequality_queries(attribute)
28
+ %w(gt gteq lt lteq).each do |ineq|
29
+ scope "by_#{attribute}_#{ineq}", lambda { |v|
30
+ where(arel_table[attribute].send(ineq, v))
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,223 @@
1
+ # frozen_string_literal: true
2
+ module Eac
3
+ module Listable
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ extend(::Eac::Listable::ClassMethods)
8
+ include(::Eac::Listable::InstanceMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ def lists
13
+ @lists ||= ::Eac::Listable::Lists.new(self)
14
+ end
15
+ end
16
+
17
+ module InstanceMethods
18
+ LISTABLE_INSTANCE_VALUE_METHODS = %w(label description).freeze
19
+
20
+ def method_missing(name, *args, &block)
21
+ list, method = parse_method(name)
22
+ list && method ? list.instance_value(self).send(method) : super
23
+ end
24
+
25
+ def respond_to?(name, include_all = false)
26
+ list, method = parse_method(name)
27
+ list && method ? true : super
28
+ end
29
+
30
+ private
31
+
32
+ def parse_method(method)
33
+ self.class.lists.acts_as_listable_items.each do |item, list|
34
+ LISTABLE_INSTANCE_VALUE_METHODS.each do |m|
35
+ return [list, m] if method.to_s == "#{item}_#{m}"
36
+ end
37
+ end
38
+ [nil, nil]
39
+ end
40
+ end
41
+
42
+ class Lists
43
+ attr_reader :source
44
+
45
+ def initialize(source)
46
+ @source = source
47
+ end
48
+
49
+ def add_integer(item, *labels)
50
+ check_acts_as_listable_new_item(item)
51
+ acts_as_listable_items[item] = ::Eac::Listable::IntegerList.new(
52
+ self, item, labels
53
+ )
54
+ end
55
+
56
+ def add_string(item, *labels)
57
+ check_acts_as_listable_new_item(item)
58
+ acts_as_listable_items[item] = ::Eac::Listable::StringList.new(
59
+ self, item, labels
60
+ )
61
+ end
62
+
63
+ def method_missing(name, *args, &block)
64
+ list = find_list_by_method(name)
65
+ list ? list : super
66
+ end
67
+
68
+ def respond_to?(name, include_all = false)
69
+ find_list_by_method(name) || super
70
+ end
71
+
72
+ def acts_as_listable_items
73
+ @acts_as_listable_items ||= ActiveSupport::HashWithIndifferentAccess.new
74
+ end
75
+
76
+ private
77
+
78
+ def check_acts_as_listable_new_item(item)
79
+ return unless acts_as_listable_items.key?(item)
80
+ raise "Item já adicionado anteriormente: #{item} em #{self} " \
81
+ "(#{acts_as_listable_items.keys})"
82
+ end
83
+
84
+ def find_list_by_method(method)
85
+ acts_as_listable_items.each do |item, list|
86
+ return list if method.to_sym == item.to_sym
87
+ end
88
+ nil
89
+ end
90
+ end
91
+
92
+ class List
93
+ attr_reader :item
94
+
95
+ def initialize(lists, item, labels)
96
+ @lists = lists
97
+ @item = item
98
+ @values = build_values(labels)
99
+ apply_constants
100
+ end
101
+
102
+ def values
103
+ @values.values.map(&:value)
104
+ end
105
+
106
+ def options
107
+ @values.values.map { |v| [v.label, v.value] }
108
+ end
109
+
110
+ def method_missing(name, *args, &block)
111
+ list = find_list_by_method(name)
112
+ list ? list : super
113
+ end
114
+
115
+ def respond_to?(name, include_all = false)
116
+ find_list_by_method(name) || super
117
+ end
118
+
119
+ def i18n_key
120
+ "eac.listable.#{class_i18n_key}.#{item}"
121
+ end
122
+
123
+ def instance_value(instance)
124
+ v = instance.send(item)
125
+ return @values[v] if @values.key?(v)
126
+ raise "List value unkown: #{v} (Source: #{@lists.source}, Item: #{item})"
127
+ end
128
+
129
+ private
130
+
131
+ def class_i18n_key
132
+ @lists.source.name.underscore.to_sym
133
+ end
134
+
135
+ def find_list_by_method(method)
136
+ @values.values.each do |v|
137
+ return v if method.to_s == "value_#{v.key}"
138
+ end
139
+ nil
140
+ end
141
+
142
+ def constants
143
+ labels.each_with_index.map { |v, i| ["#{item.upcase}_#{v.upcase}", values[i]] }
144
+ end
145
+
146
+ def apply_constants
147
+ @values.values.each do |v|
148
+ @lists.source.const_set(v.constant_name, v.value)
149
+ end
150
+ end
151
+
152
+ def build_values(labels)
153
+ vs = {}
154
+ parse_labels(labels).each do |value, key|
155
+ v = Value.new(self, value, key)
156
+ vs[v.value] = v
157
+ end
158
+ vs
159
+ end
160
+ end
161
+
162
+ class Value
163
+ attr_reader :value, :key
164
+
165
+ def initialize(list, value, key)
166
+ @list = list
167
+ @value = value
168
+ @key = key
169
+ end
170
+
171
+ def to_s
172
+ "I: #{@list.item}, V: #{@value}, K: #{@key}"
173
+ end
174
+
175
+ def constant_name
176
+ "#{@list.item}_#{@key}".gsub(/[^a-z0-9_]/, '_').gsub(/_+/, '_')
177
+ .gsub(/(?:\A_|_\z)/, '').upcase
178
+ end
179
+
180
+ def label
181
+ translate('label')
182
+ end
183
+
184
+ def description
185
+ translate('description')
186
+ end
187
+
188
+ private
189
+
190
+ def translate(translate_key)
191
+ ::I18n.t("#{@list.i18n_key}.#{@key}.#{translate_key}")
192
+ end
193
+ end
194
+
195
+ class IntegerList < ::Eac::Listable::List
196
+ protected
197
+
198
+ def parse_labels(labels)
199
+ if labels.first.is_a?(Hash)
200
+ Hash[labels.first.map { |k, v| [k.to_i, v.to_s] }]
201
+ else
202
+ Hash[labels.each_with_index.map { |v, i| [i + 1, v.to_s] }]
203
+ end
204
+ end
205
+
206
+ def build_value(index, _key)
207
+ index + 1
208
+ end
209
+ end
210
+
211
+ class StringList < ::Eac::Listable::List
212
+ protected
213
+
214
+ def parse_labels(labels)
215
+ if labels.first.is_a?(Hash)
216
+ Hash[labels.first.map { |k, v| [k.to_s, v.to_s] }]
217
+ else
218
+ Hash[labels.map { |v| [v.to_s, v.to_s] }]
219
+ end
220
+ end
221
+ end
222
+ end
223
+ end
@@ -0,0 +1,12 @@
1
+
2
+
3
+ # frozen_string_literal: true
4
+ module Eac
5
+ # https://stackoverflow.com/questions/10070786/rails-3-validation-presence-false
6
+ class NoPresenceValidator < ActiveModel::EachValidator
7
+ def validate_each(record, attribute, _value)
8
+ return if record.send(attribute).blank?
9
+ record.errors[attribute] << (options[:message] || 'must be blank')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,64 @@
1
+ # ecoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'open-uri'
5
+ require 'fileutils'
6
+
7
+ module Eac
8
+ module Parsers
9
+ class Base
10
+ def initialize(url)
11
+ @url = url
12
+ end
13
+
14
+ def url
15
+ @url.gsub(%r{/+$}, '')
16
+ end
17
+
18
+ def content
19
+ s = content_by_url_type
20
+ log_content(s)
21
+ s
22
+ end
23
+
24
+ private
25
+
26
+ def content_by_url_type
27
+ if @url.is_a?(Hash)
28
+ content_hash
29
+ elsif /^http/ =~ @url
30
+ content_get
31
+ else
32
+ content_file
33
+ end
34
+ end
35
+
36
+ def content_file
37
+ open(@url, &:read)
38
+ end
39
+
40
+ def content_get
41
+ HTTPClient.new.get_content(@url, follow_redirect: true)
42
+ end
43
+
44
+ def content_hash
45
+ return content_post if @url[:method] == :post
46
+ raise "Unknown URL format: #{@url}"
47
+ end
48
+
49
+ def content_post
50
+ HTTPClient.new.post_content(@url[:url], @url[:params].merge(follow_redirect: true))
51
+ end
52
+
53
+ def log_content(s)
54
+ File.open(log_file, 'wb') { |file| file.write(s) }
55
+ end
56
+
57
+ def log_file
58
+ f = Rails.root.join('log', 'parsers', "#{self.class.name.parameterize}.log")
59
+ FileUtils.mkdir_p(File.dirname(f))
60
+ f
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+
4
+ module Eac
5
+ module Parsers
6
+ module FilesTest
7
+ def test_data
8
+ source_target_fixtures.source_target_files do |source_file, target_file|
9
+ sd = parser_class.new(source_file).data
10
+ td = YAML.load_file(target_file)
11
+ assert_equal sort_results(td), sort_results(sd)
12
+ end
13
+ end
14
+
15
+ protected
16
+
17
+ def sort_results(r)
18
+ r
19
+ end
20
+
21
+ private
22
+
23
+ def source_target_fixtures
24
+ ::Eac::SourceTargetFixtures.new(
25
+ File.expand_path("../#{self.class.name.demodulize.underscore}_files", test_file)
26
+ )
27
+ end
28
+
29
+ def parser_class
30
+ self.class.name.gsub(/Test\z/, '').constantize
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ module Eac
3
+ module Parsers
4
+ class Ofx < ::Eac::Parsers::Base
5
+ def ofx
6
+ @ofx ||= ofx_parse
7
+ end
8
+
9
+ def assert_ofx
10
+ fail "Not a OFX: #{url}" unless ofx.bank_account || ofx.credit_card ||
11
+ ofx.investment
12
+ end
13
+
14
+ def ofx?
15
+ ofx.present?
16
+ end
17
+
18
+ private
19
+
20
+ def ofx_parse
21
+ s = content.force_encoding('iso-8859-1').encode('utf-8').gsub(/(?<!\r)\n/, "\r\n")
22
+ begin
23
+ ::OfxParser::OfxParser.parse(s)
24
+ rescue NoMethodError, ArgumentError
25
+ nil
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -37,7 +37,7 @@ module Eac
37
37
  end
38
38
 
39
39
  def sources_targets_basenames
40
- basenames = []
40
+ basenames = Set.new
41
41
  Dir.foreach(fixtures_directory) do |item|
42
42
  next if item == '.' || item == '..'
43
43
  if /^(.+)\.(?:source|target)(?:\..+)?$/ =~ File.basename(item)
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ module Eac
3
+ class TablelessModel
4
+ include ActiveModel::Model
5
+ include Virtus.model
6
+ include ActiveModel::Associations
7
+
8
+ # need hash like accessor, used internal Rails
9
+ def [](attr)
10
+ send(attr)
11
+ end
12
+
13
+ # need hash like accessor, used internal Rails
14
+ def []=(attr, value)
15
+ send("#{attr}=", value)
16
+ end
17
+
18
+ def save!
19
+ save || raise("#{self.class}.save failed: #{errors.messages}")
20
+ end
21
+ end
22
+ end
@@ -1,7 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  module EacRailsUtils
3
+ require 'activemodel/associations'
2
4
  require 'nested_form_fields'
5
+ require 'ofx-parser'
6
+ require 'virtus'
3
7
 
4
8
  require 'eac_rails_utils/patches/model_attribute_required'
9
+ require 'eac_rails_utils/patches/ofx_parser'
5
10
  require 'eac_rails_utils/rails/engine'
6
11
  require 'eac/cpf_validator'
7
12
  require 'eac/formatter_helper'
@@ -12,16 +17,24 @@ module EacRailsUtils
12
17
  require 'eac/common_form_helper/form_builder/fields_for'
13
18
  require 'eac/common_form_helper/form_builder/radio_select_field'
14
19
  require 'eac/common_form_helper/form_builder/searchable_association_field'
20
+ require 'eac/common_form_helper/form_builder/year_month_field'
15
21
  require 'eac/common_form_helper/form_builder'
16
22
  require 'eac/common_form_helper'
17
23
  require 'eac/htmlbeautifier'
24
+ require 'eac/inequality_queries'
25
+ require 'eac/listable'
18
26
  require 'eac/menus_helper'
19
27
  require 'eac/menus_helper/bootstrap_gui_builder'
20
28
  require 'eac/menus_helper/data_builder'
21
29
  require 'eac/menus_helper/gui_builder'
22
30
  require 'eac/model'
31
+ require 'eac/no_presence_validator'
32
+ require 'eac/parsers/base'
33
+ require 'eac/parsers/files_test'
34
+ require 'eac/parsers/ofx'
23
35
  require 'eac/simple_cache'
24
36
  require 'eac/source_target_fixtures'
37
+ require 'eac/tableless_model'
25
38
 
26
39
  ActionView::Base.send :include, Eac::CommonFormHelper
27
40
  ActionView::Base.send :include, Eac::FormatterHelper
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ require 'ofx-parser'
3
+
4
+ module EacRailsUtils
5
+ module Patches
6
+ module OfxParser
7
+ module OfxParser
8
+ def self.included(base)
9
+ base.class_eval do
10
+ class << self
11
+ prepend ClassMethods
12
+ end
13
+ end
14
+ end
15
+
16
+ module ClassMethods
17
+ def build_transaction(t)
18
+ r = super
19
+ r.currate = (t / 'CURRENCY/CURRATE').inner_text
20
+ r
21
+ end
22
+ end
23
+ end
24
+
25
+ module Transaction
26
+ attr_accessor :currate, :cursym
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ unless ::OfxParser::OfxParser.included_modules.include?(
33
+ ::EacRailsUtils::Patches::OfxParser::OfxParser
34
+ )
35
+ ::OfxParser::OfxParser.send(:include, ::EacRailsUtils::Patches::OfxParser::OfxParser)
36
+ end
37
+
38
+ unless ::OfxParser::Transaction.included_modules.include?(
39
+ ::EacRailsUtils::Patches::OfxParser::Transaction
40
+ )
41
+ ::OfxParser::Transaction.send(:include, ::EacRailsUtils::Patches::OfxParser::Transaction)
42
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module EacRailsUtils
2
- VERSION = '0.0.1'
3
+ VERSION = '0.1.10'
3
4
  end
@@ -0,0 +1,38 @@
1
+ pt-BR:
2
+ eac:
3
+ listable:
4
+ eac/listable_test/stub:
5
+ inteiro:
6
+ a:
7
+ label: Inteiro A
8
+ description: Inteiro A Descr.
9
+ b:
10
+ label: Inteiro BB
11
+ description: Inteiro BB Descr.
12
+ c:
13
+ label: Inteiro CCC
14
+ description: Inteiro CCC Descr.
15
+ cadeia:
16
+ a:
17
+ label: Cadeia AAA
18
+ description: Cadeia AAA Descr.
19
+ b:
20
+ label: Cadeia BB
21
+ description: Cadeia BB Descr.
22
+ c:
23
+ label: Cadeia C
24
+ description: Cadeia C Descr.
25
+ code:
26
+ a:
27
+ label: Código A
28
+ description: Código A Descr.
29
+ b:
30
+ label: Código B
31
+ description: Código B Descr.
32
+ type:
33
+ a:
34
+ label: Tipo A
35
+ description: Tipo A Descr.
36
+ b:
37
+ label: Tipo B
38
+ description: Tipo B Descr.
@@ -0,0 +1,138 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+ require 'test_helper'
4
+
5
+ module Eac
6
+ class ListableTest < ActiveSupport::TestCase
7
+ class Stub
8
+ include ::Eac::Listable
9
+
10
+ attr_accessor :inteiro, :code, :cadeia, :type
11
+
12
+ lists.add_integer :inteiro, :a, :b, :c
13
+ lists.add_integer :code, 7 => :a, 13 => :b
14
+ lists.add_string :cadeia, :a, :b, :c
15
+ lists.add_string :type, 'Namespace::ClazzA' => :a, 'Namespace::ClazzB' => :b
16
+ end
17
+
18
+ setup do
19
+ I18n.locale = 'pt-BR'
20
+ end
21
+
22
+ test 'attribute values' do
23
+ assert_equal [1, 2, 3], Stub.lists.inteiro.values
24
+ assert_equal [7, 13], Stub.lists.code.values
25
+ assert_equal %w(a b c), Stub.lists.cadeia.values
26
+ assert_equal %w(Namespace::ClazzA Namespace::ClazzB), Stub.lists.type.values
27
+ end
28
+
29
+ test 'value instance options' do
30
+ assert_equal [['Inteiro A', 1], ['Inteiro BB', 2], ['Inteiro CCC', 3]],
31
+ Stub.lists.inteiro.options
32
+ assert_equal [['Código A', 7], ['Código B', 13]], Stub.lists.code.options
33
+ assert_equal [['Cadeia AAA', 'a'], ['Cadeia BB', 'b'], ['Cadeia C', 'c']],
34
+ Stub.lists.cadeia.options
35
+ assert_equal [['Tipo A', 'Namespace::ClazzA'], ['Tipo B', 'Namespace::ClazzB']], Stub.lists.type.options
36
+ end
37
+
38
+ test 'constants' do
39
+ assert_equal 1, Stub::INTEIRO_A
40
+ assert_equal 2, Stub::INTEIRO_B
41
+ assert_equal 3, Stub::INTEIRO_C
42
+ assert_equal 7, Stub::CODE_A
43
+ assert_equal 13, Stub::CODE_B
44
+ assert_equal 'a', Stub::CADEIA_A
45
+ assert_equal 'b', Stub::CADEIA_B
46
+ assert_equal 'c', Stub::CADEIA_C
47
+ assert_equal 'Namespace::ClazzA', Stub::TYPE_A
48
+ assert_equal 'Namespace::ClazzB', Stub::TYPE_B
49
+ end
50
+
51
+ test 'values instances' do
52
+ assert Stub.lists.is_a?(::Eac::Listable::Lists)
53
+ assert Stub.lists.inteiro.value_a.is_a?(::Eac::Listable::Value)
54
+ assert Stub.lists.inteiro.value_b.is_a?(::Eac::Listable::Value)
55
+ assert Stub.lists.inteiro.value_c.is_a?(::Eac::Listable::Value)
56
+ assert Stub.lists.code.value_a.is_a?(::Eac::Listable::Value)
57
+ assert Stub.lists.code.value_b.is_a?(::Eac::Listable::Value)
58
+ assert Stub.lists.cadeia.value_a.is_a?(::Eac::Listable::Value)
59
+ assert Stub.lists.cadeia.value_b.is_a?(::Eac::Listable::Value)
60
+ assert Stub.lists.cadeia.value_c.is_a?(::Eac::Listable::Value)
61
+ assert Stub.lists.type.value_a.is_a?(::Eac::Listable::Value)
62
+ assert Stub.lists.type.value_b.is_a?(::Eac::Listable::Value)
63
+ end
64
+
65
+ test 'value instance label' do
66
+ assert_equal 'Inteiro A', Stub.lists.inteiro.value_a.label
67
+ assert_equal 'Inteiro BB', Stub.lists.inteiro.value_b.label
68
+ assert_equal 'Inteiro CCC', Stub.lists.inteiro.value_c.label
69
+ assert_equal 'Código A', Stub.lists.code.value_a.label
70
+ assert_equal 'Código B', Stub.lists.code.value_b.label
71
+ assert_equal 'Cadeia AAA', Stub.lists.cadeia.value_a.label
72
+ assert_equal 'Cadeia BB', Stub.lists.cadeia.value_b.label
73
+ assert_equal 'Cadeia C', Stub.lists.cadeia.value_c.label
74
+ assert_equal 'Tipo A', Stub.lists.type.value_a.label
75
+ assert_equal 'Tipo B', Stub.lists.type.value_b.label
76
+ end
77
+
78
+ test 'value instance description' do
79
+ assert_equal 'Inteiro A Descr.', Stub.lists.inteiro.value_a.description
80
+ assert_equal 'Inteiro BB Descr.', Stub.lists.inteiro.value_b.description
81
+ assert_equal 'Inteiro CCC Descr.', Stub.lists.inteiro.value_c.description
82
+ assert_equal 'Código A Descr.', Stub.lists.code.value_a.description
83
+ assert_equal 'Código B Descr.', Stub.lists.code.value_b.description
84
+ assert_equal 'Cadeia AAA Descr.', Stub.lists.cadeia.value_a.description
85
+ assert_equal 'Cadeia BB Descr.', Stub.lists.cadeia.value_b.description
86
+ assert_equal 'Cadeia C Descr.', Stub.lists.cadeia.value_c.description
87
+ assert_equal 'Tipo A Descr.', Stub.lists.type.value_a.description
88
+ assert_equal 'Tipo B Descr.', Stub.lists.type.value_b.description
89
+ end
90
+
91
+ test 'value instance constant name' do
92
+ assert_equal 'INTEIRO_A', Stub.lists.inteiro.value_a.constant_name
93
+ assert_equal 'INTEIRO_B', Stub.lists.inteiro.value_b.constant_name
94
+ assert_equal 'INTEIRO_C', Stub.lists.inteiro.value_c.constant_name
95
+ assert_equal 'CODE_B', Stub.lists.code.value_b.constant_name
96
+ assert_equal 'CODE_B', Stub.lists.code.value_b.constant_name
97
+ assert_equal 'CADEIA_A', Stub.lists.cadeia.value_a.constant_name
98
+ assert_equal 'CADEIA_B', Stub.lists.cadeia.value_b.constant_name
99
+ assert_equal 'CADEIA_C', Stub.lists.cadeia.value_c.constant_name
100
+ assert_equal 'TYPE_A', Stub.lists.type.value_a.constant_name
101
+ assert_equal 'TYPE_B', Stub.lists.type.value_b.constant_name
102
+ end
103
+
104
+ test 'instance label and descriptions' do
105
+ i = Stub.new
106
+ i.inteiro = Stub::INTEIRO_A
107
+ assert_equal 'Inteiro A', i.inteiro_label
108
+ assert_equal 'Inteiro A Descr.', i.inteiro_description
109
+ i.inteiro = Stub::INTEIRO_B
110
+ assert_equal 'Inteiro BB', i.inteiro_label
111
+ assert_equal 'Inteiro BB Descr.', i.inteiro_description
112
+ i.inteiro = Stub::INTEIRO_C
113
+ assert_equal 'Inteiro CCC', i.inteiro_label
114
+ assert_equal 'Inteiro CCC Descr.', i.inteiro_description
115
+ i.code = Stub::CODE_A
116
+ assert_equal 'Código A', i.code_label
117
+ assert_equal 'Código A Descr.', i.code_description
118
+ i.code = Stub::CODE_B
119
+ assert_equal 'Código B', i.code_label
120
+ assert_equal 'Código B Descr.', i.code_description
121
+ i.cadeia = Stub::CADEIA_A
122
+ assert_equal 'Cadeia AAA', i.cadeia_label
123
+ assert_equal 'Cadeia AAA Descr.', i.cadeia_description
124
+ i.cadeia = Stub::CADEIA_B
125
+ assert_equal 'Cadeia BB', i.cadeia_label
126
+ assert_equal 'Cadeia BB Descr.', i.cadeia_description
127
+ i.cadeia = Stub::CADEIA_C
128
+ assert_equal 'Cadeia C', i.cadeia_label
129
+ assert_equal 'Cadeia C Descr.', i.cadeia_description
130
+ i.type = Stub::TYPE_A
131
+ assert_equal 'Tipo A', i.type_label
132
+ assert_equal 'Tipo A Descr.', i.type_description
133
+ i.type = Stub::TYPE_B
134
+ assert_equal 'Tipo B', i.type_label
135
+ assert_equal 'Tipo B Descr.', i.type_description
136
+ end
137
+ end
138
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_rails_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.10
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: 2016-09-01 00:00:00.000000000 Z
11
+ date: 2017-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel-associations
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.2
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rails
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,34 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: 3.3.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: ofx-parser
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: virtus
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.5
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.5
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: nested_form_fields
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -105,18 +147,27 @@ files:
105
147
  - lib/eac/common_form_helper/form_builder/fields_for.rb
106
148
  - lib/eac/common_form_helper/form_builder/radio_select_field.rb
107
149
  - lib/eac/common_form_helper/form_builder/searchable_association_field.rb
150
+ - lib/eac/common_form_helper/form_builder/year_month_field.rb
108
151
  - lib/eac/cpf_validator.rb
109
152
  - lib/eac/formatter_helper.rb
110
153
  - lib/eac/htmlbeautifier.rb
154
+ - lib/eac/inequality_queries.rb
155
+ - lib/eac/listable.rb
111
156
  - lib/eac/menus_helper.rb
112
157
  - lib/eac/menus_helper/bootstrap_gui_builder.rb
113
158
  - lib/eac/menus_helper/data_builder.rb
114
159
  - lib/eac/menus_helper/gui_builder.rb
115
160
  - lib/eac/model.rb
161
+ - lib/eac/no_presence_validator.rb
162
+ - lib/eac/parsers/base.rb
163
+ - lib/eac/parsers/files_test.rb
164
+ - lib/eac/parsers/ofx.rb
116
165
  - lib/eac/simple_cache.rb
117
166
  - lib/eac/source_target_fixtures.rb
167
+ - lib/eac/tableless_model.rb
118
168
  - lib/eac_rails_utils.rb
119
169
  - lib/eac_rails_utils/patches/model_attribute_required.rb
170
+ - lib/eac_rails_utils/patches/ofx_parser.rb
120
171
  - lib/eac_rails_utils/rails/engine.rb
121
172
  - lib/eac_rails_utils/version.rb
122
173
  - test/dummy/Rakefile
@@ -128,6 +179,7 @@ files:
128
179
  - test/dummy/config/database.yml
129
180
  - test/dummy/config/environment.rb
130
181
  - test/dummy/config/environments/test.rb
182
+ - test/dummy/config/locales/pt-BR.yml
131
183
  - test/dummy/config/routes.rb
132
184
  - test/dummy/config/secrets.yml
133
185
  - test/dummy/db/migrate/20160415125333_create_users.rb
@@ -137,6 +189,7 @@ files:
137
189
  - test/lib/eac/common_form_helper_test.rb
138
190
  - test/lib/eac/cpf_validator_test.rb
139
191
  - test/lib/eac/formatter_helper_test.rb
192
+ - test/lib/eac/listable_test.rb
140
193
  - test/lib/eac/model_test.rb
141
194
  - test/lib/eac/simple_cache_test.rb
142
195
  - test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
@@ -160,30 +213,32 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
213
  version: '0'
161
214
  requirements: []
162
215
  rubyforge_project:
163
- rubygems_version: 2.4.8
216
+ rubygems_version: 2.6.12
164
217
  signing_key:
165
218
  specification_version: 4
166
219
  summary: Código reutilizável para as aplicações Rails da E.A.C..
167
220
  test_files:
168
- - test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
169
- - test/lib/eac/formatter_helper_test.rb
170
- - test/lib/eac/common_form_helper_test.rb
171
- - test/lib/eac/cpf_validator_test.rb
172
- - test/lib/eac/model_test.rb
173
- - test/lib/eac/simple_cache_test.rb
174
- - test/dummy/config.ru
175
- - test/dummy/db/migrate/20160415143229_add_job_to_users.rb
176
- - test/dummy/db/migrate/20160415143123_create_jobs.rb
177
- - test/dummy/db/migrate/20160415125333_create_users.rb
178
- - test/dummy/db/schema.rb
179
- - test/dummy/app/models/user.rb
180
- - test/dummy/app/models/job.rb
181
221
  - test/dummy/Rakefile
182
- - test/dummy/config/environments/test.rb
183
- - test/dummy/config/application.rb
222
+ - test/dummy/config.ru
184
223
  - test/dummy/config/boot.rb
185
- - test/dummy/config/secrets.yml
186
224
  - test/dummy/config/database.yml
187
- - test/dummy/config/routes.rb
225
+ - test/dummy/config/secrets.yml
226
+ - test/dummy/config/locales/pt-BR.yml
227
+ - test/dummy/config/application.rb
228
+ - test/dummy/config/environments/test.rb
188
229
  - test/dummy/config/environment.rb
230
+ - test/dummy/config/routes.rb
231
+ - test/dummy/db/schema.rb
232
+ - test/dummy/db/migrate/20160415143123_create_jobs.rb
233
+ - test/dummy/db/migrate/20160415143229_add_job_to_users.rb
234
+ - test/dummy/db/migrate/20160415125333_create_users.rb
235
+ - test/dummy/app/models/job.rb
236
+ - test/dummy/app/models/user.rb
189
237
  - test/test_helper.rb
238
+ - test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
239
+ - test/lib/eac/common_form_helper_test.rb
240
+ - test/lib/eac/cpf_validator_test.rb
241
+ - test/lib/eac/simple_cache_test.rb
242
+ - test/lib/eac/formatter_helper_test.rb
243
+ - test/lib/eac/listable_test.rb
244
+ - test/lib/eac/model_test.rb