eac_rails_utils 0.3.0 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9eeecb5a7613a760542d6b220abdd21b3c2019896f9b9d41ed0c21aee81aa123
4
- data.tar.gz: '0559817915097129faca0f1723d5e0c5c9e2b8b1417f535359446f2bbeffb440'
3
+ metadata.gz: 4331a79b726cdb7d57b195aa6a353100a40e0b13105e8af73b5de0d0ef772de8
4
+ data.tar.gz: 6708069f999d4dc7870caed8f3201c3f74b1e949f8c58b38eeb3e9ebaddd3fc0
5
5
  SHA512:
6
- metadata.gz: d6ae35dba7d708e6e8c5abfa6494b8f954c879c1b12e916e7f42781f277b3132f546e618590eadab2804219aa6b17f825c14a8e76a464936c9bc30c527bea3e7
7
- data.tar.gz: 6b35ecb2095434479d2c983d6a4cc972934c023836f6bc7e26933a8334e4ef268e6547c689eb86fc28b981a5d6a724b200a19209d543c42b74371d4a2c60af5b
6
+ metadata.gz: 138f4bebee91229a8fb9a6ff5ad7f87174cd6910d6a7e7d811f54d62f8cfff3cf85b03e3cb49284c6cafa74c23e055028a58e4543d713ce9a96108857e17bf72
7
+ data.tar.gz: 89118f011528541ab4cb106cce163bdf03bf0a056304edcdf9157e9b5baedd3709bfa184bdbd08222f00092095cbe69c493a3888eeffce6b7728d1a9f520b534
@@ -27,7 +27,6 @@ module EacRailsUtils
27
27
  require 'eac/common_form_helper/form_builder'
28
28
  require 'eac/common_form_helper'
29
29
  require_dependency 'eac/data_table_helper'
30
- require 'eac/download_fixtures'
31
30
  require 'eac/htmlbeautifier'
32
31
  require 'eac/inequality_queries'
33
32
  require 'eac/listable'
@@ -37,9 +36,7 @@ module EacRailsUtils
37
36
  require 'eac/menus_helper/gui_builder'
38
37
  require 'eac/model'
39
38
  require 'eac/no_presence_validator'
40
- require 'eac/parsers/base'
41
39
  require 'eac/parsers/files_test'
42
- require 'eac/parsers/ofx'
43
40
  require 'eac/simple_cache'
44
41
  require 'eac/source_target_fixtures'
45
42
  require 'eac/test_utils'
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module EacRailsUtils
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  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.3.0
4
+ version: 0.4.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: 2019-05-21 00:00:00.000000000 Z
11
+ date: 2019-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel-associations
@@ -163,7 +163,6 @@ files:
163
163
  - lib/eac/data_table_helper/column.rb
164
164
  - lib/eac/data_table_helper/data_table.rb
165
165
  - lib/eac/data_table_helper/setup.rb
166
- - lib/eac/download_fixtures.rb
167
166
  - lib/eac/htmlbeautifier.rb
168
167
  - lib/eac/inequality_queries.rb
169
168
  - lib/eac/listable.rb
@@ -173,9 +172,7 @@ files:
173
172
  - lib/eac/menus_helper/gui_builder.rb
174
173
  - lib/eac/model.rb
175
174
  - lib/eac/no_presence_validator.rb
176
- - lib/eac/parsers/base.rb
177
175
  - lib/eac/parsers/files_test.rb
178
- - lib/eac/parsers/ofx.rb
179
176
  - lib/eac/simple_cache.rb
180
177
  - lib/eac/source_target_fixtures.rb
181
178
  - lib/eac/test_utils.rb
@@ -187,7 +184,6 @@ files:
187
184
  - lib/eac_rails_utils/rails/engine.rb
188
185
  - lib/eac_rails_utils/tableless_model.rb
189
186
  - lib/eac_rails_utils/version.rb
190
- - lib/tasks/eac_rails_utils.rake
191
187
  - test/dummy/Rakefile
