avm-tools 0.72.0 → 0.75.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/lib/avm/{stereotypes/eac_rails_base0.rb → eac_rails_base0.rb} +1 -3
  3. data/lib/avm/eac_rails_base0/instance.rb +2 -5
  4. data/lib/avm/{rails/runners.rb → eac_rails_base1.rb} +2 -4
  5. data/lib/avm/{rails → eac_rails_base1}/instance.rb +8 -3
  6. data/lib/avm/eac_rails_base1/runner.rb +12 -0
  7. data/lib/avm/eac_rails_base1/runner/bundle.rb +28 -0
  8. data/lib/avm/eac_rails_base1/runner/code_runner.rb +28 -0
  9. data/lib/avm/eac_rails_base1/runner_with/bundle.rb +57 -0
  10. data/lib/avm/{stereotypes/rails.rb → eac_redmine_base0.rb} +2 -4
  11. data/lib/avm/eac_redmine_base0/instance.rb +2 -4
  12. data/lib/avm/{stereotypes/eac_ubuntu_base0.rb → eac_ubuntu_base0.rb} +1 -3
  13. data/lib/avm/{stereotypes/eac_webapp_base0.rb → eac_webapp_base0.rb} +1 -3
  14. data/lib/avm/eac_webapp_base0/deploy.rb +17 -40
  15. data/lib/avm/eac_webapp_base0/deploy/build.rb +48 -0
  16. data/lib/avm/eac_webapp_base0/deploy/git_info.rb +13 -0
  17. data/lib/avm/eac_webapp_base0/deploy/version.rb +4 -0
  18. data/lib/avm/eac_webapp_base0/deploy/write_on_target.rb +18 -0
  19. data/lib/avm/eac_webapp_base0/instance.rb +2 -2
  20. data/lib/avm/eac_webapp_base0/runner.rb +12 -0
  21. data/lib/avm/eac_webapp_base0/runner/apache_host.rb +2 -3
  22. data/lib/avm/eac_webapp_base0/runner/data.rb +1 -1
  23. data/lib/avm/eac_webapp_base0/runner/data/dump.rb +1 -1
  24. data/lib/avm/eac_webapp_base0/runner/data/load.rb +1 -1
  25. data/lib/avm/eac_webapp_base0/runner/deploy.rb +4 -16
  26. data/lib/avm/eac_wordpress_base0.rb +9 -0
  27. data/lib/avm/eac_wordpress_base0/apache_host.rb +25 -0
  28. data/lib/avm/eac_wordpress_base0/deploy.rb +10 -0
  29. data/lib/avm/eac_wordpress_base0/instance.rb +24 -0
  30. data/lib/avm/eac_writings_base0.rb +9 -0
  31. data/lib/avm/eac_writings_base0/apache_host.rb +17 -0
  32. data/lib/avm/eac_writings_base0/commons.rb +12 -0
  33. data/lib/avm/eac_writings_base0/deploy.rb +36 -0
  34. data/lib/avm/eac_writings_base0/file_build.rb +45 -0
  35. data/lib/avm/eac_writings_base0/file_build/base_stereotype.rb +19 -0
  36. data/lib/avm/eac_writings_base0/file_build/chapter_index.rb +23 -0
  37. data/lib/avm/eac_writings_base0/file_build/tex_source.rb +33 -0
  38. data/lib/avm/eac_writings_base0/instance.rb +11 -0
  39. data/lib/avm/eac_writings_base0/project.rb +33 -0
  40. data/lib/avm/eac_writings_base0/project_build.rb +117 -0
  41. data/lib/avm/eac_writings_base0/project_build/chapters_content.rb +47 -0
  42. data/lib/avm/eac_writings_base0/project_build/copy_files.rb +42 -0
  43. data/lib/avm/executables.rb +1 -1
  44. data/lib/avm/files/appendable.rb +55 -0
  45. data/lib/avm/files/appendable/file_content.rb +24 -0
  46. data/lib/avm/files/appendable/plain_directory.rb +25 -0
  47. data/lib/avm/files/appendable/resource_base.rb +13 -0
  48. data/lib/avm/files/appendable/tar_output_command.rb +26 -0
  49. data/lib/avm/files/appendable/templatized_directory.rb +28 -0
  50. data/lib/avm/files/appender.rb +11 -0
  51. data/lib/avm/files/deploy.rb +72 -0
  52. data/lib/avm/git/commit/deploy.rb +8 -61
  53. data/lib/avm/instances/base/auto_values.rb +2 -1
  54. data/lib/avm/instances/base/auto_values/mailer.rb +34 -0
  55. data/lib/avm/instances/entry_keys.rb +4 -0
  56. data/lib/avm/instances/runner.rb +40 -0
  57. data/lib/avm/{stereotypes/postgresql.rb → postgresql.rb} +1 -3
  58. data/lib/avm/postgresql/instance.rb +63 -0
  59. data/lib/avm/postgresql/instance/data_unit.rb +39 -0
  60. data/lib/avm/postgresql/instance_with.rb +18 -0
  61. data/lib/avm/projects/stereotypes/git_subtree/publish.rb +2 -0
  62. data/lib/avm/projects/stereotypes/git_subtree/warp.rb +3 -0
  63. data/lib/avm/tools/runner.rb +3 -3
  64. data/lib/avm/tools/runner/eac_rails_base0.rb +5 -18
  65. data/lib/avm/tools/runner/eac_rails_base0/apache_path.rb +1 -1
  66. data/lib/avm/tools/runner/eac_rails_base0/rails_server.rb +7 -12
  67. data/lib/avm/tools/runner/eac_rails_base0/runner.rb +3 -3
  68. data/lib/avm/tools/runner/eac_redmine_base0.rb +5 -23
  69. data/lib/avm/tools/runner/eac_redmine_base0/core_update.rb +1 -1
  70. data/lib/avm/tools/runner/eac_redmine_base0/docker.rb +1 -1
  71. data/lib/avm/tools/runner/eac_redmine_base0/project_rename.rb +3 -3
  72. data/lib/avm/tools/runner/eac_wordpress_base0.rb +5 -24
  73. data/lib/avm/tools/runner/{eac_rails_base0/data.rb → eac_writings_base0.rb} +4 -4
  74. data/lib/avm/tools/runner/git/deploy.rb +1 -1
  75. data/lib/avm/tools/runner/local_project/eac_writings_base0.rb +35 -0
  76. data/lib/avm/tools/runner/local_project/eac_writings_base0/build_chapters.rb +48 -0
  77. data/lib/avm/tools/runner/local_project/eac_writings_base0/build_single.rb +37 -0
  78. data/lib/avm/tools/runner/local_project/eac_writings_base0/info.rb +36 -0
  79. data/lib/avm/tools/version.rb +1 -1
  80. data/template/avm/eac_rails_base0/deploy/config/envvars.d/email.yml.template +11 -0
  81. data/template/avm/{stereotypes/eac_ubuntu_base0 → eac_ubuntu_base0}/docker_image/Dockerfile +0 -0
  82. data/template/avm/{stereotypes/eac_wordpress_base0 → eac_wordpress_base0}/deploy/wp-config.php.template +0 -0
  83. data/template/avm/eac_writings_base0/commons/all.tex +5 -0
  84. data/template/avm/eac_writings_base0/commons/ebook.tex +11 -0
  85. data/template/avm/eac_writings_base0/commons/images.tex +11 -0
  86. data/template/avm/eac_writings_base0/commons/links.tex +2 -0
  87. data/template/avm/eac_writings_base0/commons/portuguese.tex +8 -0
  88. data/template/avm/eac_writings_base0/commons/source_code.tex +21 -0
  89. data/template/avm/eac_writings_base0/commons/source_code/java.tex +15 -0
  90. data/template/avm/eac_writings_base0/commons/utils.tex +6 -0
  91. data/template/avm/eac_writings_base0/deploy/index.html.template +9 -0
  92. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +12 -0
  93. data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
  94. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/blank_not_blank.rb +19 -0
  95. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/base.rb +43 -0
  96. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/configs/file.rb +12 -31
  97. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs.rb +8 -40
  98. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/console/configs/read_entry_options.rb +41 -0
  99. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs/clearable_directory.rb +57 -0
  100. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash.rb +21 -58
  101. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/entry_key_error.rb +8 -0
  102. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/node.rb +67 -0
  103. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/paths_hash/path_search.rb +39 -0
  104. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/struct.rb +4 -0
  105. data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  106. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/blank_not_blank_spec.rb +16 -0
  107. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/configs_spec.rb +15 -0
  108. data/vendor/eac_ruby_utils/spec/lib/eac_ruby_utils/paths_hash_spec.rb +52 -13
  109. metadata +71 -36
  110. data/lib/avm/git/commit/deploy/appended.rb +0 -37
  111. data/lib/avm/git/commit/deploy/appended/base.rb +0 -17
  112. data/lib/avm/git/commit/deploy/appended/directory.rb +0 -32
  113. data/lib/avm/git/commit/deploy/appended/file_content.rb +0 -28
  114. data/lib/avm/rails/runners/bundle.rb +0 -35
  115. data/lib/avm/rails/runners/runner.rb +0 -48
  116. data/lib/avm/stereotypes/eac_redmine_base0.rb +0 -11
  117. data/lib/avm/stereotypes/eac_wordpress_base0/apache_host.rb +0 -27
  118. data/lib/avm/stereotypes/eac_wordpress_base0/deploy.rb +0 -12
  119. data/lib/avm/stereotypes/eac_wordpress_base0/instance.rb +0 -26
  120. data/lib/avm/stereotypes/postgresql/instance.rb +0 -65
  121. data/lib/avm/stereotypes/postgresql/instance/data_unit.rb +0 -41
  122. data/lib/avm/stereotypes/postgresql/instance_with.rb +0 -20
  123. data/lib/avm/tools/runner/eac_rails_base0/apache_host.rb +0 -16
  124. data/lib/avm/tools/runner/eac_rails_base0/bundle.rb +0 -14
  125. data/lib/avm/tools/runner/eac_rails_base0/deploy.rb +0 -15
  126. data/lib/avm/tools/runner/eac_redmine_base0/bundle.rb +0 -14
  127. data/lib/avm/tools/runner/eac_redmine_base0/data.rb +0 -27
  128. data/lib/avm/tools/runner/eac_redmine_base0/data/dump.rb +0 -16
  129. data/lib/avm/tools/runner/eac_redmine_base0/deploy.rb +0 -15
  130. data/lib/avm/tools/runner/eac_redmine_base0/runner.rb +0 -14
  131. data/lib/avm/tools/runner/eac_wordpress_base0/apache_host.rb +0 -17
  132. data/lib/avm/tools/runner/eac_wordpress_base0/data.rb +0 -15
  133. data/lib/avm/tools/runner/eac_wordpress_base0/deploy.rb +0 -15
