avm 0.50.0 → 0.52.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/avm/executables.rb +1 -1
- data/lib/avm/file_formats/base.rb +61 -0
- data/lib/avm/file_formats/search_formatter.rb +97 -0
- data/lib/avm/file_formats/utf8_assert.rb +72 -0
- data/lib/avm/file_formats.rb +9 -0
- data/lib/avm/registry/file_formats.rb +10 -0
- data/lib/avm/registry.rb +2 -2
- data/lib/avm/rspec/setup.rb +2 -1
- data/lib/avm/rspec/shared_examples/avm_file_formats_with_fixtures.rb +32 -0
- data/lib/avm/version.rb +1 -1
- metadata +43 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee9bdf4f0f96dc20133dd6c00c10ecba0dd48799a37d45d71f3378015448ba4c
|
4
|
+
data.tar.gz: c02fa3d82e35f6e8de9221f2ddd92819da8ecac271239e0127c5b74b43d6b06e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90d0355e8800f3157d3a1a8f90eebf6b95ee47e70be6720e4143cc618e75d8900ce7be84d6b77cc78e4220c9ea02b03b7935950665974372e1c2362f9e5ce2cb
|
7
|
+
data.tar.gz: fef3c1a442cd5bda53b6c562c6d50c48bc409e501cc95440ce876bb82973acf04e91b636a85c8bd4ee21c3e3b5853c8de99da1f66b2abbd027eb6845baf13ea6
|
data/lib/avm/executables.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/file_formats/utf8_assert'
|
4
|
+
require 'eac_fs/file_info'
|
5
|
+
require 'ostruct'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module FileFormats
|
9
|
+
class Base
|
10
|
+
enable_abstract_methods
|
11
|
+
|
12
|
+
def apply(files)
|
13
|
+
old_content = Hash[files.map { |f| [f, File.read(f)] }]
|
14
|
+
::Avm::FileFormats::Utf8Assert.assert_files(files) { internal_apply(files) }
|
15
|
+
files.map { |f| build_file_result(f, old_content[f]) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
self.class.name.demodulize
|
20
|
+
end
|
21
|
+
|
22
|
+
def match?(file)
|
23
|
+
match_by_filename?(file) || match_by_type?(file)
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid_basenames
|
27
|
+
constant_or_array('VALID_BASENAMES')
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid_types
|
31
|
+
constant_or_array('VALID_TYPES')
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def constant_or_array(name)
|
37
|
+
return [] unless self.class.const_defined?(name)
|
38
|
+
|
39
|
+
self.class.const_get(name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def build_file_result(file, old_content)
|
43
|
+
::OpenStruct.new(file: file, format: self.class,
|
44
|
+
changed: (old_content != File.read(file)))
|
45
|
+
end
|
46
|
+
|
47
|
+
def match_by_filename?(file)
|
48
|
+
valid_basenames.any? do |valid_basename|
|
49
|
+
file.basename.fnmatch?(valid_basename)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def match_by_type?(file)
|
54
|
+
info = ::EacFs::FileInfo.new(file)
|
55
|
+
return unless info.content_type.type == 'text'
|
56
|
+
|
57
|
+
valid_types.include?(info.content_type.subtype)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -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
|
data/lib/avm/registry.rb
CHANGED
@@ -7,8 +7,8 @@ module Avm
|
|
7
7
|
module Registry
|
8
8
|
require_sub __FILE__
|
9
9
|
enable_listable
|
10
|
-
lists.add_symbol :category, :application_stereotypes, :
|
11
|
-
:runners, :scms, :source_generators, :sources
|
10
|
+
lists.add_symbol :category, :application_stereotypes, :file_formats, :instances,
|
11
|
+
:launcher_stereotypes, :runners, :scms, :source_generators, :sources
|
12
12
|
|
13
13
|
class << self
|
14
14
|
enable_simple_cache
|
data/lib/avm/rspec/setup.rb
CHANGED
@@ -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
|
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
|
data/lib/avm/version.rb
CHANGED
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.
|
4
|
+
version: 0.52.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-
|
11
|
+
date: 2022-10-25 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
|
@@ -59,7 +79,7 @@ dependencies:
|
|
59
79
|
- !ruby/object:Gem::Version
|
60
80
|
version: '0.5'
|
61
81
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
82
|
+
name: eac_fs
|
63
83
|
requirement: !ruby/object:Gem::Requirement
|
64
84
|
requirements:
|
65
85
|
- - "~>"
|
@@ -78,6 +98,20 @@ dependencies:
|
|
78
98
|
- - ">="
|
79
99
|
- !ruby/object:Gem::Version
|
80
100
|
version: 0.12.3
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: eac_git
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0.13'
|
108
|
+
type: :runtime
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0.13'
|
81
115
|
- !ruby/object:Gem::Dependency
|
82
116
|
name: eac_ruby_utils
|
83
117
|
requirement: !ruby/object:Gem::Requirement
|
@@ -271,6 +305,10 @@ files:
|
|
271
305
|
- lib/avm/entries/keys_constants_set.rb
|
272
306
|
- lib/avm/entries/uri_builder.rb
|
273
307
|
- lib/avm/executables.rb
|
308
|
+
- lib/avm/file_formats.rb
|
309
|
+
- lib/avm/file_formats/base.rb
|
310
|
+
- lib/avm/file_formats/search_formatter.rb
|
311
|
+
- lib/avm/file_formats/utf8_assert.rb
|
274
312
|
- lib/avm/instances.rb
|
275
313
|
- lib/avm/instances/base.rb
|
276
314
|
- lib/avm/instances/base/auto_values.rb
|
@@ -317,6 +355,7 @@ files:
|
|
317
355
|
- lib/avm/registry/application_stereotypes.rb
|
318
356
|
- lib/avm/registry/application_stereotypes/build_available.rb
|
319
357
|
- lib/avm/registry/application_stereotypes/stereotype_builder.rb
|
358
|
+
- lib/avm/registry/file_formats.rb
|
320
359
|
- lib/avm/registry/from_gems.rb
|
321
360
|
- lib/avm/registry/instances.rb
|
322
361
|
- lib/avm/registry/launcher_stereotypes.rb
|
@@ -330,6 +369,7 @@ files:
|
|
330
369
|
- lib/avm/rspec.rb
|
331
370
|
- lib/avm/rspec/setup.rb
|
332
371
|
- lib/avm/rspec/setup/launcher.rb
|
372
|
+
- lib/avm/rspec/shared_examples/avm_file_formats_with_fixtures.rb
|
333
373
|
- lib/avm/rspec/shared_examples/entries_values.rb
|
334
374
|
- lib/avm/rspec/shared_examples/in_avm_registry.rb
|
335
375
|
- lib/avm/rspec/shared_examples/not_in_avm_registry.rb
|