192
188
  - test/dummy/app/models/job.rb
193
189
  - test/dummy/app/models/user.rb
@@ -248,39 +244,39 @@ signing_key:
248
244
  specification_version: 4
249
245
  summary: Código reutilizável para as aplicações Rails da E.A.C..
250
246
  test_files:
251
- - test/lib/eac_rails_utils/tableless_model_test.rb
252
- - test/lib/eac_rails_utils/helpers/formatter_test.rb
253
- - test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
254
- - test/lib/eac/source_target_fixtures_test.rb
255
- - test/lib/eac/listable_test.rb
256
- - test/lib/eac/data_table_test_helper.rb
257
- - test/lib/eac/cpf_validator_test.rb
258
- - test/lib/eac/model_test.rb
259
- - test/lib/eac/common_form_helper_test.rb
260
- - test/lib/eac/source_target_fixtures_test_files/a.target.yaml
261
- - test/lib/eac/source_target_fixtures_test_files/b.source.html
262
- - test/lib/eac/source_target_fixtures_test_files/c.target.yaml
263
- - test/lib/eac/source_target_fixtures_test_files/a.source.html
264
- - test/lib/eac/simple_cache_test.rb
265
- - test/lib/eac/parsers/files_test_test.rb
266
- - test/lib/eac/parsers/ok_test_files/a.target.yaml
267
- - test/lib/eac/parsers/ok_test_files/b.source.yaml
268
- - test/lib/eac/parsers/ok_test_files/b.target.yaml
269
- - test/lib/eac/parsers/ok_test_files/a.source.yaml
270
- - test/dummy/config/routes.rb
247
+ - test/dummy/Rakefile
248
+ - test/dummy/config.ru
249
+ - test/dummy/config/boot.rb
271
250
  - test/dummy/config/database.yml
272
251
  - test/dummy/config/secrets.yml
273
252
  - test/dummy/config/locales/pt-BR.yml
274
- - test/dummy/config/environment.rb
275
- - test/dummy/config/boot.rb
276
253
  - test/dummy/config/application.rb
277
254
  - test/dummy/config/environments/test.rb
278
- - test/dummy/Rakefile
279
- - test/dummy/config.ru
280
- - test/dummy/app/models/user.rb
281
- - test/dummy/app/models/job.rb
255
+ - test/dummy/config/environment.rb
256
+ - test/dummy/config/routes.rb
282
257
  - test/dummy/db/schema.rb
283
- - test/dummy/db/migrate/20160415125333_create_users.rb
284
258
  - test/dummy/db/migrate/20160415143123_create_jobs.rb
285
259
  - test/dummy/db/migrate/20160415143229_add_job_to_users.rb
260
+ - test/dummy/db/migrate/20160415125333_create_users.rb
261
+ - test/dummy/app/models/job.rb
262
+ - test/dummy/app/models/user.rb
286
263
  - test/test_helper.rb
