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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/eac_ruby_utils/envs/command.rb +10 -5
  3. data/lib/eac_ruby_utils/patches/module/common_concern.rb +0 -1
  4. data/lib/eac_ruby_utils/rspec/conditional.rb +1 -4
  5. data/lib/eac_ruby_utils/version.rb +1 -1
  6. metadata +2 -66
  7. data/lib/eac_ruby_utils/configs.rb +0 -74
  8. data/lib/eac_ruby_utils/configs/base.rb +0 -43
  9. data/lib/eac_ruby_utils/configs/file.rb +0 -47
  10. data/lib/eac_ruby_utils/console.rb +0 -5
  11. data/lib/eac_ruby_utils/console/configs.rb +0 -38
  12. data/lib/eac_ruby_utils/console/configs/entry_reader.rb +0 -81
  13. data/lib/eac_ruby_utils/console/configs/password_entry_reader.rb +0 -18
  14. data/lib/eac_ruby_utils/console/configs/read_entry_options.rb +0 -46
  15. data/lib/eac_ruby_utils/console/configs/store_passwords_entry_reader.rb +0 -27
  16. data/lib/eac_ruby_utils/console/docopt_runner.rb +0 -45
  17. data/lib/eac_ruby_utils/console/docopt_runner/_class_methods.rb +0 -18
  18. data/lib/eac_ruby_utils/console/docopt_runner/_doc.rb +0 -25
  19. data/lib/eac_ruby_utils/console/docopt_runner/_settings.rb +0 -19
  20. data/lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb +0 -154
  21. data/lib/eac_ruby_utils/console/speaker.rb +0 -133
  22. data/lib/eac_ruby_utils/console/speaker/_class_methods.rb +0 -39
  23. data/lib/eac_ruby_utils/console/speaker/_constants.rb +0 -14
  24. data/lib/eac_ruby_utils/console/speaker/list.rb +0 -63
  25. data/lib/eac_ruby_utils/console/speaker/node.rb +0 -26
  26. data/lib/eac_ruby_utils/patches/module/console_speaker.rb +0 -10
  27. data/lib/eac_ruby_utils/patches/module/template.rb +0 -10
  28. data/lib/eac_ruby_utils/patches/object/template.rb +0 -9
  29. data/lib/eac_ruby_utils/paths_hash.rb +0 -56
  30. data/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +0 -8
  31. data/lib/eac_ruby_utils/paths_hash/node.rb +0 -67
  32. data/lib/eac_ruby_utils/paths_hash/path_search.rb +0 -39
  33. data/lib/eac_ruby_utils/templates.rb +0 -9
  34. data/lib/eac_ruby_utils/templates/directory.rb +0 -110
  35. data/lib/eac_ruby_utils/templates/file.rb +0 -50
  36. data/lib/eac_ruby_utils/templates/searcher.rb +0 -55
  37. data/lib/eac_ruby_utils/templates/variable_not_found_error.rb +0 -7
  38. data/lib/eac_ruby_utils/templates/variable_providers.rb +0 -25
  39. data/lib/eac_ruby_utils/templates/variable_providers/base.rb +0 -23
  40. data/lib/eac_ruby_utils/templates/variable_providers/entries_reader.rb +0 -25
  41. data/lib/eac_ruby_utils/templates/variable_providers/generic.rb +0 -25
  42. data/lib/eac_ruby_utils/templates/variable_providers/hash.rb +0 -29
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/console/speaker/node'
4
-
5
- module EacRubyUtils
6
- module Console
7
- module Speaker
8
- class << self
9
- def current_node
10
- nodes_stack.last
11
- end
12
-
13
- def on_node(&block)
14
- push
15
- yield(*(block.arity.zero? ? [] : [current_node]))
16
- ensure
17
- pop
18
- end
19
-
20
- def push
21
- nodes_stack << ::EacRubyUtils::Console::Speaker::Node.new
22
- current_node
23
- end
24
-
25
- def pop
26
- return nodes_stack.pop if nodes_stack.count > 1
27
-
28
- raise "Cannot remove first node (nodes_stack.count: #{nodes_stack.count})"
29
- end
30
-
31
- private
32
-
33
- def nodes_stack
34
- @nodes_stack ||= [::EacRubyUtils::Console::Speaker::Node.new]
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'eac_ruby_utils/by_reference'
4
-
5
- module EacRubyUtils
6
- module Console
7
- # https://github.com/fazibear/colorize
8
- module Speaker
9
- STDERR = ::EacRubyUtils::ByReference.new { $stderr }
10
- STDIN = ::EacRubyUtils::ByReference.new { $stdin }
11
- STDOUT = ::EacRubyUtils::ByReference.new { $stdout }
12
- end
13
- end
14
- end
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/hash_with_indifferent_access'
4
- require 'ostruct'
5
-
6
- module EacRubyUtils
7
- module Console
8
- module Speaker
9
- class List
10
- class << self
11
- def build(list)
12
- return List.new(hash_to_values(list)) if list.is_a?(::Hash)
13
- return List.new(array_to_values(list)) if list.is_a?(::Array)
14
-
15
- raise "Invalid list: #{list} (#{list.class})"
16
- end
17
-
18
- private
19
-
20
- def hash_to_values(list)
21
- list.map { |key, value| ::OpenStruct.new(key: key, label: key, value: value) }
22
- end
23
-
24
- def array_to_values(list)
25
- list.map { |value| ::OpenStruct.new(key: value, label: value, value: value) }
26
- end
27
- end
28
-
29
- attr_reader :values
30
-
31
- def initialize(values)
32
- @values = values.map do |v|
33
- ::OpenStruct.new(key: to_key(v.key), label: to_label(v.label), value: v.value)
34
- end
35
- end
36
-
37
- def valid_labels
38
- values.map(&:label)
39
- end
40
-
41
- def valid_value?(value)
42
- values.any? { |v| v.key == to_key(value) }
43
- end
44
-
45
- def to_key(value)
46
- to_label(value).downcase
47
- end
48
-
49
- def to_label(value)
50
- value.to_s.strip
51
- end
52
-
53
- def build_value(value)
54
- key = to_key(value)
55
- values.each do |v|
56
- return v.value if v.key == key
57
- end
58
- raise "Value not found: \"#{value}\" (#{values})"
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -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