eac_tools 0.61.0 → 0.61.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +8 -8
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm-files/avm-files.gemspec +1 -1
  5. data/sub/avm-files/lib/avm/files/version.rb +1 -1
  6. data/sub/avm-git/avm-git.gemspec +2 -2
  7. data/sub/avm-git/lib/avm/git/version.rb +1 -1
  8. data/sub/eac_templates/lib/eac_templates/abstract/directory.rb +42 -0
  9. data/sub/eac_templates/lib/eac_templates/abstract/file.rb +25 -0
  10. data/sub/eac_templates/lib/eac_templates/abstract/fs_object.rb +94 -0
  11. data/sub/eac_templates/lib/eac_templates/abstract/fs_object_by_pathname.rb +13 -0
  12. data/sub/eac_templates/lib/eac_templates/abstract/not_found_error.rb +8 -0
  13. data/sub/eac_templates/lib/eac_templates/interface_methods.rb +3 -3
  14. data/sub/eac_templates/lib/eac_templates/modules/ancestor/directory.rb +4 -2
  15. data/sub/eac_templates/lib/eac_templates/modules/ancestor/file.rb +3 -2
  16. data/sub/eac_templates/lib/eac_templates/modules/ancestor/fs_object.rb +6 -13
  17. data/sub/eac_templates/lib/eac_templates/modules/ancestor.rb +6 -3
  18. data/sub/eac_templates/lib/eac_templates/sources/directory.rb +23 -10
  19. data/sub/eac_templates/lib/eac_templates/sources/file.rb +3 -14
  20. data/sub/eac_templates/lib/eac_templates/sources/fs_object.rb +17 -17
  21. data/sub/eac_templates/lib/eac_templates/sources/set.rb +5 -4
  22. data/sub/eac_templates/lib/eac_templates/variables/content.rb +52 -0
  23. data/sub/eac_templates/lib/eac_templates/variables/directory.rb +7 -5
  24. data/sub/eac_templates/lib/eac_templates/variables/file.rb +9 -33
  25. data/sub/eac_templates/lib/eac_templates/version.rb +1 -1
  26. data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec.rb → modules/base_spec.rb} +41 -20
  27. data/sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/a_module/a/a_b +1 -0
  28. data/sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/a_module/c +1 -0
  29. data/sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/prepended_module/c +1 -0
  30. data/sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/super_class/a/a_b +1 -0
  31. data/sub/eac_templates/spec/lib/eac_templates/variables/{file_spec.rb → content_spec.rb} +4 -4
  32. metadata +25 -18
  33. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/a/a_b +0 -1
  34. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/c +0 -1
  35. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/super_class/a/a_b +0 -1
  36. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path1/a_module/a/a_a +0 -0
  37. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path1/a_module/b +0 -0
  38. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path1/super_class/a/a_b +0 -0
  39. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path1/super_class/b +0 -0
  40. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path2/a_module/b +0 -0
  41. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path2/sub_class/b +0 -0
  42. /data/sub/eac_templates/spec/lib/eac_templates/{patches/module/template_spec_files → modules/base_spec_files}/path2/super_class/b +0 -0
  43. /data/sub/eac_templates/spec/lib/eac_templates/variables/{file_spec_files → content_spec_files}/expected_content +0 -0
  44. /data/sub/eac_templates/spec/lib/eac_templates/variables/{file_spec_files → content_spec_files}/source.template +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88b13d61ea11ac15cc3677a1cf5ec17f1381f8f87ab25074f8cf7be2804e0679
4
- data.tar.gz: 4432b02f679cabc7aa8ac455599e2bdfa653a02c973a05f02315a7992b50665e
3
+ metadata.gz: a00f661cc45fae52c9754c08ad739ca0b401f18eab714f32624cd3fc43617873
4
+ data.tar.gz: e9f70e33cb5d6cb6b82e9ab47baa474717b65566533aab724494cf604234ba59
5
5
  SHA512:
6
- metadata.gz: 0e4a6b279e9e1ee080a4fdf0f390187330bf84b36b022816cb807fa2274bf338c7c894587bd2938f9d71b72b45da42d2df6de2609ef9c783a42a4d063642685a
7
- data.tar.gz: 2731fdeb08a1110cabba28cab3ccc98a60d8530e5d8a16c08a91459524952c98cccf7550cbcb6f21ccfcbdff8917c083d4911418ad91d6dc843e6e9f02fff58f
6
+ metadata.gz: 97736cf986ece6075c9c7b019021e2d84fc7b82c8e3a146f7a52d34460825047bcf9c45cce03664ddfd9a4a1d9acab72c88052770c024056c74dab8b30b21182
7
+ data.tar.gz: 665937d9379e2fd16de13e599c59d623d101c18f271bf45085a99f9d5c57847b41649580af8447848847b0164621abaf6af32ad18dbd657f93e7954def080474
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eac_tools (0.61.0)
4
+ eac_tools (0.61.1)
5
5
  avm (~> 0.67, >= 0.67.1)
6
6
  avm-eac_asciidoctor_base0 (~> 0.19)