@@ -10,6 +10,7 @@ module EacRubyBase0
10
10
  include ::EacCli::DefaultRunner
11
11
  runner_definition do
12
12
  bool_opt '-q', '--quiet', 'Quiet mode.'
13
+ bool_opt '-I', '--no-input', 'Fail if a input is requested.'
13
14
  subcommands
14
15
  alt do
15
16
  bool_opt '-V', '--version', 'Show version.'
@@ -20,6 +21,7 @@ module EacRubyBase0
20
21
  def run
21
22
  on_speaker_node do |node|
22
23
  node.stderr = ::StringIO.new if options.fetch('--quiet')
24
+ node.stdin = FailIfRequestInput.new if options.fetch('--no-input')
23
25
  if options.fetch('--version')
24
26
  show_version
25
27
  else
@@ -35,5 +37,15 @@ module EacRubyBase0
35
37
  def show_version
36
38
  out("#{application_version}\n")
37
39
  end
40
+
41
+ class FailIfRequestInput
42
+ enable_console_speaker
43
+
44
+ %w[gets noecho].each do |method|
45
+ define_method(method) do
46
+ raise "Input method requested (\"#{method}\") and option --no-input is set"
47
+ end
48
+ end
49
+ end
38
50
  end
39
51
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyBase0
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+ require 'singleton'
5
+
6
+ module EacRubyUtils
7
+ # A blank string which returns +false+ for +blank?+ method.
8
+ class BlankNotBlank < String
9
+ include ::Singleton
10
+
11
+ def initialize
12
+ super('')
13
+ end
14
+
15
+ def blank?
16
+ false
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/blank_not_blank'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'eac_ruby_utils/paths_hash'
6
+
7
+ module EacRubyUtils
8
+ class Configs
9
+ class Base
10
+ enable_simple_cache
11
+
12
+ common_constructor :data, default: [{}] do
13
+ self.data = ::EacRubyUtils::PathsHash.new(data)
14
+ end
15
+
16
+ def []=(entry_key, entry_value)
17
+ write(entry_key, entry_value)
18
+ end
19
+
20
+ def [](entry_key)
21
+ read(entry_key)
22
+ end
23
+
24
+ def clear
25
+ replace({})
26
+ end
27
+
28
+ def read(entry_key)
29
+ return nil unless data.key?(entry_key)
30
+
31
+ data.fetch(entry_key).if_present(::EacRubyUtils::BlankNotBlank.instance)
32
+ end
33
+
34
+ def replace(new_data)
35
+ self.data = ::EacRubyUtils::PathsHash.new(new_data)
36
+ end
37
+
38
+ def write(entry_key, entry_value)
39
+ data[entry_key] = entry_value
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,27 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/string'
3
+ require 'eac_ruby_utils/configs/base'
4
4
  require 'yaml'