264
+ - test/lib/eac_rails_utils/helpers/formatter_test.rb
265
+ - test/lib/eac_rails_utils/patches/model_attribute_required_test.rb
266
+ - test/lib/eac_rails_utils/tableless_model_test.rb
267
+ - test/lib/eac/common_form_helper_test.rb
268
+ - test/lib/eac/source_target_fixtures_test.rb
269
+ - test/lib/eac/parsers/files_test_test.rb
270
+ - test/lib/eac/parsers/ok_test_files/a.source.yaml
271
+ - test/lib/eac/parsers/ok_test_files/a.target.yaml
272
+ - test/lib/eac/parsers/ok_test_files/b.source.yaml
273
+ - test/lib/eac/parsers/ok_test_files/b.target.yaml
274
+ - test/lib/eac/cpf_validator_test.rb
275
+ - test/lib/eac/data_table_test_helper.rb
276
+ - test/lib/eac/simple_cache_test.rb
277
+ - test/lib/eac/source_target_fixtures_test_files/c.target.yaml
278
+ - test/lib/eac/source_target_fixtures_test_files/b.source.html
279
+ - test/lib/eac/source_target_fixtures_test_files/a.target.yaml
280
+ - test/lib/eac/source_target_fixtures_test_files/a.source.html
281
+ - test/lib/eac/listable_test.rb
282
+ - test/lib/eac/model_test.rb
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Eac
4
- class DownloadFixtures
5
- def initialize(prefix, download)
6
- @prefix = prefix
7
- @prefix = '' if @prefix.blank?
8
- @download = download
9
- end
10
-
11
- def run
12
- url_files.each do |f|
13
- Rails.logger.info(relative_path(f))
14
- download(url(f), target(f)) if @download
15
- end
16
- end
17
-
18
- private
19
-
20
- def url_files
21
- files = []
22
- Dir["#{fixtures_root}/**/*.url"].map do |path|
23
- files << path if match_pattern(path)
24
- end
25
- files
26
- end
27
-
28
- def match_pattern(path)
29
- relative_path(path).start_with?(@prefix)
30
- end
31
-
32
- def fixtures_root
33
- Rails.root.to_s
34
- end
35
-
36
- def download(url, target)
37
- Rails.logger.info "Baixando \"#{url}\"..."
38
- File.open(target, 'wb') { |file| file.write(Parsers::Base.new(url).content) }
39
- end
40
-
41
- def url(file)
42
- File.read(file).strip
43
- end
44
-
45
- def target(file)
46
- File.expand_path(File.basename(file, '.url') + '.source.html', File.dirname(file))
47
- end
48
-
49
- def relative_path(path)
50
- path.sub(%r{^#{Regexp.quote(fixtures_root)}/}, '')
51
- end
52
- end
53
- end
@@ -1,90 +0,0 @@
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.gsub(%r{\Afile://}, ''), &:read)
38
- end
39
-
40
- def content_get
41
- content_get_fetch(@url)
42
- end
43
-
44
- def content_get_fetch(uri, limit = 10)
45
- raise 'too many HTTP redirects' if limit == 0
46
- uri = Addressable::URI.parse(uri)
47
- content_get_fetch_result(uri, limit, Net::HTTP.get_response(uri))
48
- end
49
-
50
- def content_get_fetch_result(uri, limit, response)
51
- case response
52
- when Net::HTTPSuccess then
53
- response.body
54
- when Net::HTTPRedirection then
55
- content_get_fetch_redirect(uri, Addressable::URI.parse(response['location']), limit)
56
- else
57
- response.value
58
- end
59
- end
60
-
61
- def content_get_fetch_redirect(original_uri, redirect_uri, limit)
62
- if redirect_uri.scheme.blank?
63
- redirect_uri.scheme = original_uri.scheme
64
- redirect_uri.authority = original_uri.authority
65
- end
66
- Rails.logger.debug("#{original_uri} redirected to #{redirect_uri}")
67
- content_get_fetch(redirect_uri, limit - 1)
68
- end
69
-
70
- def content_hash
71
- return content_post if @url[:method] == :post
72
- raise "Unknown URL format: #{@url}"
73
- end
74
-
75
- def content_post
76
- HTTPClient.new.post_content(@url[:url], @url[:params].merge(follow_redirect: true))
77
- end
78
-
79
- def log_content(s)
80
- File.open(log_file, 'wb') { |file| file.write(s) }
81
- end
82
-
83
- def log_file
84
- f = Rails.root.join('log', 'parsers', "#{self.class.name.parameterize}.log")
85
- FileUtils.mkdir_p(File.dirname(f))
86
- f
87
- end
88
- end
89
- end
90
- end
@@ -1,30 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
- namespace :eac do
3
- desc 'Baixa o conteúdo remoto de fixtures'
4
- task download_fixtures: :environment do
5
- ::Eac::DownloadFixtures.new(ENV['PREFIX'], ENV['DOWNLOAD'].present?).run
6
- end
7
- end