eac_ruby_utils 0.62.0 → 0.66.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 +4 -4
- data/lib/eac_ruby_utils/context.rb +31 -0
- data/lib/eac_ruby_utils/contextualizable.rb +12 -7
- data/lib/eac_ruby_utils/envs/command.rb +10 -5
- data/lib/eac_ruby_utils/filesystem_cache.rb +6 -0
- data/lib/eac_ruby_utils/patches/module/common_concern.rb +0 -1
- data/lib/eac_ruby_utils/patches/module/context.rb +11 -0
- data/lib/eac_ruby_utils/patches/regexp/to_parser.rb +10 -0
- data/lib/eac_ruby_utils/regexp_parser.rb +34 -0
- data/lib/eac_ruby_utils/rspec/conditional.rb +1 -4
- data/lib/eac_ruby_utils/simple_cache.rb +18 -5
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +8 -74
- data/lib/eac_ruby_utils/configs.rb +0 -74
- data/lib/eac_ruby_utils/configs/base.rb +0 -43
- data/lib/eac_ruby_utils/configs/file.rb +0 -47
- data/lib/eac_ruby_utils/console.rb +0 -5
- data/lib/eac_ruby_utils/console/configs.rb +0 -38
- data/lib/eac_ruby_utils/console/configs/entry_reader.rb +0 -81
- data/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +0 -18
- data/lib/eac_ruby_utils/console/configs/read_entry_options.rb +0 -46
- data/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +0 -27
- data/lib/eac_ruby_utils/console/docopt_runner.rb +0 -45
- data/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +0 -18
- data/lib/eac_ruby_utils/console/docopt_runner/_doc.rb +0 -25
- data/lib/eac_ruby_utils/console/docopt_runner/_settings.rb +0 -19
- data/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +0 -154
- data/lib/eac_ruby_utils/console/speaker.rb +0 -133
- data/lib/eac_ruby_utils/console/speaker/_class_methods.rb +0 -39
- data/lib/eac_ruby_utils/console/speaker/_constants.rb +0 -14
- data/lib/eac_ruby_utils/console/speaker/list.rb +0 -63
- data/lib/eac_ruby_utils/console/speaker/node.rb +0 -26
- data/lib/eac_ruby_utils/patches/module/console_speaker.rb +0 -10
- data/lib/eac_ruby_utils/patches/module/template.rb +0 -10
- data/lib/eac_ruby_utils/patches/object/template.rb +0 -9
- data/lib/eac_ruby_utils/paths_hash.rb +0 -56
- data/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +0 -8
- data/lib/eac_ruby_utils/paths_hash/node.rb +0 -67
- data/lib/eac_ruby_utils/paths_hash/path_search.rb +0 -39
- data/lib/eac_ruby_utils/templates.rb +0 -9
- data/lib/eac_ruby_utils/templates/directory.rb +0 -110
- data/lib/eac_ruby_utils/templates/file.rb +0 -50
- data/lib/eac_ruby_utils/templates/searcher.rb +0 -55
- data/lib/eac_ruby_utils/templates/variable_not_found_error.rb +0 -7
- data/lib/eac_ruby_utils/templates/variable_providers.rb +0 -25
- data/lib/eac_ruby_utils/templates/variable_providers/base.rb +0 -23
- data/lib/eac_ruby_utils/templates/variable_providers/entries_reader.rb +0 -25
- data/lib/eac_ruby_utils/templates/variable_providers/generic.rb +0 -25
- data/lib/eac_ruby_utils/templates/variable_providers/hash.rb +0 -29
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module EacRubyUtils
|
4
|
-
class PathsHash
|
5
|
-
class PathSearch
|
6
|
-
class << self
|
7
|
-
def parse_entry_key(string)
|
8
|
-
new(::EacRubyUtils::PathsHash.parse_entry_key(string), [])
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
common_constructor :current, :previous do
|
13
|
-
self.current = current.assert_argument(Array, 'current').freeze
|
14
|
-
self.previous = previous.assert_argument(Array, 'previous')
|
15
|
-
raise ::EacRubyUtils::PathsHash::EntryKeyError, 'Current is empty' if current.empty?
|
16
|
-
end
|
17
|
-
|
18
|
-
def cursor
|
19
|
-
current.first
|
20
|
-
end
|
21
|
-
|
22
|
-
def ended?
|
23
|
-
current.count <= 1
|
24
|
-
end
|
25
|
-
|
26
|
-
def raise_error(message)
|
27
|
-
raise ::EacRubyUtils::PathsHash::EntryKeyError, "#{message} (#{self})"
|
28
|
-
end
|
29
|
-
|
30
|
-
def succeeding
|
31
|
-
self.class.new(current[1..-1], previous + [cursor])
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_s
|
35
|
-
"#{self.class}[Current: #{current}, Previous: #{previous}]"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_ruby_utils/templates/file'
|
4
|
-
|
5
|
-
module EacRubyUtils
|
6
|
-
module Templates
|
7
|
-
class Directory
|
8
|
-
TEMPLATE_EXTNAME = '.template'
|
9
|
-
|
10
|
-
attr_reader :path
|
11
|
-
|
12
|
-
def initialize(path)
|
13
|
-
@path = path.is_a?(::Pathname) ? path : ::Pathname.new(path.to_s)
|
14
|
-
end
|
15
|
-
|
16
|
-
def apply(variables_source, directory)
|
17
|
-
TemplateNode.new(self, '.', directory, variables_source).apply
|
18
|
-
end
|
19
|
-
|
20
|
-
def child(subpath)
|
21
|
-
child_path = ::File.join(path, subpath)
|
22
|
-
return ::EacRubyUtils::Templates::File.new(child_path) if ::File.file?(child_path)
|
23
|
-
return ::EacRubyUtils::Templates::Directory.new(child_path) if ::File.directory?(child_path)
|
24
|
-
|
25
|
-
raise "Child \"#{subpath}\" from \"#{path}\" not found"
|
26
|
-
end
|
27
|
-
|
28
|
-
def children
|
29
|
-
path.children.map do |path_child|
|
30
|
-
child(path_child.basename.to_path)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def apply_fs_object(source_relative, target)
|
37
|
-
if ::File.directory?(source_absolute(source_relative))
|
38
|
-
apply_directory(source_relative, target)
|
39
|
-
elsif ::File.file?(source_absolute(source_relative))
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def source_absolute(source_relative)
|
44
|
-
::File.expand_path(source_relative, path)
|
45
|
-
end
|
46
|
-
|
47
|
-
class TemplateNode
|
48
|
-
attr_reader :source_directory, :source_relative, :target_root_directory, :variables_source
|
49
|
-
|
50
|
-
def initialize(source_directory, source_relative, target_root_directory, variables_source)
|
51
|
-
@source_directory = source_directory
|
52
|
-
@source_relative = source_relative
|
53
|
-
@target_root_directory = target_root_directory
|
54
|
-
@variables_source = variables_source
|
55
|
-
end
|
56
|
-
|
57
|
-
def apply
|
58
|
-
if file?
|
59
|
-
apply_file
|
60
|
-
elsif directory?
|
61
|
-
apply_directory
|
62
|
-
else
|
63
|
-
raise "Unknown filesystem type: #{source_absolute}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
|
69
|
-
def apply_directory
|
70
|
-
::FileUtils.mkdir_p(target_absolute)
|
71
|
-
Dir.entries(source_absolute).each do |entry|
|
72
|
-
child(entry).apply unless %w[. ..].include?(entry)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def apply_file
|
77
|
-
if ::File.extname(source_absolute) == TEMPLATE_EXTNAME
|
78
|
-
::EacRubyUtils::Templates::File.new(source_absolute).apply_to_file(
|
79
|
-
variables_source, target_absolute
|
80
|
-
)
|
81
|
-
else
|
82
|
-
::FileUtils.cp(source_absolute, target_absolute)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def child(entry)
|
87
|
-
TemplateNode.new(source_directory, ::File.join(source_relative, entry),
|
88
|
-
target_root_directory, variables_source)
|
89
|
-
end
|
90
|
-
|
91
|
-
def file?
|
92
|
-
::File.file?(source_absolute)
|
93
|
-
end
|
94
|
-
|
95
|
-
def directory?
|
96
|
-
::File.directory?(source_absolute)
|
97
|
-
end
|
98
|
-
|
99
|
-
def source_absolute
|
100
|
-
::File.expand_path(source_relative, source_directory.path)
|
101
|
-
end
|
102
|
-
|
103
|
-
def target_absolute
|
104
|
-
::File.expand_path(source_relative, target_root_directory)
|
105
|
-
.gsub(/#{::Regexp.quote(TEMPLATE_EXTNAME)}\z/, '')
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_ruby_utils/core_ext'
|
4
|
-
require 'eac_ruby_utils/templates/variable_providers'
|
5
|
-
|
6
|
-
module EacRubyUtils
|
7
|
-
module Templates
|
8
|
-
class File
|
9
|
-
VARIABLE_DELIMITER = ::Regexp.quote('%%')
|
10
|
-
VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
|
11
|
-
|
12
|
-
enable_simple_cache
|
13
|
-
common_constructor :path do
|
14
|
-
self.path = path.to_pathname
|
15
|
-
end
|
16
|
-
|
17
|
-
# +variables_provider+ A [Hash] or object which responds to +read_entry(entry_name)+.
|
18
|
-
def apply(variables_source)
|
19
|
-
variables_provider = ::EacRubyUtils::Templates::VariableProviders.build(variables_source)
|
20
|
-
variables.inject(content) do |a, e|
|
21
|
-
a.gsub(variable_pattern(e), variables_provider.variable_value(e).to_s)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def apply_to_file(variables_source, output_file_path)
|
26
|
-
output_file_path.to_pathname.write(apply(variables_source))
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def variables_uncached
|
32
|
-
content.scan(VARIABLE_PATTERN).map(&:first).map do |name|
|
33
|
-
sanitize_variable_name(name)
|
34
|
-
end.to_set
|
35
|
-
end
|
36
|
-
|
37
|
-
def content_uncached
|
38
|
-
path.read
|
39
|
-
end
|
40
|
-
|
41
|
-
def sanitize_variable_name(variable_name)
|
42
|
-
variable_name.to_s.downcase
|
43
|
-
end
|
44
|
-
|
45
|
-
def variable_pattern(name)
|
46
|
-
/#{VARIABLE_DELIMITER}#{::Regexp.quote(name)}#{VARIABLE_DELIMITER}/i
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support/core_ext/object/blank'
|
4
|
-
require 'eac_ruby_utils/templates/directory'
|
5
|
-
require 'eac_ruby_utils/templates/file'
|
6
|
-
|
7
|
-
module EacRubyUtils
|
8
|
-
module Templates
|
9
|
-
class Searcher
|
10
|
-
class << self
|
11
|
-
def default
|
12
|
-
@default ||= new
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def template(subpath, required = true)
|
17
|
-
path = template_path(subpath)
|
18
|
-
if path.blank?
|
19
|
-
return nil unless required
|
20
|
-
|
21
|
-
raise_template_not_found(subpath)
|
22
|
-
end
|
23
|
-
return ::EacRubyUtils::Templates::File.new(path) if ::File.file?(path)
|
24
|
-
return ::EacRubyUtils::Templates::Directory.new(path) if ::File.directory?(path)
|
25
|
-
|
26
|
-
raise 'Invalid branching'
|
27
|
-
end
|
28
|
-
|
29
|
-
# @return The absolute path of template if found, +nil+ otherwise.
|
30
|
-
def template_path(subpath)
|
31
|
-
included_paths.each do |included_path|
|
32
|
-
r = search_template_in_included_path(included_path, subpath)
|
33
|
-
return r if r
|
34
|
-
end
|
35
|
-
nil
|
36
|
-
end
|
37
|
-
|
38
|
-
def included_paths
|
39
|
-
@included_paths ||= ::Set.new
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def raise_template_not_found(subpath)
|
45
|
-
raise "Template not found for subpath \"#{subpath}\"" \
|
46
|
-
" (Included paths: #{included_paths.to_a.join(::File::PATH_SEPARATOR)})"
|
47
|
-
end
|
48
|
-
|
49
|
-
def search_template_in_included_path(included_path, subpath)
|
50
|
-
path = ::File.join(included_path, subpath)
|
51
|
-
::File.exist?(path) ? path : nil
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_ruby_utils/core_ext'
|
4
|
-
|
5
|
-
module EacRubyUtils
|
6
|
-
module Templates
|
7
|
-
module VariableProviders
|
8
|
-
require_sub __FILE__
|
9
|
-
|
10
|
-
PROVIDERS = %w[entries_reader hash generic].map do |name|
|
11
|
-
"eac_ruby_utils/templates/variable_providers/#{name}".camelize.constantize
|
12
|
-
end
|
13
|
-
|
14
|
-
class << self
|
15
|
-
def build(variables_source)
|
16
|
-
PROVIDERS.each do |provider|
|
17
|
-
return provider.new(variables_source) if provider.accept?(variables_source)
|
18
|
-
end
|
19
|
-
|
20
|
-
raise "Variables provider not found for #{variables_source}"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_ruby_utils/templates/variable_not_found_error'
|
4
|
-
|
5
|
-
module EacRubyUtils
|
6
|
-
module Templates
|
7
|
-
module VariableProviders
|
8
|
-
class Base
|
9
|
-
attr_reader :source
|
10
|
-
|
11
|
-
def initialize(source)
|
12
|
-
@source = source
|
13
|
-
end
|
14
|
-
|
15
|
-
def variable_value(name)
|
16
|
-
return variable_fetch(name) if variable_exist?(name)
|
17
|
-
|
18
|
-
raise VariableNotFoundError, "Variable \"#{name}\" not found in #{source}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_ruby_utils/templates/variable_providers/base'
|
4
|
-
|
5
|
-
module EacRubyUtils
|
6
|
-
module Templates
|
7
|
-
module VariableProviders
|
8
|
-
class EntriesReader < ::EacRubyUtils::Templates::VariableProviders::Base
|
9
|
-
class << self
|
10
|
-
def accept?(variables_source)
|
11
|
-
variables_source.respond_to?(:read_entry)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def variable_exist?(_name)
|
16
|
-
true
|
17
|
-
end
|
18
|
-
|
19
|
-
def variable_fetch(name)
|
20
|
-
source.read_entry(name)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_ruby_utils/templates/variable_providers/base'
|
4
|
-
|
5
|
-
module EacRubyUtils
|
6
|
-
module Templates
|
7
|
-
module VariableProviders
|
8
|
-
class Generic < ::EacRubyUtils::Templates::VariableProviders::Base
|
9
|
-
class << self
|
10
|
-
def accept?(variables_source)
|
11
|
-
variables_source.is_a?(::Object)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def variable_exist?(name)
|
16
|
-
source.respond_to?(name)
|
17
|
-
end
|
18
|
-
|
19
|
-
def variable_fetch(name)
|
20
|
-
source.send(name)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_ruby_utils/templates/variable_providers/base'
|
4
|
-
|
5
|
-
module EacRubyUtils
|
6
|
-
module Templates
|
7
|
-
module VariableProviders
|
8
|
-
class Hash < ::EacRubyUtils::Templates::VariableProviders::Base
|
9
|
-
class << self
|
10
|
-
def accept?(variables_source)
|
11
|
-
variables_source.is_a?(::Hash)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def initialize(source)
|
16
|
-
super(source.with_indifferent_access)
|
17
|
-
end
|
18
|
-
|
19
|
-
def variable_exist?(name)
|
20
|
-
source.key?(name)
|
21
|
-
end
|
22
|
-
|
23
|
-
def variable_fetch(name)
|
24
|
-
source.fetch(name)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|