avm 0.51.0 → 0.53.0

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
  SHA256:
3
- metadata.gz: c7d526aa03c069d29d98545ce6d90ff1336592ad1c74a432c88430feb4cc71a6
4
- data.tar.gz: f1b4f72746cd60c762df317eb415a91810de688bf58bc24d1ab261f085974b52
3
+ metadata.gz: 9867c212c40c67bb9467d5109778d76f2bc11752b604934404e11956663e719b
4
+ data.tar.gz: 0ef0d4ca046e4fcbf8e03174bbece1b4e71972c02d50692bd9c3ef8ad2f3e04a
5
5
  SHA512:
6
- metadata.gz: db1371c99c4d393a1b47cb09275a9fb6c9acb094706119b2db2a83131e87b75a85210b097e76dd053f35b892680713e493b2a2277767b66b0885e5c0434f713a
7
- data.tar.gz: c2f242bddf30a01e4db4f4aaaffa7878863df455a04023d928ab611951cd2a73b4343cea0bcb312c44db96b98488a4337894f90cf23aba6972f28bf4ab571ee9
6
+ metadata.gz: d68c998e7a9decaebba0c1023f1e2c259ea9edeeac3a8bb05d78740a45422308031bdcd650d2beaf487de4adef82b9faa72c4bfc2fd88e9c788a456a5ac7fd17
7
+ data.tar.gz: b499addbd90d59becc16270a7f9cb5f8839db6ac4d1a3dc2e7467f75d8d6b97a45ade2bfca0b783fb24f314a4c4241b263d587a0aee755c1e0eb1918d9d188f9
@@ -14,7 +14,7 @@ module Avm
14
14
 
15
15
  private
16
16
 
17
- %w[file git js-beautify latex php-cs-fixer tidy yapf xdg-open].each do |program|
17
+ %w[xdg-open].each do |program|
18
18
  define_method(program.underscore + '_uncached') do
19
19
  env.executable(program, '--version')
20
20
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/file_formats/utf8_assert'
3
4
  require 'eac_fs/file_info'
4
5
  require 'ostruct'
5
6
 
@@ -10,7 +11,7 @@ module Avm
10
11
 
11
12
  def apply(files)
12
13
  old_content = Hash[files.map { |f| [f, File.read(f)] }]
13
- ::Avm::Files::Formatter::Utf8Assert.assert_files(files) { internal_apply(files) }
14
+ ::Avm::FileFormats::Utf8Assert.assert_files(files) { internal_apply(files) }
14
15
  files.map { |f| build_file_result(f, old_content[f]) }
15
16
  end
