avm-tools 0.34.0 → 0.35.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: bc93a50b713fa65d2893cb05c7a38feab44295c625011c6597d5aeaaf866ccf9
4
- data.tar.gz: 67ab9170e9c7e780bf839d0bdb1d5ebe4edb91e2d46b08af22a46c5bfb2c93c6
3
+ metadata.gz: b2dfc6aad10cade7a84fad01d04a2ca982bfeb9d20f8c5efcf1253c14876d964
4
+ data.tar.gz: b5a79cb9c4d62f8cefb1954fd79ee353ab928f9a2b1042e681a962390762bfe3
5
5
  SHA512:
6
- metadata.gz: d6f5008949bde37c4f319aea45a7676b7acc314408154fabe3ace835206dd44f988cd6593e6b571291898bc659fcd013f3d43e49807f9046233f5c028f4894d6
7
- data.tar.gz: d9db915b89d71139af123feab08e08e3a4743a866d3895c9fbedb5b61def92e64d0509c9e7bb7fffbc56f76fdf7239087ef26810d7b80cd6155513d25ea75a82
6
+ metadata.gz: a3c5a134d6bff614af0aa153248c3952b5f043b590b666e2d3421a1477b2a180c69c2af864773e558af825d1f6e720ee8d56fbb13dd2c8c71782be3dedc7ba71
7
+ data.tar.gz: 47734387f9fbb75a13c734b96bf2c45d5fcd8baf464db24a0af32fc3e2c9e4813c60ffd3d3ff53237770db341ff8a1baf6c847e24909d3813cc5dcb44b1656e9
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_ruby_utils/filesystem_traverser'
5
+
6
+ module Avm
7
+ module Files
8
+ class Formatter
9
+ require_sub __FILE__
10
+ enable_simple_cache
11
+ enable_console_speaker
12
+ common_constructor :source_paths, :options
13
+
14
+ FORMATS = %w[generic_plain].freeze
15
+
16
+ def run
17
+ clear
18
+ search_files
19
+ apply
20
+ show_results
21
+ end
22
+
23
+ private
24
+
25
+ def apply
26
+ infom "Applying #{@formats_files.count} format(s)... "
27
+ @formats_files.each do |format, files|
28
+ infom "Applying format #{format.name} (Files matched: #{files.count})..."
29
+ next unless options.fetch(:apply)
30
+
31
+ @result += format.apply(files)
32
+ end
33
+ end
34
+
35
+ def check_file(file)
36
+ format = find_format(file)
37
+ infov file, format ? format.class : '-' if options.fetch(:verbose)
38
+ return unless format
39
+
40
+ @formats_files[format] ||= []
41
+ @formats_files[format] << file
42
+ end
43
+
44
+ def clear
45
+ @formats_files = {}
46
+ @result = []
47
+ end
48
+
49
+ def find_format(file)
50
+ formats.each do |c|
51
+ return c if c.match?(file)
52
+ end
53
+ nil
54
+ end
55
+
56
+ def formats_uncached
57
+ FORMATS.map do |identifier|
58
+ "avm/files/formatter/formats/#{identifier}".camelize.constantize.new
59
+ end
60
+ end
61
+
62
+ def fs_traverser_uncached
63
+ r = ::EacRubyUtils::FilesystemTraverser.new
64
+ r.check_file = method(:check_file)
65
+ r.recursive = options.fetch(:recursive)
66
+ r
67
+ end
68
+
69
+ def search_files
70
+ infov 'Directories to search', source_paths.count
71
+ source_paths.each do |source_path|
72
+ infom "Searching files on \"#{source_path}\"..."
73
+ fs_traverser.check_path(source_path)
74
+ end
75
+ end
76
+
77
+ def show_results
78
+ changed = @result.select(&:changed)
79
+ changed.each do |h|
80
+ out h.file.t_s.cyan
81
+ out " (#{h.format})".yellow
82
+ puts ' changed'.green
83
+ end
84
+ infov('Files changed', "#{changed.count}/#{@result.count}")
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Files
7
+ class Formatter
8
+ module Formats
9
+ require_sub __FILE__
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
5
+ module Avm
6
+ module Files
7
+ class Formatter
8
+ module Formats
9
+ class Base
10
+ def apply(files)
11
+ old_content = Hash[files.map { |f| [f, File.read(f)] }]
12
+ internal_apply(files)
13
+ files.map { |f| build_file_result(f, old_content[f]) }
14
+ end
15
+
16
+ def name
17
+ self.class.name.demodulize
18
+ end
19
+
20
+ def match?(file)
21
+ match_by_extension?(file) || match_by_type?(file)
22
+ end
23
+
24
+ def valid_extensions
25
+ constant_or_array('VALID_EXTENSIONS')
26
+ end
27
+
28
+ def valid_types
29
+ constant_or_array('VALID_TYPES')
30
+ end
31
+
32
+ private
33
+
34
+ def constant_or_array(name)
35
+ return [] unless self.class.const_defined?(name)
36
+
37
+ self.class.const_get(name)
38
+ end
39
+
40
+ def build_file_result(file, old_content)
41
+ ::OpenStruct.new(file: file, format: self.class,
42
+ changed: (old_content != File.read(file)))
43
+ end
44
+
45
+ def match_by_extension?(file)
46
+ valid_extensions.any? do |valid_extension|
47
+ file.extname.ends_with?(valid_extension)
48
+ end
49
+ end
50
+
51
+ def match_by_type?(file)
52
+ file_type = ::EacRubyUtils::Envs.local.command('file', '-b', file).execute!
53
+ valid_types.find { |t| file_type.include?(t) }
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/files/formatter/formats/base'
4
+
5
+ module Avm
6
+ module Files
7
+ class Formatter
8
+ module Formats
9
+ class GenericPlain < ::Avm::Files::Formatter::Formats::Base
10
+ VALID_EXTENSIONS = %w[.bat .css.coffee .java .js .json .php .rb .scss .sql .tex .url .yml
11
+ .yaml].freeze
12
+
13
+ VALID_TYPES = ['Bourne-Again shell script', 'ASCII text', 'UTF-8 Unicode text'].freeze
14
+
15
+ def internal_apply(files)
16
+ files.each { |file| file_apply(file) }
17
+ end
18
+
19
+ def file_apply(file)
20
+ file.write(string_apply(file.read))
21
+ end
22
+
23
+ def string_apply(string)
24
+ b = ''
25
+ string.each_line do |line|
26
+ b += "#{line.rstrip}\n"
27
+ end
28
+ "#{b.strip}\n".gsub(/\t/, ' ')
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -9,7 +9,7 @@ module Avm
9
9
 
