avm-tools 0.37.0 → 0.37.1
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 +4 -0
- data/lib/avm/files/formatter/formats/base.rb +6 -3
- data/lib/avm/files/formatter/formats/generic_plain.rb +2 -2
- data/lib/avm/files/formatter/formats/php.rb +1 -1
- data/lib/avm/files/formatter/utf8_assert.rb +72 -0
- data/lib/avm/files/info.rb +22 -0
- data/lib/avm/tools/version.rb +1 -1
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 265ec590d53bde1eff714c1789cb317e4fe855cce54bf12535f60ab4b508b811
|
4
|
+
data.tar.gz: 2ac59d6b0c89adb5e091ebe88a65062ccd0ded1c2cb98e5046296701b8cb3604
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38828cff9cfdc2d3aed17d93f81cc2254bb4f3bae27bd35320f1e5e4d4a7d38d6b24d0a95251aedb35fb7c2d9178ba705b7eb402306a66d2827f310e9e8a3d7e
|
7
|
+
data.tar.gz: 1e557150968a16d21a5002d30febe4f6812deac5b8f87f8faf84b07b6790ce71608353fa6ffe7d3727536bf4b1b4572914166eb6066f07b27c82c2d875a1f79b
|
data/lib/avm/executables.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'avm/files/info'
|
3
4
|
require 'ostruct'
|
4
5
|
|
5
6
|
module Avm
|
@@ -9,7 +10,7 @@ module Avm
|
|
9
10
|
class Base
|
10
11
|
def apply(files)
|
11
12
|
old_content = Hash[files.map { |f| [f, File.read(f)] }]
|
12
|
-
internal_apply(files)
|
13
|
+
::Avm::Files::Formatter::Utf8Assert.assert_files(files) { internal_apply(files) }
|
13
14
|
files.map { |f| build_file_result(f, old_content[f]) }
|
14
15
|
end
|
15
16
|
|
@@ -49,8 +50,10 @@ module Avm
|
|
49
50
|
end
|
50
51
|
|
51
52
|
def match_by_type?(file)
|
52
|
-
|
53
|
-
|
53
|
+
info = ::Avm::Files::Info.new(file)
|
54
|
+
return unless info.content_type.type == 'text'
|
55
|
+
|
56
|
+
valid_types.include?(info.content_type.subtype)
|
54
57
|
end
|
55
58
|
end
|
56
59
|
end
|
@@ -7,10 +7,10 @@ module Avm
|
|
7
7
|
class Formatter
|
8
8
|
module Formats
|
9
9
|
class GenericPlain < ::Avm::Files::Formatter::Formats::PerFileBase
|
10
|
-
VALID_EXTENSIONS = %w[.bat .css.coffee .java .js .json .
|
10
|
+
VALID_EXTENSIONS = %w[.bat .css.coffee .java .js .json .rb .scss .sql .tex .url .yml
|
11
11
|
.yaml].freeze
|
12
12
|
|
13
|
-
VALID_TYPES = [
|
13
|
+
VALID_TYPES = %w[plain x-shellscript].freeze
|
14
14
|
|
15
15
|
def internal_apply(files)
|
16
16
|
files.each { |file| file_apply(file) }
|
@@ -9,7 +9,7 @@ module Avm
|
|
9
9
|
module Formats
|
10
10
|
class Php < ::Avm::Files::Formatter::Formats::PerFileBase
|
11
11
|
VALID_EXTENSIONS = %w[.php].freeze
|
12
|
-
VALID_TYPES = ['
|
12
|
+
VALID_TYPES = ['x-php'].freeze
|
13
13
|
|
14
14
|
def file_apply(file)
|
15
15
|
::Avm::Executables.php_cs_fixer.command.append(['fix', file]).system!
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Avm
|
4
|
+
module Files
|
5
|
+
class Formatter
|
6
|
+
class Utf8Assert
|
7
|
+
UTF8_CHARSET = 'utf-8'
|
8
|
+
UTF8_CHARSETS = [UTF8_CHARSET, 'us-ascii'].freeze
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def assert_files(files)
|
12
|
+
asserters = files.map { |file| new(file) }
|
13
|
+
begin
|
14
|
+
asserters.each(&:assert)
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
asserters.each(&:revert)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
enable_simple_cache
|
23
|
+
common_constructor :path
|
24
|
+
|
25
|
+
def assert
|
26
|
+
return if original_utf8?
|
27
|
+
|
28
|
+
convert_self(original_charset, UTF8_CHARSET)
|
29
|
+
end
|
30
|
+
|
31
|
+
def revert
|
32
|
+
return if original_utf8?
|
33
|
+
|
34
|
+
convert_self(UTF8_CHARSET, original_charset)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def original_info_uncached
|
40
|
+
::Avm::Files::Info.new(path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def original_charset_uncached
|
44
|
+
return original_info.content_type.charset if original_info.content_type.charset.present?
|
45
|
+
|
46
|
+
raise 'No charset found'
|
47
|
+
rescue StandardError => e
|
48
|
+
raise "Unable to determine the charset of #{path} (#{e.message})"
|
49
|
+
end
|
50
|
+
|
51
|
+
def original_utf8?
|
52
|
+
UTF8_CHARSETS.include?(original_charset)
|
53
|
+
end
|
54
|
+
|
55
|
+
def convert_file(from_path, from_charset, to_path, to_charset)
|
56
|
+
File.open(from_path, "r:#{from_charset}") do |input|
|
57
|
+
File.open(to_path, "w:#{to_charset}") do |output|
|
58
|
+
output.write(input.read)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def convert_self(from_charset, to_charset)
|
64
|
+
temp = ::Tempfile.new
|
65
|
+
temp.close
|
66
|
+
convert_file(path, from_charset, temp.path, to_charset)
|
67
|
+
::FileUtils.mv(temp.path, path)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'avm/executables'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
require 'content-type'
|
6
|
+
|
7
|
+
module Avm
|
8
|
+
module Files
|
9
|
+
class Info
|
10
|
+
enable_simple_cache
|
11
|
+
common_constructor :path
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def content_type_uncached
|
16
|
+
::ContentType.parse(
|
17
|
+
::Avm::Executables.file.command.append(['-ib', path]).execute!.strip
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/avm/tools/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: avm-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.37.
|
4
|
+
version: 0.37.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
@@ -44,6 +44,20 @@ dependencies:
|
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 1.3.3
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: content-type
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.0.1
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.0.1
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: eac_launcher
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -201,6 +215,8 @@ files:
|
|
201
215
|
- lib/avm/files/formatter/formats/generic_plain.rb
|
202
216
|
- lib/avm/files/formatter/formats/per_file_base.rb
|
203
217
|
- lib/avm/files/formatter/formats/php.rb
|
218
|
+
- lib/avm/files/formatter/utf8_assert.rb
|
219
|
+
- lib/avm/files/info.rb
|
204
220
|
- lib/avm/files/rotate.rb
|
205
221
|
- lib/avm/fs_cache.rb
|
206
222
|
- lib/avm/git.rb
|