eac_templates 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_templates/core_ext.rb +1 -1
- data/lib/eac_templates/interface_methods.rb +12 -0
- data/lib/eac_templates/modules/ancestor/directory.rb +15 -0
- data/lib/eac_templates/modules/ancestor/file.rb +15 -0
- data/lib/eac_templates/modules/ancestor/fs_object.rb +32 -0
- data/lib/eac_templates/modules/ancestor.rb +48 -0
- data/lib/eac_templates/modules/base.rb +35 -0
- data/lib/eac_templates/modules.rb +9 -0
- data/lib/eac_templates/patches/module/template.rb +2 -3
- data/lib/eac_templates/sources/directory.rb +24 -0
- data/lib/eac_templates/sources/file.rb +24 -0
- data/lib/eac_templates/sources/from_all_gems.rb +4 -0
- data/lib/eac_templates/sources/from_gem.rb +37 -0
- data/lib/eac_templates/sources/fs_object.rb +53 -0
- data/lib/eac_templates/sources/internal_set.rb +22 -0
- data/lib/eac_templates/sources/set.rb +54 -0
- data/lib/eac_templates/sources/single.rb +29 -0
- data/lib/eac_templates/sources.rb +9 -0
- data/lib/eac_templates/variables/directory.rb +47 -0
- data/lib/eac_templates/variables/file.rb +50 -0
- data/lib/eac_templates/variables/fs_object.rb +65 -0
- data/lib/eac_templates/variables/not_found_error.rb +7 -0
- data/lib/eac_templates/variables/providers/base.rb +23 -0
- data/lib/eac_templates/variables/providers/config_reader.rb +29 -0
- data/lib/eac_templates/variables/providers/entries_reader.rb +25 -0
- data/lib/eac_templates/variables/providers/generic.rb +25 -0
- data/lib/eac_templates/variables/providers/hash.rb +29 -0
- data/lib/eac_templates/variables/providers.rb +25 -0
- data/lib/eac_templates/variables.rb +9 -0
- data/lib/eac_templates/version.rb +1 -1
- metadata +33 -30
- data/lib/eac_templates/directory.rb +0 -108
- data/lib/eac_templates/file.rb +0 -48
- data/lib/eac_templates/from_all_gems.rb +0 -4
- data/lib/eac_templates/from_gem.rb +0 -35
- data/lib/eac_templates/searcher.rb +0 -53
- data/lib/eac_templates/variable_not_found_error.rb +0 -5
- data/lib/eac_templates/variable_providers/base.rb +0 -21
- data/lib/eac_templates/variable_providers/config_reader.rb +0 -27
- data/lib/eac_templates/variable_providers/entries_reader.rb +0 -23
- data/lib/eac_templates/variable_providers/generic.rb +0 -23
- data/lib/eac_templates/variable_providers/hash.rb +0 -27
- data/lib/eac_templates/variable_providers.rb +0 -23
@@ -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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
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:
|
11
|
+
date: 2023-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eac_config
|
@@ -16,40 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.11.1
|
19
|
+
version: '0.12'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0.
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 0.11.1
|
26
|
+
version: '0.12'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: eac_ruby_utils
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: '0.
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 0.102.1
|
33
|
+
version: '0.112'
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
46
37
|
requirements:
|
47
38
|
- - "~>"
|
48
39
|
- !ruby/object:Gem::Version
|
49
|
-
version: '0.
|
50
|
-
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: 0.102.1
|
40
|
+
version: '0.112'
|
53
41
|
- !ruby/object:Gem::Dependency
|
54
42
|
name: eac_ruby_gem_support
|
55
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,10 +60,13 @@ extra_rdoc_files: []
|
|
72
60
|
files:
|
73
61
|
- lib/eac_templates.rb
|
74
62
|
- lib/eac_templates/core_ext.rb
|
75
|
-
- lib/eac_templates/
|
76
|
-
- lib/eac_templates/
|
77
|
-
- lib/eac_templates/
|
78
|
-
- lib/eac_templates/
|
63
|
+
- lib/eac_templates/interface_methods.rb
|
64
|
+
- lib/eac_templates/modules.rb
|
65
|
+
- lib/eac_templates/modules/ancestor.rb
|
66
|
+
- lib/eac_templates/modules/ancestor/directory.rb
|
67
|
+
- lib/eac_templates/modules/ancestor/file.rb
|
68
|
+
- lib/eac_templates/modules/ancestor/fs_object.rb
|
69
|
+
- lib/eac_templates/modules/base.rb
|
79
70
|
- lib/eac_templates/patches.rb
|
80
71
|
- lib/eac_templates/patches/module.rb
|
81
72
|
- lib/eac_templates/patches/module/erb_template.rb
|
@@ -83,14 +74,26 @@ files:
|
|
83
74
|
- lib/eac_templates/patches/object.rb
|
84
75
|
- lib/eac_templates/patches/object/erb_template.rb
|
85
76
|
- lib/eac_templates/patches/object/template.rb
|
86
|
-
- lib/eac_templates/
|
87
|
-
- lib/eac_templates/
|
88
|
-
- lib/eac_templates/
|
89
|
-
- lib/eac_templates/
|
90
|
-
- lib/eac_templates/
|
91
|
-
- lib/eac_templates/
|
92
|
-
- lib/eac_templates/
|
93
|
-
- lib/eac_templates/
|
77
|
+
- lib/eac_templates/sources.rb
|
78
|
+
- lib/eac_templates/sources/directory.rb
|
79
|
+
- lib/eac_templates/sources/file.rb
|
80
|
+
- lib/eac_templates/sources/from_all_gems.rb
|
81
|
+
- lib/eac_templates/sources/from_gem.rb
|
82
|
+
- lib/eac_templates/sources/fs_object.rb
|
83
|
+
- lib/eac_templates/sources/internal_set.rb
|
84
|
+
- lib/eac_templates/sources/set.rb
|
85
|
+
- lib/eac_templates/sources/single.rb
|
86
|
+
- lib/eac_templates/variables.rb
|
87
|
+
- lib/eac_templates/variables/directory.rb
|
88
|
+
- lib/eac_templates/variables/file.rb
|
89
|
+
- lib/eac_templates/variables/fs_object.rb
|
90
|
+
- lib/eac_templates/variables/not_found_error.rb
|
91
|
+
- lib/eac_templates/variables/providers.rb
|
92
|
+
- lib/eac_templates/variables/providers/base.rb
|
93
|
+
- lib/eac_templates/variables/providers/config_reader.rb
|
94
|
+
- lib/eac_templates/variables/providers/entries_reader.rb
|
95
|
+
- lib/eac_templates/variables/providers/generic.rb
|
96
|
+
- lib/eac_templates/variables/providers/hash.rb
|
94
97
|
- lib/eac_templates/version.rb
|
95
98
|
homepage:
|
96
99
|
licenses: []
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_templates/file'
|
4
|
-
|
5
|
-
module EacTemplates
|
6
|
-
class Directory
|
7
|
-
TEMPLATE_EXTNAME = '.template'
|
8
|
-
|
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
|
-
TemplateNode.new(self, '.', directory, variables_source).apply
|
17
|
-
end
|
18
|
-
|
19
|
-
def child(subpath)
|
20
|
-
child_path = ::File.join(path, subpath)
|
21
|
-
return ::EacTemplates::File.new(child_path) if ::File.file?(child_path)
|
22
|
-
return ::EacTemplates::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
|
-
|
46
|
-
class TemplateNode
|
47
|
-
attr_reader :source_directory, :source_relative, :target_root_directory, :variables_source
|
48
|
-
|
49
|
-
def initialize(source_directory, source_relative, target_root_directory, variables_source)
|
50
|
-
@source_directory = source_directory
|
51
|
-
@source_relative = source_relative
|
52
|
-
@target_root_directory = target_root_directory
|
53
|
-
@variables_source = variables_source
|
54
|
-
end
|
55
|
-
|
56
|
-
def apply
|
57
|
-
if file?
|
58
|
-
apply_file
|
59
|
-
elsif directory?
|
60
|
-
apply_directory
|
61
|
-
else
|
62
|
-
raise "Unknown filesystem type: #{source_absolute}"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
|
68
|
-
def apply_directory
|
69
|
-
::FileUtils.mkdir_p(target_absolute)
|
70
|
-
Dir.entries(source_absolute).each do |entry|
|
71
|
-
child(entry).apply unless %w[. ..].include?(entry)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def apply_file
|
76
|
-
if ::File.extname(source_absolute) == TEMPLATE_EXTNAME
|
77
|
-
::EacTemplates::File.new(source_absolute).apply_to_file(
|
78
|
-
variables_source, target_absolute
|
79
|
-
)
|
80
|
-
else
|
81
|
-
::FileUtils.cp(source_absolute, target_absolute)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def child(entry)
|
86
|
-
TemplateNode.new(source_directory, ::File.join(source_relative, entry),
|
87
|
-
target_root_directory, variables_source)
|
88
|
-
end
|
89
|
-
|
90
|
-
def file?
|
91
|
-
::File.file?(source_absolute)
|
92
|
-
end
|
93
|
-
|
94
|
-
def directory?
|
95
|
-
::File.directory?(source_absolute)
|
96
|
-
end
|
97
|
-
|
98
|
-
def source_absolute
|
99
|
-
::File.expand_path(source_relative, source_directory.path)
|
100
|
-
end
|
101
|
-
|
102
|
-
def target_absolute
|
103
|
-
::File.expand_path(source_relative, target_root_directory)
|
104
|
-
.gsub(/#{::Regexp.quote(TEMPLATE_EXTNAME)}\z/, '')
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
data/lib/eac_templates/file.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_ruby_utils/core_ext'
|
4
|
-
require 'eac_templates/variable_providers'
|
5
|
-
|
6
|
-
module EacTemplates
|
7
|
-
class File
|
8
|
-
VARIABLE_DELIMITER = ::Regexp.quote('%%')
|
9
|
-
VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
|
10
|
-
|
11
|
-
enable_simple_cache
|
12
|
-
common_constructor :path do
|
13
|
-
self.path = path.to_pathname
|
14
|
-
end
|
15
|
-
|
16
|
-
# +variables_provider+ A [Hash] or object which responds to +read_entry(entry_name)+.
|
17
|
-
def apply(variables_source)
|
18
|
-
variables_provider = ::EacTemplates::VariableProviders.build(variables_source)
|
19
|
-
variables.inject(content) do |a, e|
|
20
|
-
a.gsub(variable_pattern(e), variables_provider.variable_value(e).to_s)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def apply_to_file(variables_source, output_file_path)
|
25
|
-
output_file_path.to_pathname.write(apply(variables_source))
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def variables_uncached
|
31
|
-
content.scan(VARIABLE_PATTERN).map(&:first).map do |name|
|
32
|
-
sanitize_variable_name(name)
|
33
|
-
end.to_set
|
34
|
-
end
|
35
|
-
|
36
|
-
def content_uncached
|
37
|
-
path.read
|
38
|
-
end
|
39
|
-
|
40
|
-
def sanitize_variable_name(variable_name)
|
41
|
-
variable_name.to_s.downcase
|
42
|
-
end
|
43
|
-
|
44
|
-
def variable_pattern(name)
|
45
|
-
/#{VARIABLE_DELIMITER}#{::Regexp.quote(name)}#{VARIABLE_DELIMITER}/i
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_templates/searcher'
|
4
|
-
|
5
|
-
module EacTemplates
|
6
|
-
class FromGem
|
7
|
-
class << self
|
8
|
-
def include_all(searcher = nil)
|
9
|
-
::Gem::Specification.each { |gemspec| new(gemspec, searcher).include }
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
TEMPLATES_DIR_SUBPATH = 'template'
|
14
|
-
|
15
|
-
common_constructor :gemspec, :searcher, default: [nil] do
|
16
|
-
self.searcher ||= ::EacTemplates::Searcher.default
|
17
|
-
end
|
18
|
-
|
19
|
-
# @return [Boolean]
|
20
|
-
delegate :exist?, to: :path
|
21
|
-
|
22
|
-
# @return [Pathname]
|
23
|
-
def include
|
24
|
-
return nil unless exist?
|
25
|
-
|
26
|
-
searcher.included_paths << path
|
27
|
-
path
|
28
|
-
end
|
29
|
-
|
30
|
-
# @return [Pathname]
|
31
|
-
def path
|
32
|
-
gemspec.gem_dir.to_pathname.join(TEMPLATES_DIR_SUBPATH)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'active_support/core_ext/object/blank'
|
4
|
-
require 'eac_templates/directory'
|
5
|
-
require 'eac_templates/file'
|
6
|
-
|
7
|
-
module EacTemplates
|
8
|
-
class Searcher
|
9
|
-
class << self
|
10
|
-
def default
|
11
|
-
@default ||= new
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def template(subpath, required = true)
|
16
|
-
path = template_path(subpath)
|
17
|
-
if path.blank?
|
18
|
-
return nil unless required
|
19
|
-
|
20
|
-
raise_template_not_found(subpath)
|
21
|
-
end
|
22
|
-
return ::EacTemplates::File.new(path) if ::File.file?(path)
|
23
|
-
return ::EacTemplates::Directory.new(path) if ::File.directory?(path)
|
24
|
-
|
25
|
-
raise 'Invalid branching'
|
26
|
-
end
|
27
|
-
|
28
|
-
# @return The absolute path of template if found, +nil+ otherwise.
|
29
|
-
def template_path(subpath)
|
30
|
-
included_paths.each do |included_path|
|
31
|
-
r = search_template_in_included_path(included_path, subpath)
|
32
|
-
return r if r
|
33
|
-
end
|
34
|
-
nil
|
35
|
-
end
|
36
|
-
|
37
|
-
def included_paths
|
38
|
-
@included_paths ||= ::Set.new
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def raise_template_not_found(subpath)
|
44
|
-
raise "Template not found for subpath \"#{subpath}\"" \
|
45
|
-
" (Included paths: #{included_paths.to_a.join(::File::PATH_SEPARATOR)})"
|
46
|
-
end
|
47
|
-
|
48
|
-
def search_template_in_included_path(included_path, subpath)
|
49
|
-
path = ::File.join(included_path, subpath)
|
50
|
-
::File.exist?(path) ? path : nil
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_templates/variable_not_found_error'
|
4
|
-
|
5
|
-
module EacTemplates
|
6
|
-
module VariableProviders
|
7
|
-
class Base
|
8
|
-
attr_reader :source
|
9
|
-
|
10
|
-
def initialize(source)
|
11
|
-
@source = source
|
12
|
-
end
|
13
|
-
|
14
|
-
def variable_value(name)
|
15
|
-
return variable_fetch(name) if variable_exist?(name)
|
16
|
-
|
17
|
-
raise VariableNotFoundError, "Variable \"#{name}\" not found in #{source}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_config/node'
|
4
|
-
require 'eac_templates/variable_providers/base'
|
5
|
-
|
6
|
-
module EacTemplates
|
7
|
-
module VariableProviders
|
8
|
-
class ConfigReader < ::EacTemplates::VariableProviders::Base
|
9
|
-
class << self
|
10
|
-
def accept?(variables_source)
|
11
|
-
return false unless variables_source.respond_to?(:entry)
|
12
|
-
|
13
|
-
entry = variables_source.entry(:any_value)
|
14
|
-
entry.respond_to?(:value) && entry.respond_to?(:found?)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def variable_exist?(name)
|
19
|
-
source.entry(name).found?
|
20
|
-
end
|
21
|
-
|
22
|
-
def variable_fetch(name)
|
23
|
-
source.entry(name).value
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_templates/variable_providers/base'
|
4
|
-
|
5
|
-
module EacTemplates
|
6
|
-
module VariableProviders
|
7
|
-
class EntriesReader < ::EacTemplates::VariableProviders::Base
|
8
|
-
class << self
|
9
|
-
def accept?(variables_source)
|
10
|
-
variables_source.respond_to?(:read_entry)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def variable_exist?(_name)
|
15
|
-
true
|
16
|
-
end
|
17
|
-
|
18
|
-
def variable_fetch(name)
|
19
|
-
source.read_entry(name)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_templates/variable_providers/base'
|
4
|
-
|
5
|
-
module EacTemplates
|
6
|
-
module VariableProviders
|
7
|
-
class Generic < ::EacTemplates::VariableProviders::Base
|
8
|
-
class << self
|
9
|
-
def accept?(variables_source)
|
10
|
-
variables_source.is_a?(::Object)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def variable_exist?(name)
|
15
|
-
source.respond_to?(name)
|
16
|
-
end
|
17
|
-
|
18
|
-
def variable_fetch(name)
|
19
|
-
source.send(name)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_templates/variable_providers/base'
|
4
|
-
|
5
|
-
module EacTemplates
|
6
|
-
module VariableProviders
|
7
|
-
class Hash < ::EacTemplates::VariableProviders::Base
|
8
|
-
class << self
|
9
|
-
def accept?(variables_source)
|
10
|
-
variables_source.is_a?(::Hash)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(source)
|
15
|
-
super(source.with_indifferent_access)
|
16
|
-
end
|
17
|
-
|
18
|
-
def variable_exist?(name)
|
19
|
-
source.key?(name)
|
20
|
-
end
|
21
|
-
|
22
|
-
def variable_fetch(name)
|
23
|
-
source.fetch(name)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'eac_ruby_utils/core_ext'
|
4
|
-
|
5
|
-
module EacTemplates
|
6
|
-
module VariableProviders
|
7
|
-
require_sub __FILE__
|
8
|
-
|
9
|
-
PROVIDERS = %w[config_reader entries_reader hash generic].map do |name|
|
10
|
-
"eac_templates/variable_providers/#{name}".camelize.constantize
|
11
|
-
end
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def build(variables_source)
|
15
|
-
PROVIDERS.each do |provider|
|
16
|
-
return provider.new(variables_source) if provider.accept?(variables_source)
|
17
|
-
end
|
18
|
-
|
19
|
-
raise "Variables provider not found for #{variables_source}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|