16
17
 
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/registry'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_fs/traversable'
6
+
7
+ module Avm
8
+ module FileFormats
9
+ class SearchFormatter
10
+ include ::EacFs::Traversable
11
+ require_sub __FILE__
12
+ enable_simple_cache
13
+ enable_speaker
14
+ enable_listable
15
+ lists.add_symbol :option, :apply, :recursive, :verbose
16
+ common_constructor :source_paths, :options, default: [{}] do
17
+ options.assert_valid_keys(self.class.lists.option.values)
18
+ end
19
+
20
+ def run
21
+ clear
22
+ search_files
23
+ apply
24
+ show_results
25
+ end
26
+
27
+ private
28
+
29
+ def apply
30
+ speak(:infom, "Applying #{@formats_files.count} format(s)... ")
31
+ @formats_files.each do |format, files|
32
+ speak(:infom, "Applying format #{format.name} (Files matched: #{files.count})...")
33
+ next unless options[OPTION_APPLY]
34
+
35
+ @result += format.apply(files)
36
+ end
37
+ end
38
+
39
+ def traverser_check_file(file)
40
+ format = find_format(file)
41
+ speak(:infov, file, format ? format.class : '-')
42
+ return unless format
43
+
44
+ @formats_files[format] ||= []
45
+ @formats_files[format] << file
46
+ end
47
+
48
+ def clear
49
+ @formats_files = {}
50
+ @result = []
51
+ end
52
+
53
+ def find_format(file)
54
+ formats.each do |c|
55
+ return c if c.match?(file)
56
+ end
57
+ nil
58
+ end
59
+
60
+ def formats_uncached
61
+ formats_from_registry
62
+ end
63
+
64
+ def formats_from_registry
65
+ ::Avm::Registry.file_formats.available.reverse.map(&:new)
66
+ end
67
+
68
+ def search_files
69
+ speak(:infov, 'Directories to search', source_paths.count)
70
+ source_paths.each do |source_path|
71
+ speak(:infom, "Searching files on \"#{source_path}\"...")
72
+ traverser_check_path(source_path)
73
+ end
74
+ end
75
+
76
+ def show_results
77
+ changed = @result.select(&:changed)
78
+ changed.each do |h|
79
+ speak(:out, h.file.to_s.cyan)
80
+ speak(:out, " (#{h.format})".yellow)
81
+ speak(:puts, ' changed'.green)
82
+ end
83
+ speak(:infov, 'Files changed', "#{changed.count}/#{@result.count}")
84
+ end
85
+
86
+ def traverser_recursive
87
+ options[OPTION_RECURSIVE]
88
+ end
89
+
90
+ def speak(method, *method_args)
91
+ return unless options[OPTION_VERBOSE].to_bool
92
+
93
+ send(method, *method_args)
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_fs/file_info'
4
+
5
+ module Avm
6
+ module FileFormats
7
+ class Utf8Assert
8
+ UTF8_CHARSET = 'utf-8'
9
+ UTF8_CHARSETS = [UTF8_CHARSET, 'us-ascii'].freeze
10
+
11
+ class << self
12
+ def assert_files(files)
13
+ asserters = files.map { |file| new(file) }
14
+ begin
15
+ asserters.each(&:assert)
16
+ yield
17
+ ensure
18
+ asserters.each(&:revert)
19
+ end
20
+ end
21
+ end
22
+
23
+ enable_simple_cache
24
+ common_constructor :path
25
+
26
+ def assert
27
+ return if original_utf8?
28
+
29
+ convert_self(original_charset, UTF8_CHARSET)
30
+ end
31
+
32
+ def revert
33
+ return if original_utf8?
34
+
35
+ convert_self(UTF8_CHARSET, original_charset)
36
+ end
37
+
38
+ private
39
+
40
+ def original_info_uncached
41
+ ::EacFs::FileInfo.new(path)
42
+ end
43
+
44
+ def original_charset_uncached
45
+ return original_info.content_type.charset if original_info.content_type.charset.present?
46
+
47
+ raise 'No charset found'
48
+ rescue StandardError => e
49
+ raise "Unable to determine the charset of #{path} (#{e.message})"
50
+ end
51
+
52
+ def original_utf8?
53
+ UTF8_CHARSETS.include?(original_charset)
54
+ end
55
+
56
+ def convert_file(from_path, from_charset, to_path, to_charset)
57
+ File.open(from_path, "r:#{from_charset}") do |input|
58
+ File.open(to_path, "w:#{to_charset}") do |output|
59
+ output.write(input.read)
60
+ end
61
+ end
62
+ end
63
+
64
+ def convert_self(from_charset, to_charset)
65
+ temp = ::Tempfile.new
66
+ temp.close
67
+ convert_file(path, from_charset, temp.path, to_charset)
68
+ ::FileUtils.mv(temp.path, path)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -7,7 +7,8 @@ module Avm
7
7
  module Rspec
8
8
  module Setup
9
9
  require_sub __FILE__
10
- EXAMPLES = %w[entries_values in_avm_registry not_in_avm_registry].freeze
10
+ EXAMPLES = %w[avm_file_formats_with_fixtures entries_values in_avm_registry
11
+ not_in_avm_registry].freeze
11
12
 
12
13
  def self.extended(obj)