5
- require 'eac_ruby_utils/patches/hash/sym_keys_hash'
6
- require 'eac_ruby_utils/paths_hash'
7
- require 'eac_ruby_utils/simple_cache'
8
5
 
9
6
  module EacRubyUtils
10
7
  class Configs
11
- class File
12
- include ::EacRubyUtils::SimpleCache
13
-
8
+ class File < ::EacRubyUtils::Configs::Base
14
9
  attr_reader :path, :options
15
10
 
16
11
  # Valid options: [:autosave]
17
12
  def initialize(path, options = {})
18
13
  @path = path
19
14
  @options = options.to_sym_keys_hash.freeze
20
- load
21
- end
22
-
23
- def clear
24
- self.data = ::EacRubyUtils::PathsHash.new({})
15
+ super(raw_data_from_file)
25
16
  end
26
17
 
27
18
  def save
@@ -30,37 +21,27 @@ module EacRubyUtils
30
21
  end
31
22
 
32
23
  def load
33
- self.data = if ::File.exist?(path) && ::File.size(path).positive?
34
- ::EacRubyUtils::PathsHash.new(YAML.load_file(path))
35
- else
36
- {}
37
- end
38
- end
39
-
40
- def []=(entry_key, entry_value)
41
- write(entry_key, entry_value)
24
+ replace(raw_data_from_file)
42
25
  end