7
7
  avm-eac_generic_base0 (~> 0.12)
@@ -16,7 +16,7 @@ PATH
16
16
  avm-eac_ruby_base1 (~> 0.30, >= 0.30.2)
17
17
  avm-eac_webapp_base0 (~> 0.15)
18
18
  avm-eac_wordpress_base0 (~> 0.3, >= 0.3.1)
19
- avm-git (~> 0.13, >= 0.13.1)
19
+ avm-git (~> 0.13, >= 0.13.2)
20
20
  avm-tools (~> 0.145, >= 0.145.1)
21
21
  eac_ruby_utils (~> 0.112)
22
22
 
@@ -153,19 +153,19 @@ PATH
153
153
  PATH
154
154
  remote: sub/avm-files
155
155
  specs:
156
- avm-files (0.6.1)
156
+ avm-files (0.6.2)
157
157
  avm (~> 0.67, >= 0.67.1)
158
158
  eac_cli (~> 0.30, >= 0.30.1)
159
159
  eac_fs (~> 0.16)
160
160
  eac_ruby_utils (~> 0.112)
161
- eac_templates (~> 0.4)
161
+ eac_templates (~> 0.5)
162
162
 
163
163
  PATH
164
164
  remote: sub/avm-git
165
165
  specs:
166
- avm-git (0.13.1)
167
- avm (~> 0.64, >= 0.64.2)
168
- avm-files (~> 0.6)
166
+ avm-git (0.13.2)
167
+ avm (~> 0.67, >= 0.67.1)
168
+ avm-files (~> 0.6, >= 0.6.2)
169
169
  eac_git (~> 0.14, >= 0.14.1)
170
170
  eac_ruby_utils (~> 0.112)
171
171
  git (~> 1.18)
@@ -263,7 +263,7 @@ PATH
263
263
  PATH
264
264
  remote: sub/eac_templates
265
265
  specs:
266
- eac_templates (0.4.0)
266
+ eac_templates (0.5.0)
267
267
  eac_config (~> 0.12)
268
268
  eac_ruby_utils (~> 0.112)
269
269
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacTools
4
- VERSION = '0.61.0'
4
+ VERSION = '0.61.1'
5
5
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.add_dependency 'eac_cli', '~> 0.30', '>= 0.30.1'
17
17
  s.add_dependency 'eac_fs', '~> 0.16'
18
18
  s.add_dependency 'eac_ruby_utils', '~> 0.112'
19
- s.add_dependency 'eac_templates', '~> 0.4'
19
+ s.add_dependency 'eac_templates', '~> 0.5'
20
20
 
21
21
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
22
22
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Files
5
- VERSION = '0.6.1'
5
+ VERSION = '0.6.2'
6
6
  end
7
7
  end
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib,locale}/**/*']
14
14
 
15
- s.add_dependency 'avm', '~> 0.64', '>= 0.64.2'
16
- s.add_dependency 'avm-files', '~> 0.6'
15
+ s.add_dependency 'avm', '~> 0.67', '>= 0.67.1'
16
+ s.add_dependency 'avm-files', '~> 0.6', '>= 0.6.2'
17
17
  s.add_dependency 'eac_git', '~> 0.14', '>= 0.14.1'
18
18
  s.add_dependency 'eac_ruby_utils', '~> 0.112'
19
19
  s.add_dependency 'git', '~> 1.18'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Git
5
- VERSION = '0.13.1'
5
+ VERSION = '0.13.2'
6
6
  end
7
7
  end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/interface_methods'
