eac_templates 0.3.2 → 0.5.0
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.
- checksums.yaml +4 -4
- data/lib/eac_templates/abstract/directory.rb +42 -0
- data/lib/eac_templates/abstract/file.rb +25 -0
- data/lib/eac_templates/abstract/fs_object.rb +94 -0
- data/lib/eac_templates/abstract/fs_object_by_pathname.rb +13 -0
- data/lib/eac_templates/abstract/not_found_error.rb +8 -0
- 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 +17 -0
- data/lib/eac_templates/modules/ancestor/file.rb +16 -0
- data/lib/eac_templates/modules/ancestor/fs_object.rb +25 -0
- data/lib/eac_templates/modules/ancestor.rb +51 -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 +37 -0
- data/lib/eac_templates/sources/file.rb +13 -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 +55 -0
- data/lib/eac_templates/sources/single.rb +29 -0
- data/lib/eac_templates/sources.rb +9 -0
- data/lib/eac_templates/variables/content.rb +52 -0
- data/lib/eac_templates/variables/directory.rb +49 -0
- data/lib/eac_templates/variables/file.rb +26 -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 +39 -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
@@ -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
|