43
26
 
44
27
  def write(entry_key, entry_value)
45
- data[entry_key] = entry_value
28
+ super
46
29
  save if autosave?
47
30
  end
48
31
 
49
- def [](entry_key)
50
- read(entry_key)
51
- end
52
-
53
- def read(entry_key)
54
- data[entry_key]
55
- end
56
-
57
32
  def autosave?
58
33
  options[:autosave] ? true : false
59
34
  end
60
35
 
61
36
  private
62
37
 
63
- attr_accessor :data
38
+ def raw_data_from_file
39
+ if ::File.exist?(path) && ::File.size(path).positive?
40
+ ::YAML.load_file(path)
41
+ else
42
+ {}
43
+ end
44
+ end
64
45
  end
65
46
  end
66
47
  end
@@ -1,16 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/common_constructor'
4
3
  require 'eac_ruby_utils/configs'
5
- require 'eac_ruby_utils/console/speaker'
6
- require 'eac_ruby_utils/options_consumer'
7
- require 'eac_ruby_utils/patches/object/asserts'
8
- require 'eac_ruby_utils/simple_cache'
4
+ require 'eac_ruby_utils/core_ext'
9
5
 
10
6
  module EacRubyUtils
11
7
  module Console
12
8
  class Configs
13
- include ::EacRubyUtils::Console::Speaker
9
+ require_sub __FILE__
10
+ enable_console_speaker
14
11
 
15
12
  class << self
16
13
  def entry_key_to_envvar_name(entry_key)
@@ -34,7 +31,7 @@ module EacRubyUtils
34
31
  end
35
32
 
36
33
  def read_password(entry_key, options = {})
37
- options = options.merge(noecho: true)
34
+ options = ReadEntryOptions.new(options.merge(noecho: true))
38
35
  if store_passwords?