5
+ require 'eac_templates/abstract/fs_object'
6
+ require 'eac_templates/variables/directory'
7
+
8
+ module EacTemplates
9
+ module Abstract
10
+ class Directory < ::EacTemplates::Abstract::FsObject
11
+ enable_abstract_methods
12
+ delegate(*::EacTemplates::InterfaceMethods::DIRECTORY - %i[child chidren], to: :applier)
13
+
14
+ # @param basename [Pathname]
15
+ # @return [EacTemplates::Abstract::FsObject
16
+ def build_child(child_basename, child_type)
17
+ child_basename = child_basename.to_pathname
18
+ child_type = type_list.value_validate!(child_type)
19
+ category_module.const_get(child_type.to_s.camelize)
20
+ .new(owner, self, child_basename, options)
21
+ end
22
+
23
+ # @param basename [Pathname]
24
+ # @return [EacTemplates::Abstract::FsObject]
25
+ def child(basename)
26
+ basename = basename.to_pathname
27
+ children.find { |c| c.basename == basename } ||
28
+ raise_not_found("No child found with basename \"#{basename}\"")
29
+ end
30
+
31
+ # @return [Enumerable<EacTemplates::Abstract::FsObject>]
32
+ def children
33
+ children_basenames.map { |c_basename, c_type| build_child(c_basename, c_type) }
34
+ end
35
+
36
+ # @return [Hash<Pathname, Symbol>]
37
+ def children_basenames
38
+ raise_abstract_method __method__
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/interface_methods'
5
+ require 'eac_templates/abstract/fs_object'
6
+ require 'eac_templates/variables/file'
7
+
8
+ module EacTemplates
9
+ module Abstract
10
+ class File < ::EacTemplates::Abstract::FsObject
11
+ enable_abstract_methods
12
+ delegate(*::EacTemplates::InterfaceMethods::FILE - %i[content path], to: :applier)
13
+
14
+ # @return [String]
15
+ def content
16
+ path.read
17
+ end
18
+
19
+ # @return [Pathname]
20
+ def path
21
+ raise_abstract_method __method__
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/abstract/fs_object_by_pathname'
5
+ require 'eac_templates/abstract/not_found_error'
6
+
7
+ module EacTemplates
8
+ module Abstract
9
+ class FsObject
10
+ class << self
11
+ # @param obj [Object]
12
+ # @return [EacTemplates::Abstract::FsObject, EacTemplates::Abstracts::FsObjectByPathname]
13
+ def assert(obj)
14
+ if obj.is_a?(self)
15
+ obj
16
+ else
17
+ ::EacTemplates::Abstract::FsObjectByPathname.new(obj)
18
+ end
19
+ end
20
+
21
+ # @param owner [Object]
22
+ # @param parent_object [Object, nil]
23
+ # @param subpath [Pathname]
24
+ # @return [EacTemplates::Abstract::FsObject]
25
+ def by_subpath(owner, parent_object, subpath, options = {})
26
+ r = nil
27
+ subpath.to_pathname.each_filename do |basename|
28
+ r = new(owner, parent_object, basename, options)
29
+ parent_object = r
30
+ end
31
+ r || raise("Subpath is empty: #{subpath}")
32
+ end
33
+ end
34
+
35
+ enable_abstract_methods
36
+ enable_simple_cache
37
+ enable_listable
38
+ lists.add_symbol :option, :source_set
39
+ lists.add_symbol :type, :directory, :file
40
+ common_constructor :owner, :parent_object, :basename, :options, default: [{}] do
41
+ self.basename = basename.present? ? basename.to_pathname : ::Pathname.new('')
42
+ self.options = ::EacTemplates::Abstract::FsObject.lists.option.hash_keys_validate!(options)
43
+ end
44
+
45
+ # @return [EacTemplates::Variables::Directory, EacTemplates::Variables::File]
46
+ def applier
47
+ applier_class.new(self)
48
+ end
49
+
50
+ # @return [Class]
51
+ def applier_class
52
+ ::EacTemplates::Variables.const_get(type.to_s.camelize)
53
+ end
54
+
55
+ # @return [Module]
56
+ def category_module
57
+ self.class.module_parent
58
+ end
59
+
60
+ # @return [Pathname]
61
+ def path_for_search
62
+ if parent_object.present?
63
+ parent_object.path_for_search.join(basename)
64
+ else
65
+ path_for_search_prefix.join(basename)
66
+ end
67
+ end
68
+
69
+ # @return [Pathname]
70
+ def path_for_search_prefix
71
+ raise_abstract_method __method__
72
+ end
73
+
74
+ def raise_not_found(message)
75
+ raise ::EacTemplates::Abstract::NotFoundError, message
76
+ end
77
+
78
+ # @return [EacTemplates::Sources::Set]
79
+ def source_set
80
+ options[OPTION_SOURCE_SET] || ::EacTemplates::Sources::Set.default
81
+ end
82
+
83
+ # @return [Symbol]
84
+ def type
85
+ type_list.value_validate!(self.class.name.demodulize.underscore.to_sym)
86
+ end
87
+
88
+ # @return [EacRubyUtils::Listable::SymbolList]
89
+ def type_list
90
+ ::EacTemplates::Abstract::FsObject.lists.type
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacTemplates
6
+ module Abstract
7
+ class FsObjectByPathname
8
+ common_constructor :path do
9
+ self.path = path.to_pathname
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacTemplates
4
+ module Abstract
5
+ class NotFoundError < ::RuntimeError
6
+ end
7
+ end
8
+ end
@@ -2,10 +2,10 @@
2
2
 
3
3
  module EacTemplates
4
4
  module InterfaceMethods
5
- COMMON = %w[apply path].freeze
6
- ONLY_DIRECTORY = %w[child children].freeze
5
+ COMMON = %i[apply path].freeze
6
+ ONLY_DIRECTORY = %i[child children].freeze
7
7
  DIRECTORY = COMMON + ONLY_DIRECTORY
8
- ONLY_FILE = %w[apply_to_file content variables].freeze
8
+ ONLY_FILE = %i[apply_to_file content variables].freeze
9
9
  FILE = COMMON + ONLY_FILE
10
10
  ALL = COMMON + ONLY_DIRECTORY + ONLY_FILE
11
11
  end
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/abstract/directory'
4
5
  require 'eac_templates/interface_methods'
5
6
  require 'eac_templates/modules/ancestor/fs_object'
6
7
 
7
8
  module EacTemplates
8
9
  module Modules
9
10
  class Ancestor
