eac_ruby_utils 0.63.0 → 0.64.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_ruby_utils/envs/command.rb +10 -5
- data/lib/eac_ruby_utils/patches/module/common_concern.rb +0 -1
- data/lib/eac_ruby_utils/rspec/conditional.rb +1 -4
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +2 -66
- 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,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
|