13
14
  obj.setup_examples
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aranha/parsers/source_target_fixtures'
4
+ require 'avm/file_formats/search_formatter'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ ::RSpec.shared_examples 'avm_file_formats_with_fixtures' do |the_spec_file|
8
+ include_examples 'source_target_fixtures', the_spec_file
9
+
10
+ def format_files_in_directory(target_dir)
11
+ ::Avm::FileFormats::SearchFormatter
12
+ .new([target_dir], recursive: true, apply: true, verbose: false)
13
+ .run
14
+ end
15
+
16
+ def source_data(source_file)
17
+ dir = temp_dir
18
+ source_basename = source_file_basename_without_source_extname(source_file)
19
+ source_path = dir.join(source_basename)
20
+ ::FileUtils.cp(source_file, source_path)
21
+ format_files_in_directory(dir)
22
+ source_path.read
23
+ end
24
+
25
+ def source_file_basename_without_source_extname(source_file)
26
+ source_file.to_pathname.basename_sub { |b| b.to_path.gsub(/\.source/, '') }.basename
27
+ end
28
+
29
+ def target_data(target_file)
30
+ ::File.read(target_file)
31
+ end
32
+ end
@@ -12,6 +12,14 @@ module Avm
12
12
  raise_abstract_method __method__
13
13
  end
14
14
 
15
+ def deploy_to_env_path(_target_env, _target_path)
16
+ raise_abstract_method __method__
17
+ end
18
+
19
+ def id
20
+ raise_abstract_method __method__
21
+ end
22
+
15
23
  # @param other [Avm::Scms::Commit]
16
24
  # @return [Avm::Scms::Commit]
17
25
  def merge_with(_other)
data/lib/avm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avm
4
- VERSION = '0.51.0'
4
+ VERSION = '0.53.0'
5
5
  end
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.51.0
4
+ version: 0.53.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo H. Bogoni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-20 00:00:00.000000000 Z
11
+ date: 2022-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aranha-parsers
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.14'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.14.4
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.14'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.14.4
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: eac_cli
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +78,26 @@ dependencies:
58
78
  - - "~>"
59
79
  - !ruby/object:Gem::Version
60
80
  version: '0.5'
81
+ - !ruby/object:Gem::Dependency
82
+ name: eac_fs
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '0.12'
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: 0.12.3
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0.12'
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 0.12.3
61
101
  - !ruby/object:Gem::Dependency
62
102
  name: eac_git
63
103
  requirement: !ruby/object:Gem::Requirement
@@ -78,14 +118,20 @@ dependencies:
78
118
  requirements:
79
119
  - - "~>"
80
120
  - !ruby/object:Gem::Version
81
- version: '0.105'
121
+ version: '0.106'
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 0.106.1
82
125
  type: :runtime
83
126
  prerelease: false
84
127
  version_requirements: !ruby/object:Gem::Requirement
85
128
  requirements:
86
129
  - - "~>"
87
130
  - !ruby/object:Gem::Version
88
- version: '0.105'
131
+ version: '0.106'
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 0.106.1
89
135
  - !ruby/object:Gem::Dependency
90
136
  name: eac_templates
91
137
  requirement: !ruby/object:Gem::Requirement
@@ -267,6 +313,8 @@ files:
267
313
  - lib/avm/executables.rb
268
314
  - lib/avm/file_formats.rb
269
315
  - lib/avm/file_formats/base.rb
316
+ - lib/avm/file_formats/search_formatter.rb
317
+ - lib/avm/file_formats/utf8_assert.rb
270
318
  - lib/avm/instances.rb
271
319
  - lib/avm/instances/base.rb
272
320
  - lib/avm/instances/base/auto_values.rb
@@ -327,6 +375,7 @@ files:
327
375
  - lib/avm/rspec.rb
328
376
  - lib/avm/rspec/setup.rb
329
377
  - lib/avm/rspec/setup/launcher.rb
378
+ - lib/avm/rspec/shared_examples/avm_file_formats_with_fixtures.rb
330
379
  - lib/avm/rspec/shared_examples/entries_values.rb
331
380
  - lib/avm/rspec/shared_examples/in_avm_registry.rb
332
381
  - lib/avm/rspec/shared_examples/not_in_avm_registry.rb