10
- class Directory < ::EacTemplates::Modules::Ancestor::FsObject
11
- delegate(*::EacTemplates::InterfaceMethods::ONLY_DIRECTORY, to: :source_object)
11
+ class Directory < ::EacTemplates::Abstract::Directory
12
+ include ::EacTemplates::Modules::Ancestor::FsObject
13
+ delegate :children_basenames, to: :source_object
12
14
  end
13
15
  end
14
16
  end
@@ -1,14 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/abstract/file'
4
5
  require 'eac_templates/interface_methods'
5
6
  require 'eac_templates/modules/ancestor/fs_object'
6
7
 
7
8
  module EacTemplates
8
9
  module Modules
9
10
  class Ancestor
10
- class File < ::EacTemplates::Modules::Ancestor::FsObject
11
- delegate(*::EacTemplates::InterfaceMethods::ONLY_FILE, to: :source_object)
11
+ class File < ::EacTemplates::Abstract::File
12
+ include ::EacTemplates::Modules::Ancestor::FsObject
12
13
  end
13
14
  end
14
15
  end
@@ -6,25 +6,18 @@ require 'eac_templates/interface_methods'
6
6
  module EacTemplates
7
7
  module Modules
8
8
  class Ancestor
9
- class FsObject
10
- enable_simple_cache
11
- common_constructor :base
12
- delegate(*::EacTemplates::InterfaceMethods::COMMON, :found?, to: :source_object)
9
+ module FsObject
10
+ delegate :found?, :path, to: :source_object
13
11
 
14
- # @return [Symbol]
15
- def object_type
16
- self.class.name.demodulize.underscore.to_sym
17
- end
18
-
19
- # @return [Pathname, nil]
20
- def path
21
- source_object.found? ? source_object.send(:real_paths).first : nil
12
+ # @return [Pathname]
13
+ def path_for_search_prefix
14
+ owner.path_for_search
22
15
  end
23
16
 
24
17
  private
25
18
 
26
19
  def source_object_uncached
27
- base.source_set.send(object_type, base.path_for_search)
20
+ owner.source_set.send(type, path_for_search)
28
21
  end
29
22
  end
30
23
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
4
  require 'eac_templates/interface_methods'
5
+ require 'eac_templates/abstract/not_found_error'
5
6
 
6
7
  module EacTemplates
7
8
  module Modules
@@ -20,12 +21,14 @@ module EacTemplates
20
21
 
21
22
  # @return [EacTemplates::Modules::Directory]
22
23
  def directory
23
- ::EacTemplates::Modules::Ancestor::Directory.new(self)
24
+ @directory ||= ::EacTemplates::Modules::Ancestor::Directory
25
+ .new(self, nil, nil, source_set: source_set)
24
26
  end
25
27
 
26
28
  # @return [EacTemplates::Modules::File]
27
29
  def file
28
- @file ||= ::EacTemplates::Modules::Ancestor::File.new(self)
30
+ @file ||= ::EacTemplates::Modules::Ancestor::File
31
+ .new(self, nil, nil, source_set: source_set)
29
32
  end
30
33
 
31
34
  # @return [Pathname]
@@ -39,7 +42,7 @@ module EacTemplates
39
42
  return file if file.found?
40
43
  return directory if directory.found?
41
44
 
42
- raise "No template found: #{path_for_search}"
45
+ raise ::EacTemplates::Abstract::NotFoundError, "No template found: #{path_for_search}"
43
46
  end
44
47
 
45
48
  require_sub __FILE__
@@ -1,23 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/abstract/directory'
4
5
  require 'eac_templates/sources/fs_object'
5
- require 'eac_templates/variables/directory'
6
6
 
7
7
  module EacTemplates
8
8
  module Sources
9
- class Directory < ::EacTemplates::Sources::FsObject
10
- delegate :apply, :child, :children, :path, to: :applier
9
+ class Directory < ::EacTemplates::Abstract::Directory
10
+ include ::EacTemplates::Sources::FsObject
11
11
 
12
- # @return [Class]
13
- def applier_class
14
- ::EacTemplates::Variables::Directory
12
+ # @return [Hash<Pathname, Symbol>]
13
+ def children_basenames
14
+ r = {}
15
+ real_paths.each do |real_path|
16
+ real_path.children.each do |child|
17
+ next if r.key?(child.basename)
18
+
19
+ r[child.basename] = real_path_type(child)
20
+ end
21
+ end
22
+ r
15
23
  end
16
24
 
17
- # @param path [Pathname]
18
- # @return [Boolean]
19
- def select_path?(path)
20
- super && path.directory?
25
+ # @return [Pathname]
26
+ def real_path_type(path)
27
+ if path.file?
28
+ :file
29
+ elsif path.directory?
30
+ :directory
31
+ else
32
+ raise "Path \"#{path}\" is not a file nor a directory"
33
+ end
21
34
  end
22
35
  end
23
36
  end
@@ -1,24 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/abstract/file'
4
5
  require 'eac_templates/sources/fs_object'
5
- require 'eac_templates/variables/file'
6
6
 
7
7
  module EacTemplates