10
10
  lists.add_string :type, :success, :error, :neutral
11
11
 
12
- lists.type.values.each do |type|
12
+ lists.type.values.each do |type| # rubocop:disable Style/HashEachMethods
13
13
  class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
14
14
  def self.#{type}(value)
15
15
  new(value, TYPE_#{type.upcase})
@@ -51,7 +51,7 @@ module Avm
51
51
  self.class.const_get("type_#{type}_color".upcase)
52
52
  end
53
53
 
54
- lists.type.values.each do |type|
54
+ lists.type.values.each do |type| # rubocop:disable Style/HashEachMethods
55
55
  class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
56
56
  def #{type}?
57
57
  @type == '#{type}'
@@ -11,7 +11,7 @@ module Avm
11
11
 
12
12
  def on_clean_envvars(*start_with_vars)
13
13
  old_values = envvars_starting_with(start_with_vars)
14
- old_values.keys.each { |k| ENV.delete(k) }
14
+ old_values.keys.each { |k| ENV.delete(k) } # rubocop:disable Style/HashEachMethods
15
15
  yield
16
16
  ensure
17
17
  old_values&.each { |k, v| ENV[k] = v }
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/console/docopt_runner'
4
- require 'avm/tools/runner/files/rotate'
4
+ require 'eac_ruby_utils/core_ext'
5
5
 
6
6
  module Avm
7
7
  module Tools
8
8
  class Runner < ::EacRubyUtils::Console::DocoptRunner
9
9
  class Files < ::EacRubyUtils::Console::DocoptRunner
10
+ require_sub __FILE__
11
+
10
12
  DOC = <<~DOCOPT
11
13
  Files utilities for AVM.
12
14
 
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/files/formatter'
4
+ require 'eac_ruby_utils/console/docopt_runner'
5
+ require 'eac_ruby_utils/core_ext'
6
+
7
+ module Avm
8
+ module Tools
9
+ class Runner < ::EacRubyUtils::Console::DocoptRunner
10
+ class Files < ::EacRubyUtils::Console::DocoptRunner
11
+ class Format < ::EacRubyUtils::Console::DocoptRunner
12
+ include ::EacRubyUtils::Console::Speaker
13
+
14
+ DOC = <<~DOCOPT
15
+ Format files.
16
+
17
+ Usage:
18
+ __PROGRAM__ [options] [<paths>...]
19
+ __PROGRAM__ -h | --help
20
+
21
+ Options:
22
+ -h --help Show this screen.
23
+ -a --apply Confirm changes.
24
+ -n --no-recursive No recursive.
25
+ -v --verbose Verbose
26
+ DOCOPT
27
+
28
+ def run
29
+ ::Avm::Files::Formatter.new(source_paths, formatter_options).run
30
+ end
31
+
32
+ def formatter_options
33
+ { apply: options.fetch('--apply'), recursive: !options.fetch('--no-recursive'),
34
+ verbose: options.fetch('--verbose') }
35
+ end
36
+
37
+ def source_paths
38
+ options.fetch('<paths>').if_present(%w[.])
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.34.0'
5
+ VERSION = '0.35.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.0
4
+ version: 0.35.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-27 00:00:00.000000000 Z
11
+ date: 2020-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aranha-parsers
@@ -76,20 +76,14 @@ dependencies:
76
76
  requirements:
77
77
  - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: '0.18'
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 0.18.1
79
+ version: '0.22'
83
80
  type: :runtime
84
81
  prerelease: false
85
82
  version_requirements: !ruby/object:Gem::Requirement
86
83
  requirements:
87
84
  - - "~>"
88
85
  - !ruby/object:Gem::Version
89
- version: '0.18'
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: 0.18.1
86
+ version: '0.22'
93
87
  - !ruby/object:Gem::Dependency
94
88
  name: filesize
95
89
  requirement: !ruby/object:Gem::Requirement
@@ -136,16 +130,16 @@ dependencies:
136
130
  name: rubocop
137
131
  requirement: !ruby/object:Gem::Requirement
138
132
  requirements:
139
- - - "~>"
133
+ - - '='
140
134
  - !ruby/object:Gem::Version
141
- version: 0.79.0
135
+ version: 0.80.1
142
136
  type: :development
143
137
  prerelease: false
144
138
  version_requirements: !ruby/object:Gem::Requirement
145
139
  requirements:
146
- - - "~>"
140
+ - - '='
147
141
  - !ruby/object:Gem::Version
148
- version: 0.79.0
142
+ version: 0.80.1
149
143
  - !ruby/object:Gem::Dependency
150
144
  name: rubocop-rspec
151
145
  requirement: !ruby/object:Gem::Requirement
@@ -193,6 +187,10 @@ files:
193
187
  - lib/avm/docker/runner.rb
194
188
  - lib/avm/executables.rb
195
189
  - lib/avm/files.rb
190
+ - lib/avm/files/formatter.rb
191
+ - lib/avm/files/formatter/formats.rb
192
+ - lib/avm/files/formatter/formats/base.rb
193
+ - lib/avm/files/formatter/formats/generic_plain.rb
196
194
  - lib/avm/files/rotate.rb
197
195
  - lib/avm/fs_cache.rb
198
196
  - lib/avm/git.rb
@@ -289,6 +287,7 @@ files:
289
287
  - lib/avm/tools/runner/eac_wordpress_base0/data.rb
290
288
  - lib/avm/tools/runner/eac_wordpress_base0/deploy.rb
291
289
  - lib/avm/tools/runner/files.rb
290
+ - lib/avm/tools/runner/files/format.rb
292
291
  - lib/avm/tools/runner/files/rotate.rb
293
292
  - lib/avm/tools/runner/git.rb
294
293
  - lib/avm/tools/runner/git/auto_fixup.rb