39
36
  read_entry(entry_key, options)
40
37
  else
@@ -66,7 +63,10 @@ module EacRubyUtils
66
63
  protected
67
64
 
68
65
  def envvar_read_entry(entry_key)
69
- ENV[self.class.entry_key_to_envvar_name(entry_key)]
66
+ env_entry_key = self.class.entry_key_to_envvar_name(entry_key)
67
+ return nil unless ENV.key?(env_entry_key)
68
+
69
+ ENV.fetch(env_entry_key).if_present(::EacRubyUtils::BlankNotBlank.instance)
70
70
  end
71
71
 
72
72
  def read_entry_from_console(entry_key, options)
@@ -98,38 +98,6 @@ module EacRubyUtils
98
98
  warn('Entered value is blank') if entry_value.blank?
99
99
  entry_value
100
100
  end
101
-
102
- class ReadEntryOptions
103
- include ::EacRubyUtils::SimpleCache
104
- ::EacRubyUtils::CommonConstructor.new(:options).setup_class(self)
105
-
106
- DEFAULT_VALUES = {
107
- before_input: nil, bool: false, list: false, noecho: false, noenv: false, noinput: false,
108
- required: true, validator: nil
109
- }.freeze
110
-
111
- def [](key)
112
- values.fetch(key.to_sym)
113
- end
114
-
115
- def request_input_options
116
- values.slice(:bool, :list, :noecho)
117
- end
118
-
119
- private
120
-
121
- def values_uncached
122
- consumer = ::EacRubyUtils::OptionsConsumer.new(options)
123
- r = {}
124
- DEFAULT_VALUES.each do |key, default_value|
125
- value = consumer.consume(key)
126
- value = default_value if value.nil?
127
- r[key] = value
128
- end
129
- consumer.validate
130
- r
131
- end
132
- end
133
101
  end
134
102
  end
135
103
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacRubyUtils
6
+ module Console
7
+ class Configs
8
+ class ReadEntryOptions
9
+ enable_simple_cache
10
+ common_constructor :options
11
+
12
+ DEFAULT_VALUES = {
13
+ before_input: nil, bool: false, list: false, noecho: false, noenv: false, noinput: false,
14
+ required: true, validator: nil
15
+ }.freeze
16
+
17
+ def [](key)
18
+ values.fetch(key.to_sym)
19
+ end
20
+
21
+ def request_input_options
22
+ values.slice(:bool, :list, :noecho)
23
+ end
24
+
25
+ private
26
+
27
+ def values_uncached
28
+ consumer = options.to_options_consumer
29
+ r = {}
30
+ DEFAULT_VALUES.each do |key, default_value|
31
+ value = consumer.consume(key)
32
+ value = default_value if value.nil?
33
+ r[key] = value
34
+ end
35
+ consumer.validate
36
+ r
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'pathname'
5
+
6
+ module EacRubyUtils
7
+ module Fs
8
+ class ClearableDirectory < ::Pathname
9
+ CLEARABLE_BASENAME = '.clearable_directory'
10
+
11
+ def clear
12
+ validate_clearable
13
+ directory? ? clear_directory : clear_no_directory
14
+ mkpath
15
+ ::FileUtils.touch(clearable_note_file.to_path)
16
+ self
17
+ end
18
+
19
+ def clearable?
20
+ clearable_negate_message ? true : false
21
+ end
22
+
23
+ def clearable_negate_message
24
+ return if !exist? || empty?
25
+ return "Path \"#{self}\" exists, is not empty and is not a directory" unless directory?
26
+ return if clearable_note_file.exist?
27
+
28
+ "Directory \"#{self}\" is not empty and does not have a #{CLEARABLE_BASENAME} file"
29
+ end
30
+
31
+ def clearable_note_file
32
+ join(CLEARABLE_BASENAME)
33
+ end
34
+
35
+ def validate_clearable
36
+ message = clearable_negate_message
37
+ raise message if message
38
+ end
39
+
40
+ private
41
+
42
+ def clear_directory
43
+ children.each do |child|
44
+ if child.directory?
45
+ child.rmtree
46
+ elsif child.file?
47
+ child.unlink
48
+ end
49
+ end
50
+ end
51
+
52
+ def clear_no_directory
53
+ ::FileUtils.rm_rf(to_path)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,21 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/object'
4
- require 'eac_ruby_utils/patches/object/asserts'
3
+ require 'eac_ruby_utils/core_ext'
5
4
 