8
8
  module Sources
9
- class File < ::EacTemplates::Sources::FsObject
10
- delegate :apply, :apply_to_file, :content, :path, :variables, to: :applier
11
-
12
- # @return [Class]
13
- def applier_class
14
- ::EacTemplates::Variables::File
15
- end
16
-
17
- # @param path [Pathname]
18
- # @return [Boolean]
19
- def select_path?(path)
20
- super && path.file?
21
- end
9
+ class File < ::EacTemplates::Abstract::File
10
+ include ::EacTemplates::Sources::FsObject
22
11
  end
23
12
  end
24
13
  end
@@ -1,14 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/abstract/not_found_error'
4
5
 
5
6
  module EacTemplates
6
7
  module Sources
7
- class FsObject
8
- enable_abstract_methods
9
- enable_simple_cache
10
- common_constructor :source_set, :subpath do
11
- self.subpath = subpath.to_pathname
8
+ module FsObject
9
+ PATH_FOR_SEARCH_PREFIX = ::Pathname.new('')
10
+
11
+ common_concern do
12
+ enable_abstract_methods
13
+ enable_simple_cache
12
14
  end
13
15
 
14
16
  # @return [Boolean]
@@ -16,20 +18,18 @@ module EacTemplates
16
18
  real_paths.any?
17
19
  end
18
20
 
19
- protected
20
-
21
- # @return [Class]
22
- def applier_class
23
- raise_abstract_method __method__
21
+ # @return [Pathname]
22
+ def path
23
+ real_paths.first
24
24
  end
25
25
 
26
- # @return [EacTemplates::Variables::SourceFile]
27
- def applier_uncached
28
- raise "No #{self.class.name.downcase} found for \"#{subpath}\"" unless found?
29
-
30
- applier_class.new(real_paths.first)
26
+ # @return [Pathname]
27
+ def path_for_search_prefix
28
+ PATH_FOR_SEARCH_PREFIX
31
29
  end
32
30
 
31
+ protected
32
+
33
33
  # @return [Array<Pathname>]
34
34
  def real_paths_uncached
35
35
  source_set.included_paths.lazy.map { |source_single| source_single_search(source_single) }
@@ -39,13 +39,13 @@ module EacTemplates
39
39
  # @param path [Pathname]
40
40
  # @return [Boolean]
41
41
  def select_path?(path)
42
- path.present?
42
+ path.present? && path.send("#{type}?")
43
43
  end
44
44
 
45
45
  # @param source_single [EacTemplates::Sources::Single]
46
46
  # @return [Pathname, nil]
47
47
  def source_single_search(source_single)
48
- r = source_single.search(subpath)
48
+ r = source_single.search(path_for_search)
49
49
  select_path?(r) ? r : nil
50
50
  end
51
51
  end
@@ -4,6 +4,7 @@ require 'active_support/core_ext/object/blank'
4
4
  require 'eac_templates/sources/directory'
5
5
  require 'eac_templates/sources/file'
6
6
  require 'eac_templates/sources/internal_set'
7
+ require 'eac_templates/abstract/not_found_error'
7
8
 
8
9
  module EacTemplates
9
10
  module Sources
@@ -17,13 +18,13 @@ module EacTemplates
17
18
  # @param subpath [Pathname]
18
19
  # @return [EacTemplates::Sources::Directory]
19
20
  def directory(subpath)
20
- ::EacTemplates::Sources::Directory.new(self, subpath)
21
+ ::EacTemplates::Sources::Directory.by_subpath(self, nil, subpath, source_set: self)
21
22
  end
22
23
 
23
24
  # @param subpath [Pathname]
24
25
  # @return [EacTemplates::Sources::Directory]
25
26
  def file(subpath)
26
- ::EacTemplates::Sources::File.new(self, subpath)
27
+ ::EacTemplates::Sources::File.by_subpath(self, nil, subpath, source_set: self)
27
28
  end
28
29
 
29
30
  def template(subpath, required = true)
@@ -46,8 +47,8 @@ module EacTemplates
46
47
  private
47
48
 
48
49
  def raise_template_not_found(subpath)
49
- raise "Template not found for subpath \"#{subpath}\"" \
50
- " (Included paths: #{included_paths.to_a.join(::File::PATH_SEPARATOR)})"
50
+ raise ::EacTemplates::Abstract::NotFoundError, 'Template not found for subpath ' \
51
+ "\"#{subpath}\" (Included paths: #{included_paths.to_a.join(::File::PATH_SEPARATOR)})"
51
52
  end
52
53
  end
