avm 0.65.0 → 0.66.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: 2944015b38061efc50472926c45c9d9696c6960d0d150226481249f86ee5d2d1
4
- data.tar.gz: c8e3d32b157f5e8ff06ce1904fa702fdd7a5ae425e3d1da9e8327332c71b9693
3
+ metadata.gz: b052d242bf8dccbe7db34f395acd096c3700c7553ee5c16f590970653ad6274f
4
+ data.tar.gz: 35f3f1cbb0840d82b8450921f2725b1adf10df833f82f9ec82138bb777b52e74
5
5
  SHA512:
6
- metadata.gz: 792dfd5ec8d14e1fd1723962a4b6ab1da06e998a0d3bb1204ae4801c76a94130969010a3be542fd4d08f07b77ab896b7cedce265a29f9a40430a0f490670f567
7
- data.tar.gz: f76e19d8af260f6ff840960b655362c2c47dd9292030c26eb7e0c72667f37e72051f3460b517a7057655da7b9b4dc7b9a89851452fd3de78f4f96c9c46aca9eb
6
+ metadata.gz: 1d3e9166ff3862d74e3d5087509c2fb0efbf5d96072eb6acde907ceb88eb14c4be73b7b4b6e0a36081feeefd893050c5bb18abc99b06e3bf983485c20a9af7ea
7
+ data.tar.gz: 0c1245bdf1e60ccee7bd6f270d7962f2e7eac458c802a728d395f0fb72e8e62e79535a9a0a3e5921bd8f7254bfa907ab7fafbc9a54e765d842aefa6973c3baa6
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/file_formats/utf8_assert'
4
3
  require 'eac_fs/file_info'
5
4
  require 'ostruct'
6
5
 
@@ -10,10 +9,10 @@ module Avm
10
9
  enable_abstract_methods
11
10
  compare_by :class
12
11
 
13
- def apply(files)
14
- old_content = Hash[files.map { |f| [f, File.read(f)] }]
15
- ::Avm::FileFormats::Utf8Assert.assert_files(files) { internal_apply(files) }
16
- files.map { |f| build_file_result(f, old_content[f]) }
12
+ # @params files [Enumerable<Pathname>]
13
+ # @return [Enumerable<Avm::FileFormats::FileResult>]
14
+ def apply(_files)
15
+ raise_abstract_method __method__
17
16
  end
18
17
 
19
18
  # @param path [Pathname]
@@ -26,42 +25,10 @@ module Avm
26
25
  self.class.name.demodulize
27
26
  end
28
27
 
29
- def match?(file)
30
- match_by_filename?(file) || match_by_type?(file)
31
- end
32
-
33
- def valid_basenames
34
- constant_or_array('VALID_BASENAMES')
35
- end
36
-
37
- def valid_types
38
- constant_or_array('VALID_TYPES')
39
- end
40
-
41
- private
42
-
43
- def constant_or_array(name)
44
- return [] unless self.class.const_defined?(name)
45
-
46
- self.class.const_get(name)
47
- end
48
-
49
- def build_file_result(file, old_content)
50
- ::OpenStruct.new(file: file, format: self.class,
51
- changed: (old_content != File.read(file)))
52
- end
53
-
54
- def match_by_filename?(file)
55
- valid_basenames.any? do |valid_basename|
56
- file.basename.fnmatch?(valid_basename)
57
- end
58
- end
59
-
60
- def match_by_type?(file)
61
- info = ::EacFs::FileInfo.new(file)
62
- return unless info.content_type.type == 'text'
63
-
64
- valid_types.include?(info.content_type.subtype)
28
+ # @param file [Pathname]
29
+ # @return [Boolean]
30
+ def match?(_file)
31
+ raise_abstract_method __method__
65
32
  end
66
33
  end
67
34
  end
@@ -0,0 +1,13 @@
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 FileResult
10
+ common_constructor :file, :format, :changed
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/file_formats/base'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module FileFormats
8
+ class Unknown < ::Avm::FileFormats::Base
9
+ # @params files [Enumerable<Pathname>]
10
+ # @return [Enumerable<Avm::FileFormats::FileResult>]
11
+ def apply(files)
12
+ files.map do |file|
13
+ ::Avm::FileFormats::FileResult.new(file, self.class, false)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'avm/file_formats/unknown'
3
4
  require 'avm/registry/from_gems'
4
5
 
5
6
  module Avm
@@ -9,6 +10,11 @@ module Avm
9
10
  def class_detect(klass, detect_args)
10
11
  klass.new if klass.new.match?(detect_args.first)
11
12
  end
13
+
14
+ # @return [Avm::FileFormats::Base, Avm::FileFormats::Unknown]
15
+ def detect_optional(*registered_initialize_args)
16
+ super || ::Avm::FileFormats::Unknown.new
17
+ end
12
18
  end
13
19
  end
14
20
  end
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.65.0'
4
+ VERSION = '0.66.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.65.0
4
+ version: 0.66.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: 2023-03-31 00:00:00.000000000 Z
11
+ date: 2023-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -279,7 +279,9 @@ files:
279
279
  - lib/avm/executables.rb
280
280
  - lib/avm/file_formats.rb
281
281
  - lib/avm/file_formats/base.rb
282
+ - lib/avm/file_formats/file_result.rb
282
283
  - lib/avm/file_formats/search_formatter.rb
284
+ - lib/avm/file_formats/unknown.rb
283
285
  - lib/avm/file_formats/utf8_assert.rb
284
286
  - lib/avm/instances.rb
285
287
  - lib/avm/instances/base.rb