6
5
  module EacRubyUtils
7
6
  class PathsHash
7
+ require_sub __FILE__
8
+
8
9
  class << self
9
10
  def parse_entry_key(entry_key)
10
11
  r = entry_key.to_s.strip
11
- raise EntryKeyError, 'Entry key cannot start or end with dot' if
12
+ raise ::EacRubyUtils::PathsHash::EntryKeyError, 'Entry key cannot start or end with dot' if
12
13
  r.start_with?('.') || r.end_with?('.')
13
14
 
14
15
  r = r.split('.').map(&:strip)
15
- raise EntryKeyError, "Entry key \"#{entry_key}\" is empty" if r.empty?
16
+ if r.empty?
17
+ raise ::EacRubyUtils::PathsHash::EntryKeyError, "Entry key \"#{entry_key}\" is empty"
18
+ end
16
19
  return r.map(&:to_sym) unless r.any?(&:blank?)
17
20
 
18
- raise EntryKeyError, "Entry key \"#{entry_key}\" has at least one blank part"
21
+ raise ::EacRubyUtils::PathsHash::EntryKeyError,
22
+ "Entry key \"#{entry_key}\" has at least one blank part"
19
23
  end
20
24
  end
21
25
 
@@ -26,68 +30,27 @@ module EacRubyUtils
26
30
  end
27
31
 
28
32
  def [](entry_key)
29
- root.read_entry(self.class.parse_entry_key(entry_key), [])
33
+ root.read_entry(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
30
34
  end
31
35
 
32
36
  def []=(entry_key, entry_value)
33
- root.write_entry(self.class.parse_entry_key(entry_key), entry_value, [])
37
+ root.write_entry(
38
+ ::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key), entry_value
39
+ )
34
40
  end
35
41
 
36
- delegate :to_h, to: :root
37
-
38
- private
39
-
40
- attr_reader :data
41
-
42
- class EntryKeyError < StandardError
42
+ def fetch(entry_key)
43
+ root.fetch(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
43
44
  end
44
45
 
45
- class Node
46
- def initialize(source_hash)
47
- source_hash.assert_argument(Hash, 'source_hash')
48
- @data = source_hash.map { |k, v| [k.to_sym, v.is_a?(Hash) ? Node.new(v) : v] }.to_h
49
- end
50
-
51
- def to_h
52
- data.map { |k, v| [k, v.is_a?(Node) ? v.to_h : v] }.to_h
53
- end
54
-
55
- def read_entry(path, current)
56
- validate_path(path, current)
57
- node_key = path.shift
58
- node = data[node_key]
59
- return (node.is_a?(Node) ? node.to_h : node) if path.empty?
60
- return nil if node.blank?
61
- return node.read_entry(path, current + [node_key]) if node.is_a?(Node)
62
-
63
- raise(EntryKeyError,
64
- "Path #{current.join(',')} is not a Node and path continues (#{current + path})")
65
- end
66
-
67
- def write_entry(path, value, current)
68
- validate_path(path, current)
69
- node_key = path.shift
70
- write_entry_value(path, node_key, value, current)
71
- end
72
-
73
- private
46
+ def key?(entry_key)
47
+ root.entry?(::EacRubyUtils::PathsHash::PathSearch.parse_entry_key(entry_key))
48
+ end
74
49
 
75
- def write_entry_value(path, node_key, value, current)
76
- if path.empty?
77
- data[node_key] = value.is_a?(Hash) ? Node.new(value) : value
78
- else
79
- data[node_key] = Node.new({}) unless data[node_key].is_a?(Node)
80
- data[node_key].write_entry(path, value, current + [node_key])
81
- end
82
- end
50
+ delegate :to_h, to: :root
83
51
 
84
- def validate_path(path, current)
85
- path.assert_argument(Array, 'path')
86
- current.assert_argument(Array, 'current')
87
- raise EntryKeyError, 'Path is empty' if path.empty?
88
- end
52
+ private
89
53
 
90
- attr_reader :data
91
- end
54
+ attr_reader :data
92
55
  end
93
56
  end