53
54
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/variables/providers'
5
+
6
+ module EacTemplates
7
+ module Variables
8
+ class Content
9
+ VARIABLE_DELIMITER = ::Regexp.quote('%%')
10
+ VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
11
+
12
+ class << self
13
+ # @param path [Pathname]
14
+ # @return [EacTemplates::Variables::Content]
15
+ def from_file(path)
16
+ new(path.to_pathname.read)
17
+ end
18
+ end
19
+
20
+ enable_simple_cache
21
+ common_constructor :content
22
+
23
+ # +variables_provider+ A [Hash] or object which responds to +read_entry(entry_name)+.
24
+ def apply(variables_source)
25
+ variables_provider = ::EacTemplates::Variables::Providers.build(variables_source)
26
+ variables.inject(content) do |a, e|
27
+ a.gsub(variable_pattern(e), variables_provider.variable_value(e).to_s)
28
+ end
29
+ end
30
+
31
+ def apply_to_file(variables_source, output_file_path)
32
+ output_file_path.to_pathname.write(apply(variables_source))
33
+ end
34
+
35
+ private
36
+
37
+ def variables_uncached
38
+ content.scan(VARIABLE_PATTERN).map(&:first).map do |name|
39
+ sanitize_variable_name(name)
40
+ end.to_set
41
+ end
42
+
43
+ def sanitize_variable_name(variable_name)
44
+ variable_name.to_s.downcase
45
+ end
46
+
47
+ def variable_pattern(name)
48
+ /#{VARIABLE_DELIMITER}#{::Regexp.quote(name)}#{VARIABLE_DELIMITER}/i
49
+ end
50
+ end
51
+ end
52
+ end
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_templates/abstract/not_found_error'
4
+ require 'eac_templates/abstract/directory'
3
5
  require 'eac_templates/variables/file'
4
6
  require 'eac_templates/variables/fs_object'
5
7
 
6
8
  module EacTemplates
7
9
  module Variables
8
10
  class Directory
9
- attr_reader :path
10
-
11
- def initialize(path)
12
- @path = path.is_a?(::Pathname) ? path : ::Pathname.new(path.to_s)
11
+ common_constructor :abstract_directory do
12
+ self.abstract_directory = ::EacTemplates::Abstract::Directory.assert(abstract_directory)
13
13
  end
14
+ delegate :path, to: :abstract_directory
14
15
 
15
16
  def apply(variables_source, directory)
16
17
  ::EacTemplates::Variables::FsObject.new(self, '.', directory, variables_source).apply
@@ -21,7 +22,8 @@ module EacTemplates
21
22
  return ::EacTemplates::Variables::File.new(child_path) if ::File.file?(child_path)
22
23
  return ::EacTemplates::Variables::Directory.new(child_path) if ::File.directory?(child_path)
23
24
 
24
- raise "Child \"#{subpath}\" from \"#{path}\" not found"
25
+ raise ::EacTemplates::Abstract::NotFoundError,
26
+ "Child \"#{subpath}\" from \"#{path}\" not found"
25
27
  end
26
28
 
27
29
  def children
@@ -1,49 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/abstract/file'
5
+ require 'eac_templates/variables/content'
4
6
  require 'eac_templates/variables/providers'
5
7
 
6
8
  module EacTemplates
7
9
  module Variables
8
10
  class File
9
- VARIABLE_DELIMITER = ::Regexp.quote('%%')
10
- VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
11
-
12
11
  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 = ::EacTemplates::Variables::Providers.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))
12
+ common_constructor :abstract_file do
13
+ self.abstract_file = ::EacTemplates::Abstract::File.assert(abstract_file)
27
14
  end
15
+ delegate :path, to: :abstract_file
16
+ delegate :apply, :apply_to_file, :content, :variables, to: :content_applier
28
17
 
29
18
  private
30
19
 
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
20
+ # @return [EacTemplates::Variables::Content]
21
+ def content_applier_uncached
22
+ ::EacTemplates::Variables::Content.from_file(path)
47
23
  end
48
24
  end
49
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacTemplates
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_templates/patches/module/template'
3
+ require 'eac_templates/modules/base'
4
+ require 'eac_templates/abstract/not_found_error'
4
5
  require 'eac_templates/sources/set'
5
6
 
6
- RSpec.describe ::Module do
7
+ RSpec.describe ::EacTemplates::Modules::Base do
7
8
  def self.on_node_specs(node_name, &block)
8
9
  context "when object is \"#{node_name}\"" do # rubocop:disable RSpec/EmptyExampleGroup
9
10
  let(:node) { send(node_name) }
@@ -40,13 +41,13 @@ RSpec.describe ::Module do
40
41
  def self.file_specs_error(node_name)
41
42
  on_node_specs(node_name) do
42
43
  it do
43
- expect { node }.to raise_error(::RuntimeError)
44
+ expect { node }.to raise_error(::EacTemplates::Abstract::NotFoundError)
44
45
  end
45
46
  end
46
47
  end
47
48
 
48
49
  let(:a_module) do
49
- described_class.new do
50
+ ::Module.new do
50
51
  def self.name
51
52
  'AModule'
52
53
  end
@@ -61,43 +62,52 @@ RSpec.describe ::Module do
61
62
  r.include a_module
62
63
  r
63
64
  end
65
+ let(:prepended_module) do
66
+ ::Module.new do
67
+ def self.name
68
+ 'PrependedModule'
69
+ end
70
+ end
71
+ end
64
72
  let(:sub_class) do
65
73
  r = ::Class.new(super_class) do
66
74
  def self.name
