eac_tools 0.60.2 → 0.60.3

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +29 -24
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/avm.gemspec +1 -1
  5. data/sub/avm/lib/avm/version.rb +1 -1
  6. data/sub/avm-eac_ruby_base1/avm-eac_ruby_base1.gemspec +2 -2
  7. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/source_generators/base.rb +2 -2
  8. data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/version.rb +1 -1
  9. data/sub/avm-eac_ubuntu_base0/Gemfile +3 -0
  10. data/sub/avm-eac_ubuntu_base0/avm-eac_ubuntu_base0.gemspec +1 -1
  11. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/docker_image.rb +1 -1
  12. data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/version.rb +1 -1
  13. data/sub/avm-files/avm-files.gemspec +5 -5
  14. data/sub/avm-files/lib/avm/files/appendable/templatized_directory.rb +2 -2
  15. data/sub/avm-files/lib/avm/files/version.rb +1 -1
  16. data/sub/eac_templates/Gemfile +8 -0
  17. data/sub/eac_templates/eac_templates.gemspec +19 -0
  18. data/sub/eac_templates/lib/eac_templates/core_ext.rb +4 -0
  19. data/sub/eac_templates/lib/eac_templates/interface_methods.rb +12 -0
  20. data/sub/eac_templates/lib/eac_templates/modules/ancestor/directory.rb +15 -0
  21. data/sub/eac_templates/lib/eac_templates/modules/ancestor/file.rb +15 -0
  22. data/sub/eac_templates/lib/eac_templates/modules/ancestor/fs_object.rb +32 -0
  23. data/sub/eac_templates/lib/eac_templates/modules/ancestor.rb +48 -0
  24. data/sub/eac_templates/lib/eac_templates/modules/base.rb +35 -0
  25. data/sub/eac_templates/lib/eac_templates/modules.rb +9 -0
  26. data/sub/eac_templates/lib/eac_templates/patches/module/erb_template.rb +9 -0
  27. data/sub/eac_templates/lib/eac_templates/patches/module/template.rb +9 -0
  28. data/sub/eac_templates/lib/eac_templates/patches/module.rb +4 -0
  29. data/sub/eac_templates/lib/eac_templates/patches/object/erb_template.rb +9 -0
  30. data/sub/eac_templates/lib/eac_templates/patches/object/template.rb +9 -0
  31. data/sub/eac_templates/lib/eac_templates/patches/object.rb +4 -0
  32. data/sub/eac_templates/lib/eac_templates/patches.rb +4 -0
  33. data/sub/eac_templates/lib/eac_templates/sources/directory.rb +24 -0
  34. data/sub/eac_templates/lib/eac_templates/sources/file.rb +24 -0
  35. data/sub/eac_templates/lib/eac_templates/sources/from_all_gems.rb +4 -0
  36. data/sub/eac_templates/lib/eac_templates/sources/from_gem.rb +37 -0
  37. data/sub/eac_templates/lib/eac_templates/sources/fs_object.rb +53 -0
  38. data/sub/eac_templates/lib/eac_templates/sources/internal_set.rb +22 -0
  39. data/sub/eac_templates/lib/eac_templates/sources/set.rb +54 -0
  40. data/sub/eac_templates/lib/eac_templates/sources/single.rb +29 -0
  41. data/sub/eac_templates/lib/eac_templates/sources.rb +9 -0
  42. data/sub/eac_templates/lib/eac_templates/variables/directory.rb +47 -0
  43. data/sub/eac_templates/lib/eac_templates/variables/file.rb +50 -0
  44. data/sub/eac_templates/lib/eac_templates/variables/fs_object.rb +65 -0
  45. data/sub/eac_templates/lib/eac_templates/variables/not_found_error.rb +7 -0
  46. data/sub/eac_templates/lib/eac_templates/variables/providers/base.rb +23 -0
  47. data/sub/eac_templates/lib/eac_templates/variables/providers/config_reader.rb +29 -0
  48. data/sub/eac_templates/lib/eac_templates/variables/providers/entries_reader.rb +25 -0
  49. data/sub/eac_templates/lib/eac_templates/variables/providers/generic.rb +25 -0
  50. data/sub/eac_templates/lib/eac_templates/variables/providers/hash.rb +29 -0
  51. data/sub/eac_templates/lib/eac_templates/variables/providers.rb +25 -0
  52. data/sub/eac_templates/lib/eac_templates/variables.rb +9 -0
  53. data/sub/eac_templates/lib/eac_templates/version.rb +5 -0
  54. data/sub/eac_templates/lib/eac_templates.rb +7 -0
  55. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec.rb +120 -0
  56. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/a_module/a/a_a +1 -0
  57. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/a_module/b +1 -0
  58. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/super_class/a/a_b +1 -0
  59. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/super_class/b +1 -0
  60. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/a/a_b +1 -0
  61. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/b +1 -0
  62. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/c +1 -0
  63. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/sub_class/b +1 -0
  64. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/super_class/a/a_b +1 -0
  65. data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/super_class/b +1 -0
  66. data/sub/eac_templates/spec/lib/eac_templates/patches/object/template_spec.rb +26 -0
  67. data/sub/eac_templates/spec/lib/eac_templates/patches/object/template_spec_files/path/my_stub_with_template +1 -0
  68. data/sub/eac_templates/spec/lib/eac_templates/sources/set_spec.rb +42 -0
  69. data/sub/eac_templates/spec/lib/eac_templates/sources/set_spec_files/path1/subdir1/file1.template +1 -0
  70. data/sub/eac_templates/spec/lib/eac_templates/sources/set_spec_files/path1/subdir1/file2 +1 -0
  71. data/sub/eac_templates/spec/lib/eac_templates/sources/set_spec_files/path2/subdir1/file3.template +1 -0
  72. data/sub/eac_templates/spec/lib/eac_templates/variables/file_spec.rb +35 -0
  73. data/sub/eac_templates/spec/lib/eac_templates/variables/file_spec_files/expected_content +2 -0
  74. data/sub/eac_templates/spec/lib/eac_templates/variables/file_spec_files/source.template +2 -0
  75. data/sub/eac_templates/spec/rubocop_spec.rb +3 -0
  76. data/sub/eac_templates/spec/spec_helper.rb +4 -0
  77. metadata +71 -4
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/sources/set'
4
+
5
+ module EacTemplates
6
+ module Sources
7
+ class FromGem
8
+ class << self
9
+ def include_all(searcher = nil)
10
+ ::Gem::Specification.each { |gemspec| new(gemspec, searcher).include }
11
+ end
12
+ end
13
+
14
+ TEMPLATES_DIR_SUBPATH = 'template'
15
+
16
+ common_constructor :gemspec, :searcher, default: [nil] do
17
+ self.searcher ||= ::EacTemplates::Sources::Set.default
18
+ end
19
+
20
+ # @return [Boolean]
21
+ delegate :exist?, to: :path
22
+
23
+ # @return [Pathname]
24
+ def include
25
+ return nil unless exist?
26
+
27
+ searcher.included_paths << path
28
+ path
29
+ end
30
+
31
+ # @return [Pathname]
32
+ def path
33
+ gemspec.gem_dir.to_pathname.join(TEMPLATES_DIR_SUBPATH)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacTemplates
6
+ 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
12
+ end
13
+
14
+ # @return [Boolean]
15
+ def found?
16
+ real_paths.any?
17
+ end
18
+
19
+ protected
20
+
21
+ # @return [Class]
22
+ def applier_class
23
+ raise_abstract_method __method__
24
+ end
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)
31
+ end
32
+
33
+ # @return [Array<Pathname>]
34
+ def real_paths_uncached
35
+ source_set.included_paths.lazy.map { |source_single| source_single_search(source_single) }
36
+ .select(&:present?)
37
+ end
38
+
39
+ # @param path [Pathname]
40
+ # @return [Boolean]
41
+ def select_path?(path)
42
+ path.present?
43
+ end
44
+
45
+ # @param source_single [EacTemplates::Sources::Single]
46
+ # @return [Pathname, nil]
47
+ def source_single_search(source_single)
48
+ r = source_single.search(subpath)
49
+ select_path?(r) ? r : nil
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+ require 'eac_templates/sources/single'
5
+
6
+ module EacTemplates
7
+ module Sources
8
+ class InternalSet < ::Set
9
+ # @param single [EacTemplates::Sources::Single]
10
+ # @return [self]
11
+ def add(single)
12
+ super(::EacTemplates::Sources::Single.assert(single))
13
+ end
14
+
15
+ # @param single [EacTemplates::Sources::Single]
16
+ # @return [self]
17
+ def <<(single)
18
+ add(single)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+ require 'eac_templates/sources/directory'
5
+ require 'eac_templates/sources/file'
6
+ require 'eac_templates/sources/internal_set'
7
+
8
+ module EacTemplates
9
+ module Sources
10
+ class Set
11
+ class << self
12
+ def default
13
+ @default ||= new
14
+ end
15
+ end
16
+
17
+ # @param subpath [Pathname]
18
+ # @return [EacTemplates::Sources::Directory]
19
+ def directory(subpath)
20
+ ::EacTemplates::Sources::Directory.new(self, subpath)
21
+ end
22
+
23
+ # @param subpath [Pathname]
24
+ # @return [EacTemplates::Sources::Directory]
25
+ def file(subpath)
26
+ ::EacTemplates::Sources::File.new(self, subpath)
27
+ end
28
+
29
+ def template(subpath, required = true)
30
+ found_file = file(subpath)
31
+ return found_file if found_file.found?
32
+
33
+ found_directory = directory(subpath)
34
+ return found_directory if found_directory.found?
35
+
36
+ return nil unless required
37
+
38
+ raise_template_not_found(subpath)
39
+ end
40
+
41
+ # @return [EacTemplates::Sources::InternalSet]
42
+ def included_paths
43
+ @included_paths ||= ::EacTemplates::Sources::InternalSet.new
44
+ end
45
+
46
+ private
47
+
48
+ 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)})"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacTemplates
6
+ module Sources
7
+ class Single
8
+ class << self
9
+ # @param object [EacTemplates::Sources::Single, Pathname]
10
+ # @return [EacTemplates::Sources::Single]
11
+ def assert(object)
12
+ return object if object.is_a?(self)
13
+
14
+ new(object.to_pathname)
15
+ end
16
+ end
17
+
18
+ common_constructor :path do
19
+ self.path = path.to_pathname.expand_path
20
+ end
21
+
22
+ # @return [Pathname, nil]
23
+ def search(subpath)
24
+ r = path.join(subpath)
25
+ r.exist? ? r : nil
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacTemplates
6
+ module Sources
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/variables/file'
4
+ require 'eac_templates/variables/fs_object'
5
+
6
+ module EacTemplates
7
+ module Variables
8
+ class Directory
9
+ attr_reader :path
10
+
11
+ def initialize(path)
12
+ @path = path.is_a?(::Pathname) ? path : ::Pathname.new(path.to_s)
13
+ end
14
+
15
+ def apply(variables_source, directory)
16
+ ::EacTemplates::Variables::FsObject.new(self, '.', directory, variables_source).apply
17
+ end
18
+
19
+ def child(subpath)
20
+ child_path = ::File.join(path, subpath)
21
+ return ::EacTemplates::Variables::File.new(child_path) if ::File.file?(child_path)
22
+ return ::EacTemplates::Variables::Directory.new(child_path) if ::File.directory?(child_path)
23
+
24
+ raise "Child \"#{subpath}\" from \"#{path}\" not found"
25
+ end
26
+
27
+ def children
28
+ path.children.map do |path_child|
29
+ child(path_child.basename.to_path)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def apply_fs_object(source_relative, target)
36
+ if ::File.directory?(source_absolute(source_relative))
37
+ apply_directory(source_relative, target)
38
+ elsif ::File.file?(source_absolute(source_relative))
39
+ end
40
+ end
41
+
42
+ def source_absolute(source_relative)
43
+ ::File.expand_path(source_relative, path)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,50 @@
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 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 = ::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))
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
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/variables/file'
4
+
5
+ module EacTemplates
6
+ module Variables
7
+ class FsObject
8
+ TEMPLATE_EXTNAME = '.template'
9
+
10
+ common_constructor :source_directory, :source_relative, :target_root_directory,
11
+ :variables_source
12
+
13
+ def apply
14
+ if file?
15
+ apply_file
16
+ elsif directory?
17
+ apply_directory
18
+ else
19
+ raise "Unknown filesystem type: #{source_absolute}"
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def apply_directory
26
+ ::FileUtils.mkdir_p(target_absolute)
27
+ Dir.entries(source_absolute).each do |entry|
28
+ child(entry).apply unless %w[. ..].include?(entry)
29
+ end
30
+ end
31
+
32
+ def apply_file
33
+ if ::File.extname(source_absolute) == TEMPLATE_EXTNAME
34
+ ::EacTemplates::Variables::File.new(source_absolute).apply_to_file(
35
+ variables_source, target_absolute
36
+ )
37
+ else
38
+ ::FileUtils.cp(source_absolute, target_absolute)
39
+ end
40
+ end
41
+
42
+ def child(entry)
43
+ self.class.new(source_directory, ::File.join(source_relative, entry),
44
+ target_root_directory, variables_source)
45
+ end
46
+
47
+ def file?
48
+ ::File.file?(source_absolute)
49
+ end
50
+
51
+ def directory?
52
+ ::File.directory?(source_absolute)
53
+ end
54
+
55
+ def source_absolute
56
+ ::File.expand_path(source_relative, source_directory.path)
57
+ end
58
+
59
+ def target_absolute
60
+ ::File.expand_path(source_relative, target_root_directory)
61
+ .gsub(/#{::Regexp.quote(TEMPLATE_EXTNAME)}\z/, '')
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacTemplates
4
+ module Variables
5
+ class NotFoundError < StandardError; end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/variables/not_found_error'
4
+
5
+ module EacTemplates
6
+ module Variables
7
+ module Providers
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
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_config/node'
4
+ require 'eac_templates/variables/providers/base'
5
+
6
+ module EacTemplates
7
+ module Variables
8
+ module Providers
9
+ class ConfigReader < ::EacTemplates::Variables::Providers::Base
10
+ class << self
11
+ def accept?(variables_source)
12
+ return false unless variables_source.respond_to?(:entry)
13
+
14
+ entry = variables_source.entry(:any_value)
15
+ entry.respond_to?(:value) && entry.respond_to?(:found?)
16
+ end
17
+ end
18
+
19
+ def variable_exist?(name)
20
+ source.entry(name).found?
21
+ end
22
+
23
+ def variable_fetch(name)
24
+ source.entry(name).value
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/variables/providers/base'
4
+
5
+ module EacTemplates
6
+ module Variables
7
+ module Providers
8
+ class EntriesReader < ::EacTemplates::Variables::Providers::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
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/variables/providers/base'
4
+
5
+ module EacTemplates
6
+ module Variables
7
+ module Providers
8
+ class Generic < ::EacTemplates::Variables::Providers::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
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/variables/providers/base'
4
+
5
+ module EacTemplates
6
+ module Variables
7
+ module Providers
8
+ class Hash < ::EacTemplates::Variables::Providers::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
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacTemplates
6
+ module Variables
7
+ module Providers
8
+ require_sub __FILE__
9
+
10
+ PROVIDERS = %w[config_reader entries_reader hash generic].map do |name|
11
+ "eac_templates/variables/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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacTemplates
6
+ module Variables
7
+ require_sub __FILE__
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EacTemplates
4
+ VERSION = '0.4.0'
5
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module EacTemplates
6
+ require_sub __FILE__
7
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_templates/patches/module/template'
4
+ require 'eac_templates/sources/set'
5
+
6
+ RSpec.describe ::Module do
7
+ def self.on_node_specs(node_name, &block)
8
+ context "when object is \"#{node_name}\"" do # rubocop:disable RSpec/EmptyExampleGroup
9
+ let(:node) { send(node_name) }
10
+
11
+ instance_eval(&block)
12
+ end
13
+ end
14
+
15
+ def self.dir_specs(node_name, expected_children)
16
+ on_node_specs(node_name) do
17
+ it do
18
+ expect(node.children.map { |child| child.path.basename.to_path }).to(
19
+ eq(expected_children)
20
+ )
21
+ end
22
+ end
23
+ end
24
+
25
+ def self.file_specs_ok(node_name, expected_content, expected_apply, # rubocop:disable Metrics/AbcSize
26
+ expected_variables)
27
+ on_node_specs(node_name) do
28
+ it { expect(node.content).to eq(expected_content) }
29
+ it { expect(node.variables).to eq(::Set.new(expected_variables)) }
30
+ it { expect(node.apply(variables_source)).to eq(expected_apply) }
31
+
32
+ it do
33
+ target_file = temp_file
34
+ node.apply_to_file(variables_source, target_file)
35
+ expect(target_file.read).to eq(expected_apply)
36
+ end
37
+ end
38
+ end
39
+
40
+ def self.file_specs_error(node_name)
41
+ on_node_specs(node_name) do
42
+ it do
43
+ expect { node }.to raise_error(::RuntimeError)
44
+ end
45
+ end
46
+ end
47
+
48
+ let(:a_module) do
49
+ described_class.new do
50
+ def self.name
51
+ 'AModule'
52
+ end
53
+ end
54
+ end
55
+ let(:super_class) do
56
+ r = ::Class.new do
57
+ def self.name
58
+ 'SuperClass'
59
+ end
60
+ end
61
+ r.include a_module
62
+ r
63
+ end
64
+ let(:sub_class) do
65
+ r = ::Class.new(super_class) do
66
+ def self.name
67
+ 'SuperClass'
68
+ end
69
+ end
70
+ r
71
+ end
72
+ let(:files_dir) { __dir__.to_pathname.join('template_spec_files') }
73
+ let(:variables_source) { { vx: '_X_', vy: '_Y_' } }
74
+
75
+ let(:a) { instance.template.child('a') }
76
+ let(:a_a) { a.child('a_a') }
77
+ let(:a_b) { a.child('a_b') }
78
+ 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
87
+
88
+ context 'when module is AModule' do # rubocop:disable RSpec/EmptyExampleGroup
89
+ let(:instance) { a_module }
90
+
91
+ dir_specs(:a, %w[a_a])
92
+ file_specs_ok(:a_a, "A_MODULE_A_A\n", "A_MODULE_A_A\n", [])
93
+ file_specs_error(:a_b)
94
+ file_specs_error(:a_c)
95
+ file_specs_ok(:b, "A_MODULE_B%%vy%%\n", "A_MODULE_B_Y_\n", %w[vy])
96
+ file_specs_error(:c)
97
+ end
98
+
99
+ context 'when module is SuperClass' do # rubocop:disable RSpec/EmptyExampleGroup
100
+ let(:instance) { super_class }
101
+
102
+ dir_specs(:a, %w[a_b])
103
+ file_specs_error(:a_a)
104
+ file_specs_ok(:a_b, "SUPER_CLASS_A_B\n", "SUPER_CLASS_A_B\n", [])
105
+ file_specs_error(:a_c)
106
+ file_specs_ok(:b, "SUPER_CLASS_B\n", "SUPER_CLASS_B\n", [])
107
+ file_specs_error(:c)
108
+ end
109
+
110
+ context 'when module is SubClass' do # rubocop:disable RSpec/EmptyExampleGroup
111
+ let(:instance) { sub_class }
112
+
113
+ dir_specs(:a, %w[a_b])
114
+ file_specs_error(:a_a)
115
+ file_specs_ok(:a_b, "SUPER_CLASS_A_B\n", "SUPER_CLASS_A_B\n", [])
116
+ file_specs_error(:a_c)
117
+ file_specs_ok(:b, "SUPER_CLASS_B\n", "SUPER_CLASS_B\n", [])
118
+ file_specs_error(:c)
119
+ end
120
+ end