eac_ruby_utils 0.60.0 → 0.64.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/eac_ruby_utils/envs/command.rb +10 -5
  3. data/lib/eac_ruby_utils/filesystem_cache.rb +6 -0
  4. data/lib/eac_ruby_utils/fs/logs.rb +63 -0
  5. data/lib/eac_ruby_utils/inflector.rb +9 -1
  6. data/lib/eac_ruby_utils/listable/list.rb +3 -2
  7. data/lib/eac_ruby_utils/patches/kernel/nyi.rb +4 -2
  8. data/lib/eac_ruby_utils/patches/module/common_concern.rb +0 -1
  9. data/lib/eac_ruby_utils/patches/regexp/to_parser.rb +10 -0
  10. data/lib/eac_ruby_utils/patches/string/inflector.rb +4 -2
  11. data/lib/eac_ruby_utils/regexp_parser.rb +34 -0
  12. data/lib/eac_ruby_utils/rspec/conditional.rb +1 -4
  13. data/lib/eac_ruby_utils/simple_cache.rb +18 -5
  14. data/lib/eac_ruby_utils/version.rb +1 -1
  15. metadata +13 -66
  16. data/lib/eac_ruby_utils/configs.rb +0 -74
  17. data/lib/eac_ruby_utils/configs/base.rb +0 -43
  18. data/lib/eac_ruby_utils/configs/file.rb +0 -47
  19. data/lib/eac_ruby_utils/console.rb +0 -5
  20. data/lib/eac_ruby_utils/console/configs.rb +0 -38
  21. data/lib/eac_ruby_utils/console/configs/entry_reader.rb +0 -81
  22. data/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +0 -18
  23. data/lib/eac_ruby_utils/console/configs/read_entry_options.rb +0 -46
  24. data/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +0 -27
  25. data/lib/eac_ruby_utils/console/docopt_runner.rb +0 -45
  26. data/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +0 -18
  27. data/lib/eac_ruby_utils/console/docopt_runner/_doc.rb +0 -25
  28. data/lib/eac_ruby_utils/console/docopt_runner/_settings.rb +0 -19
  29. data/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +0 -154
  30. data/lib/eac_ruby_utils/console/speaker.rb +0 -133
  31. data/lib/eac_ruby_utils/console/speaker/_class_methods.rb +0 -39
  32. data/lib/eac_ruby_utils/console/speaker/_constants.rb +0 -14
  33. data/lib/eac_ruby_utils/console/speaker/list.rb +0 -63
  34. data/lib/eac_ruby_utils/console/speaker/node.rb +0 -26
  35. data/lib/eac_ruby_utils/patches/module/console_speaker.rb +0 -10
  36. data/lib/eac_ruby_utils/patches/module/template.rb +0 -10
  37. data/lib/eac_ruby_utils/patches/object/template.rb +0 -9
  38. data/lib/eac_ruby_utils/paths_hash.rb +0 -56
  39. data/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +0 -8
  40. data/lib/eac_ruby_utils/paths_hash/node.rb +0 -67
  41. data/lib/eac_ruby_utils/paths_hash/path_search.rb +0 -39
  42. data/lib/eac_ruby_utils/templates.rb +0 -9
  43. data/lib/eac_ruby_utils/templates/directory.rb +0 -110
  44. data/lib/eac_ruby_utils/templates/file.rb +0 -50
  45. data/lib/eac_ruby_utils/templates/searcher.rb +0 -55
  46. data/lib/eac_ruby_utils/templates/variable_not_found_error.rb +0 -7
  47. data/lib/eac_ruby_utils/templates/variable_providers.rb +0 -25
  48. data/lib/eac_ruby_utils/templates/variable_providers/base.rb +0 -23
  49. data/lib/eac_ruby_utils/templates/variable_providers/entries_reader.rb +0 -25
  50. data/lib/eac_ruby_utils/templates/variable_providers/generic.rb +0 -25
  51. data/lib/eac_ruby_utils/templates/variable_providers/hash.rb +0 -29
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/patches/object/if_present'
4
- require 'eac_ruby_utils/console/speaker/_constants'
5
-
6
- module EacRubyUtils
7
- module Console
8
- module Speaker
9
- class Node
10
- attr_accessor :stdin, :stdout, :stderr, :stderr_line_prefix
11
-
12
- def initialize(parent = nil)
13
- self.stdin = parent.if_present(::EacRubyUtils::Console::Speaker::STDIN, &:stdin)
14
- self.stdout = parent.if_present(::EacRubyUtils::Console::Speaker::STDOUT, &:stdout)
15
- self.stderr = parent.if_present(::EacRubyUtils::Console::Speaker::STDERR, &:stderr)
16
- self.stderr_line_prefix = parent.if_present('', &:stderr_line_prefix)
17
- end
18
-
19
- def configure
20
- yield(self)
21
- self
22
- end
23
- end
24
- end
25
- end
26
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/patch'
4
- require 'eac_ruby_utils/console/speaker'
5
-
6
- class Module
7
- def enable_console_speaker
8
- ::EacRubyUtils.patch(self, ::EacRubyUtils::Console::Speaker)
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/core_ext/string/inflections'
4
- require 'eac_ruby_utils/templates/searcher'
5
-
6
- class Module
7
- def template
8
- @template ||= ::EacRubyUtils::Templates::Searcher.default.template(name.underscore)
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/patches/module/template'
4
-
5
- class Object
6
- def template
7
- self.class.template
8
- end
9
- end
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
-
5
- module EacRubyUtils
6
- class PathsHash
7
- require_sub __FILE__
8
-
9
- class << self
10
- def parse_entry_key(entry_key)
11
- r = entry_key.to_s.strip
12
- raise ::EacRubyUtils::PathsHash::EntryKeyError, 'Entry key cannot start or end with dot' if
13
- r.start_with?('.') || r.end_with?('.')
14
-
15
- r = r.split('.').map(&:strip)
16
- if r.empty?
17
- raise ::EacRubyUtils::PathsHash::EntryKeyError, "Entry key \"#{entry_key}\" is empty"
18
- end
19
- return r.map(&:to_sym) unless r.any?(&:blank?)
20
-
21
- raise ::EacRubyUtils::PathsHash::EntryKeyError,
22
- "Entry key \"#{entry_key}\" has at least one blank part"
23
- end
24
- end
25
-
26
- attr_reader :root
27
-
28
- def initialize(source_hash = {})
29
- @root = Node.new(source_hash)
30
- end
31
-
32
- def [](entry_key)
33
- root.read_entry(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
34
- end
35
-
36
- def []=(entry_key, entry_value)
37
- root.write_entry(
38
- ::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key), entry_value
39
- )
40
- end
41
-
42
- def fetch(entry_key)
43
- root.fetch(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
44
- end
45
-
46
- def key?(entry_key)
47
- root.entry?(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
48
- end
49
-
50
- delegate :to_h, to: :root
51
-
52
- private
53
-
54
- attr_reader :data
55
- end
56
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module EacRubyUtils
4
- class PathsHash
5
- class EntryKeyError < StandardError
6
- end
7
- end
8
- end
@@ -1,67 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/core_ext'
4
- require 'eac_ruby_utils/paths_hash/entry_key_error'
5
-
6
- module EacRubyUtils
7
- class PathsHash
8
- class Node
9
- PATH_SEARCH_UNENDED_ERROR_MESSAGE = 'Path search is not a Node and is not ended'
10
-
11
- def initialize(source_hash)
12
- source_hash.assert_argument(Hash, 'source_hash')
13
- @data = source_hash.map { |k, v| [k.to_sym, v.is_a?(Hash) ? Node.new(v) : v] }.to_h
14
- end
15
-
16
- def entry?(path_search)
17
- return false unless data.key?(path_search.cursor)
18
- return true if path_search.ended?
19
- return data.fetch(path_search.cursor).entry?(path_search.succeeding) if
20
- data.fetch(path_search.cursor).is_a?(Node)
21
-
22
- false # Paths continue and there is not available nodes
23
- end
24
-
25
- def fetch(path_search)
26
- if data.key?(path_search.cursor)
27
- node = data.fetch(path_search.cursor)
28
- return (node.is_a?(Node) ? node.to_h : node) if path_search.ended?
29
- return nil if node.blank?
30
- return node.fetch(path_search.succeeding) if node.is_a?(Node)
31
- end
32
-
33
- path_search.raise_error(PATH_SEARCH_UNENDED_ERROR_MESSAGE)
34
- end
35
-
36
- def to_h
37
- data.map { |k, v| [k, v.is_a?(Node) ? v.to_h : v] }.to_h
38
- end
39
-
40
- def read_entry(path_search)
41
- node = data[path_search.cursor]
42
- return (node.is_a?(Node) ? node.to_h : node) if path_search.ended?
43
- return nil if node.blank?
44
- return node.read_entry(path_search.succeeding) if node.is_a?(Node)
45
-
46
- path_search.raise_error(PATH_SEARCH_UNENDED_ERROR_MESSAGE)
47
- end
48
-
49
- def write_entry(path_search, value)
50
- if path_search.ended?
51
- data[path_search.cursor] = value.is_a?(Hash) ? self.class.new(value) : value
52
- else
53
- assert_data_node(path_search.cursor).write_entry(path_search.succeeding, value)
54
- end
55
- end
56
-
57
- private
58
-
59
- attr_reader :data
60
-
61
- def assert_data_node(key)
62
- data[key] = self.class.new({}) unless data[key].is_a?(Node)
63
- data[key]
64
- end
65
- end
66
- end
67
- end
@@ -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,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/require_sub'
4
-
5
- module Avm
6
- module Templates
7
- ::EacRubyUtils.require_sub(__FILE__)
8
- end
9
- 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