67
75
  'SuperClass'
68
76
  end
69
77
  end
78
+ r.prepend(prepended_module)
70
79
  r
71
80
  end
72
- let(:files_dir) { __dir__.to_pathname.join('template_spec_files') }
81
+ let(:files_dir) { __dir__.to_pathname.join('base_spec_files') }
73
82
  let(:variables_source) { { vx: '_X_', vy: '_Y_' } }
83
+ let(:source_set) do
84
+ r = ::EacTemplates::Sources::Set.new
85
+ %w[path1 path2].each do |sub|
86
+ r.included_paths << files_dir.join(sub)
87
+ end
88
+ r
89
+ end
74
90
 
75
- let(:a) { instance.template.child('a') }
91
+ let(:a) { instance.child('a') }
76
92
  let(:a_a) { a.child('a_a') }
77
93
  let(:a_b) { a.child('a_b') }
78
94
  let(:a_c) { a.child('a_c') }
79
- let(:b) { instance.template.child('b') }
80
- let(:c) { instance.template.child('c') }
81
-
82
- before do
83
- %w[path1 path2].each do |sub|
84
- ::EacTemplates::Sources::Set.default.included_paths << files_dir.join(sub)
85
- end
86
- end
95
+ let(:b) { instance.child('b') }
96
+ let(:c) { instance.child('c') }
87
97
 
88
98
  context 'when module is AModule' do # rubocop:disable RSpec/EmptyExampleGroup
89
- let(:instance) { a_module }
99
+ let(:instance) { described_class.new(a_module, source_set: source_set) }
90
100
 
91
- dir_specs(:a, %w[a_a])
101
+ dir_specs(:a, %w[a_a a_b])
92
102
  file_specs_ok(:a_a, "A_MODULE_A_A\n", "A_MODULE_A_A\n", [])
93
- file_specs_error(:a_b)
103
+ file_specs_ok(:a_b, "A_MODULE_A_B\n", "A_MODULE_A_B\n", [])
94
104
  file_specs_error(:a_c)
95
105
  file_specs_ok(:b, "A_MODULE_B%%vy%%\n", "A_MODULE_B_Y_\n", %w[vy])
96
- file_specs_error(:c)
106
+ file_specs_ok(:c, "A_MODULE_C%%vx%%\n", "A_MODULE_C_X_\n", %w[vx])
97
107
  end
98
108
 
99
109
  context 'when module is SuperClass' do # rubocop:disable RSpec/EmptyExampleGroup
100
- let(:instance) { super_class }
110
+ let(:instance) { described_class.new(super_class, source_set: source_set) }
101
111
 
102
112
  dir_specs(:a, %w[a_b])
103
113
  file_specs_error(:a_a)
@@ -108,7 +118,7 @@ RSpec.describe ::Module do
108
118
  end
109
119
 
110
120
  context 'when module is SubClass' do # rubocop:disable RSpec/EmptyExampleGroup
111
- let(:instance) { sub_class }
121
+ let(:instance) { described_class.new(sub_class, source_set: source_set) }
112
122
 
113
123
  dir_specs(:a, %w[a_b])
114
124
  file_specs_error(:a_a)
@@ -117,4 +127,15 @@ RSpec.describe ::Module do
117
127
  file_specs_ok(:b, "SUPER_CLASS_B\n", "SUPER_CLASS_B\n", [])
118
128
  file_specs_error(:c)
119
129
  end
130
+
131
+ context 'when module is PrependedModule' do # rubocop:disable RSpec/EmptyExampleGroup
132
+ let(:instance) { described_class.new(prepended_module, source_set: source_set) }
133
+
134
+ file_specs_error(:a)
135
+ file_specs_error(:a_a)
136
+ file_specs_error(:a_b)
137
+ file_specs_error(:a_c)
138
+ file_specs_error(:b)
139
+ file_specs_ok(:c, "PREPENDED_MODULE_C%%vy%%%%vx%%\n", "PREPENDED_MODULE_C_Y__X_\n", %w[vy vx])
140
+ end
120
141
  end
@@ -3,10 +3,10 @@
3
3
  require 'eac_config/old_configs'
4
4
  require 'eac_templates/variables/file'
5
5
 
6
- RSpec.describe ::EacTemplates::Variables::File do
7
- let(:files_dir) { ::File.join(__dir__, 'file_spec_files') }
8
- let(:source_path) { ::File.join(files_dir, 'source.template') }
9
- let(:instance) { described_class.new(source_path) }
6
+ RSpec.describe ::EacTemplates::Variables::Content do
7
+ let(:files_dir) { ::File.join(__dir__, 'content_spec_files').to_pathname }
8
+ let(:source_path) { files_dir.join('source.template') }
9
+ let(:instance) { described_class.from_file(source_path) }
10
10
  let(:expected_content) { ::File.read(::File.join(files_dir, 'expected_content')) }
11
11
 
12
12
  describe '#apply' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.61.0
4
+ version: 0.61.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-01 00:00:00.000000000 Z
11
+ date: 2023-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: avm
@@ -275,7 +275,7 @@ dependencies:
275
275
  version: '0.13'
