avm-files 0.3.2 → 0.4.1

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: dd887408e51980ca8bf5ec1c26b79d49036f3d43eb6f5bd52a7054d973a6d57a
4
- data.tar.gz: 0e838cf7cd2b77930b6232d759f6aa2f596d2588c9d3a4f4f9202b443923239e
3
+ metadata.gz: 3085133d00ac94129da5d5e78859c07481852f0069ab0f26e2eb3444fb94702b
4
+ data.tar.gz: d224e3473ce1a5a04600cb7956a2150551f5c9c5b6faeef78d6ece26806ab127
5
5
  SHA512:
6
- metadata.gz: 2aab78001bb900be430fbf7e04e2d5b522de2bae6da1b844c844c9a4159735b80f168015089a8360bc373b543e3737a47aac7afc6c99dc500a4ce507b568bc2d
7
- data.tar.gz: 7cf5a0c53983e7010f72342f55d153b9c89aaf351c516b148912cdeda7f17349bbfcb531aa8799745b958a0252892f5606b36f5d199b51d9dc04960f5fdec9d7
6
+ metadata.gz: dc02d2d6c0b3eaa3f9e2a7c2632a1a6d4d8593a5a57dd1e966fc3494306d0ae14868af2471713a5b423710bd857bd3e4bc0f5691b620065491dc5ca6e1ec2994
7
+ data.tar.gz: 9e48c31f7224c9bfafb7103a03cd854ef4e158a2dd5d289a13391e0ca2082296468031a575a6126015f331baf0abdeea95be3738b01053b20bd9f1abc26812fc
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/core_ext'
4
+ require 'avm/files/text_replacer'
5
+ require 'avm/files/runner_with/filesystem_traverser'
6
+
7
+ module Avm
8
+ module Files
9
+ module RunnerWith
10
+ module FileReplacer
11
+ common_concern do
12
+ include ::Avm::Files::RunnerWith::FilesystemTraverser
13
+ include TopMethods
14
+ end
15
+
16
+ module TopMethods
17
+ def text_replacer
18
+ ::Avm::Files::TextReplacer.new
19
+ end
20
+
21
+ def replace_file?(_file)
22
+ true
23
+ end
24
+
25
+ def traverser_check_file(file)
26
+ return unless replace_file?(file)
27
+
28
+ infov 'Changed', file if text_replacer.file_apply(file)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_cli/runner'
4
+ require 'eac_fs/traversable'
5
+ require 'eac_ruby_utils/core_ext'
6
+ require 'eac_ruby_utils/settings_provider'
7
+
8
+ module Avm
9
+ module Files
10
+ module RunnerWith
11
+ module FilesystemTraverser
12
+ DEFAULT_DEFAULT_TRAVERSER_RECURSIVE = false
13
+
14
+ common_concern do
15
+ include ::EacCli::Runner
16
+ include ::EacFs::Traversable
17
+ enable_settings_provider
18
+ include TopMethods
19
+ runner_definition do
20
+ bool_opt '-R', '--recursive', 'Recursive.'
21
+ bool_opt '--no-recursive', 'No recursive.'
22
+ pos_arg :paths, optional: true, repeat: true
23
+ end
24
+ end
25
+
26
+ module TopMethods
27
+ def on_none_path_informed
28
+ infom 'Warning: none path informed'
29
+ end
30
+
31
+ def paths
32
+ parsed.paths.map(&:to_pathname)
33
+ end
34
+
35
+ def run_filesystem_traverser
36
+ if parsed.paths.any?
37
+ parsed.paths.each { |path| traverser_check_path(path) }
38
+ else
39
+ on_none_path_informed
40
+ end
41
+ end
42
+
43
+ def traverser_recursive
44
+ return false if parsed.no_recursive?
45
+ return true if parsed.recursive?
46
+
47
+ setting_value(:default_traverser_recursive, required: false)
48
+ .if_not_nil(DEFAULT_DEFAULT_TRAVERSER_RECURSIVE)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Files
7
+ module RunnerWith
8
+ require_sub __FILE__
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Files
7
+ class TextReplacer
8
+ class Gsub
9
+ common_constructor :from, :to do
10
+ self.from = from
11
+ self.to = to
12
+ end
13
+
14
+ def apply(input)
15
+ input.gsub(from, to)
16
+ end
17
+
18
+ def to_s
19
+ "\"#{from}\" => \"#{to}\""
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Files
7
+ class TextReplacer
8
+ require_sub __FILE__
9
+ enable_immutable
10
+
11
+ immutable_accessor :replacement, type: :array
12
+
13
+ def apply(input)
14
+ replacements.inject(input) { |a, e| e.apply(a) }
15
+ end
16
+
17
+ def file_apply(file)
18
+ file = file.to_pathname
19
+ input = file.read
20
+ output = apply(file.read)
21
+ return false if output == input
22
+
23
+ file.write(output)
24
+ true
25
+ end
26
+
27
+ def gsub(from, to)
28
+ replacement(::Avm::Files::TextReplacer::Gsub.new(from, to))
29
+ end
30
+ end
31
+ end
32
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Files
5
- VERSION = '0.3.2'
5
+ VERSION = '0.4.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avm-files
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-06 00:00:00.000000000 Z
11
+ date: 2022-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm
@@ -16,56 +16,82 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.6'
19
+ version: '0.43'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.6'
26
+ version: '0.43'
27
+ - !ruby/object:Gem::Dependency
28
+ name: eac_cli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.28'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.28'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: eac_fs
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0.5'
47
+ version: '0.12'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.12.3
34
51
  type: :runtime
35
52
  prerelease: false
36
53
  version_requirements: !ruby/object:Gem::Requirement
37
54
  requirements:
38
55
  - - "~>"
39
56
  - !ruby/object:Gem::Version
40
- version: '0.5'
57
+ version: '0.12'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.12.3
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: eac_ruby_utils
43
63
  requirement: !ruby/object:Gem::Requirement
44
64
  requirements:
45
65
  - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '0.76'
67
+ version: '0.103'
48
68
  type: :runtime
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '0.76'
74
+ version: '0.103'
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: eac_templates
57
77
  requirement: !ruby/object:Gem::Requirement
58
78
  requirements:
59
79
  - - "~>"
60
80
  - !ruby/object:Gem::Version
61
- version: '0.2'
81
+ version: '0.3'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 0.3.2
62
85
  type: :runtime
63
86
  prerelease: false
64
87
  version_requirements: !ruby/object:Gem::Requirement
65
88
  requirements:
66
89
  - - "~>"
67
90
  - !ruby/object:Gem::Version
68
- version: '0.2'
91
+ version: '0.3'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 0.3.2
69
95
  - !ruby/object:Gem::Dependency
70
96
  name: eac_ruby_gem_support
71
97
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +133,11 @@ files:
107
133
  - lib/avm/files/formatter/formats/ruby.rb
108
134
  - lib/avm/files/formatter/formats/xml.rb
109
135
  - lib/avm/files/formatter/utf8_assert.rb
136
+ - lib/avm/files/runner_with.rb
137
+ - lib/avm/files/runner_with/file_replacer.rb
138
+ - lib/avm/files/runner_with/filesystem_traverser.rb
139
+ - lib/avm/files/text_replacer.rb
140
+ - lib/avm/files/text_replacer/gsub.rb
110
141
  - lib/avm/files/version.rb
111
142
  homepage:
112
143
  licenses: []