276
276
  - - ">="
277
277
  - !ruby/object:Gem::Version
278
- version: 0.13.1
278
+ version: 0.13.2
279
279
  type: :runtime
280
280
  prerelease: false
281
281
  version_requirements: !ruby/object:Gem::Requirement
@@ -285,7 +285,7 @@ dependencies:
285
285
  version: '0.13'
286
286
  - - ">="
287
287
  - !ruby/object:Gem::Version
288
- version: 0.13.1
288
+ version: 0.13.2
289
289
  - !ruby/object:Gem::Dependency
290
290
  name: avm-tools
291
291
  requirement: !ruby/object:Gem::Requirement
@@ -1969,6 +1969,11 @@ files:
1969
1969
  - sub/eac_templates/Gemfile
1970
1970
  - sub/eac_templates/eac_templates.gemspec
1971
1971
  - sub/eac_templates/lib/eac_templates.rb
1972
+ - sub/eac_templates/lib/eac_templates/abstract/directory.rb
1973
+ - sub/eac_templates/lib/eac_templates/abstract/file.rb
1974
+ - sub/eac_templates/lib/eac_templates/abstract/fs_object.rb
1975
+ - sub/eac_templates/lib/eac_templates/abstract/fs_object_by_pathname.rb
1976
+ - sub/eac_templates/lib/eac_templates/abstract/not_found_error.rb
1972
1977
  - sub/eac_templates/lib/eac_templates/core_ext.rb
1973
1978
  - sub/eac_templates/lib/eac_templates/interface_methods.rb
1974
1979
  - sub/eac_templates/lib/eac_templates/modules.rb
@@ -1994,6 +1999,7 @@ files:
1994
1999
  - sub/eac_templates/lib/eac_templates/sources/set.rb
1995
2000
  - sub/eac_templates/lib/eac_templates/sources/single.rb
1996
2001
  - sub/eac_templates/lib/eac_templates/variables.rb
2002
+ - sub/eac_templates/lib/eac_templates/variables/content.rb
1997
2003
  - sub/eac_templates/lib/eac_templates/variables/directory.rb
1998
2004
  - sub/eac_templates/lib/eac_templates/variables/file.rb
1999
2005
  - sub/eac_templates/lib/eac_templates/variables/fs_object.rb
@@ -2005,26 +2011,27 @@ files:
2005
2011
  - sub/eac_templates/lib/eac_templates/variables/providers/generic.rb
2006
2012
  - sub/eac_templates/lib/eac_templates/variables/providers/hash.rb
2007
2013
  - sub/eac_templates/lib/eac_templates/version.rb
2008
- - sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec.rb
2009
- - sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/a_module/a/a_a
2010
- - sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/a_module/b
2011
- - sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/super_class/a/a_b
2012
- - sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/super_class/b
2013
- - sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/a/a_b
2014
- - sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/b
2015
- - sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/c
2016
- - sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/sub_class/b
2017
- - sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/super_class/a/a_b
2018
- - sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/super_class/b
2014
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec.rb
2015
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path1/a_module/a/a_a
2016
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path1/a_module/b
2017
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path1/super_class/a/a_b
2018
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path1/super_class/b
2019
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/a_module/a/a_b
2020
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/a_module/b
2021
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/a_module/c
2022
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/prepended_module/c
2023
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/sub_class/b
2024
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/super_class/a/a_b
2025
+ - sub/eac_templates/spec/lib/eac_templates/modules/base_spec_files/path2/super_class/b
2019
2026
  - sub/eac_templates/spec/lib/eac_templates/patches/object/template_spec.rb
2020
2027
  - sub/eac_templates/spec/lib/eac_templates/patches/object/template_spec_files/path/my_stub_with_template
2021
2028
  - sub/eac_templates/spec/lib/eac_templates/sources/set_spec.rb
2022
2029
  - sub/eac_templates/spec/lib/eac_templates/sources/set_spec_files/path1/subdir1/file1.template
2023
2030
  - sub/eac_templates/spec/lib/eac_templates/sources/set_spec_files/path1/subdir1/file2
2024
2031
  - sub/eac_templates/spec/lib/eac_templates/sources/set_spec_files/path2/subdir1/file3.template
2025
- - sub/eac_templates/spec/lib/eac_templates/variables/file_spec.rb
2026
- - sub/eac_templates/spec/lib/eac_templates/variables/file_spec_files/expected_content
2027
- - sub/eac_templates/spec/lib/eac_templates/variables/file_spec_files/source.template
2032
+ - sub/eac_templates/spec/lib/eac_templates/variables/content_spec.rb
2033
+ - sub/eac_templates/spec/lib/eac_templates/variables/content_spec_files/expected_content
2034
+ - sub/eac_templates/spec/lib/eac_templates/variables/content_spec_files/source.template
2028
2035
  - sub/eac_templates/spec/rubocop_spec.rb
2029
2036
  - sub/eac_templates/spec/spec_helper.rb
2030
2037
  homepage: