config_templates 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/autoload.rb +2 -1
- data/lib/config_templates/collections/components.rb +30 -0
- data/lib/config_templates/{repositories → collections}/engines.rb +2 -2
- data/lib/config_templates/collections/extensions.rb +28 -0
- data/lib/config_templates/{repositories → collections}/outputs.rb +1 -1
- data/lib/config_templates/collections/settings.rb +15 -0
- data/lib/config_templates/collections/templates.rb +16 -0
- data/lib/config_templates/collections/validators.rb +23 -0
- data/lib/config_templates/config.rb +10 -4
- data/lib/config_templates/contexts/compilation.rb +11 -7
- data/lib/config_templates/contexts/rendering.rb +20 -19
- data/lib/config_templates/criteria/composite.rb +3 -3
- data/lib/config_templates/criteria/name.rb +2 -2
- data/lib/config_templates/criteria/path.rb +11 -0
- data/lib/config_templates/directives/include.rb +9 -0
- data/lib/config_templates/directives/invocation.rb +11 -0
- data/lib/config_templates/directives/stage.rb +23 -0
- data/lib/config_templates/engines/erb.rb +3 -3
- data/lib/config_templates/engines/text.rb +2 -2
- data/lib/config_templates/errors.rb +1 -0
- data/lib/config_templates/models/compilation.rb +6 -5
- data/lib/config_templates/models/component.rb +19 -16
- data/lib/config_templates/models/template.rb +7 -7
- data/lib/config_templates/outputs/filesystem.rb +4 -4
- data/lib/config_templates/outputs/stdout.rb +1 -1
- data/lib/config_templates/version.rb +1 -1
- data/lib/config_templates.rb +1 -0
- data/lib/ioc_config.rb +7 -6
- data/spec/fixtures/src/kapacitor/config.erb +1 -3
- data/spec/fixtures/src/kapacitor/include.erb +3 -0
- data/spec/mocks/outputs/test.rb +1 -1
- data/spec/mocks/validators/test.rb +15 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/templates_spec.rb +25 -7
- metadata +31 -7
- data/lib/config_templates/repositories/settings.rb +0 -15
- data/lib/config_templates/repositories/templates.rb +0 -16
- data/lib/config_templates/repositories/validators.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2819660249db42a27e0a885f569a1a9cd94f8d44
|
4
|
+
data.tar.gz: ea65ab18c2b310e9dabeba9f515037bc501dd5cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c110fccc3f5ddddf266a0de407ca7fd36cd6e2c2a5c92d5da5891b6822b774e39e8cbc9c838b425a5e932d3a67af17d3e16a6ca6e5192f1519bc7eab0dcbe353
|
7
|
+
data.tar.gz: e857341a1314ff40eddea158e5f9a7d6c7a0e08999b5d7687bd8bf8647ef0a0e226f9b3bd1b19c363a505cf964b9dd824f06ef81ad128e49d9b663ac5322c9ff
|
data/lib/autoload.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
module ConfigTemplates::Collections
|
2
|
+
class Components
|
3
|
+
def initialize(criteria)
|
4
|
+
@criteria = criteria
|
5
|
+
@components = {}
|
6
|
+
end
|
7
|
+
|
8
|
+
def <<(component)
|
9
|
+
@components[component.source_path] = component
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_all
|
13
|
+
@criteria.filter(@components).lazy
|
14
|
+
.reject { |_, component| component.child? }
|
15
|
+
.map { |_, component| component }
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_by_path!(path)
|
19
|
+
find_by! ConfigTemplates::Criteria::Path.new path
|
20
|
+
rescue
|
21
|
+
raise ConfigTemplates::Errors::ComponentNotFound, path
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_by!(criteria)
|
25
|
+
criteria.filter(@components).first.last
|
26
|
+
rescue
|
27
|
+
raise ConfigTemplates::Errors::ComponentNotFound
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module ConfigTemplates::
|
1
|
+
module ConfigTemplates::Collections
|
2
2
|
class Engines
|
3
3
|
def initialize
|
4
4
|
@default = ::ConfigTemplates::Engines::Text.new
|
@@ -14,7 +14,7 @@ module ConfigTemplates::Repositories
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def find_by(criteria)
|
17
|
-
|
17
|
+
criteria.filter(@engines).first.last
|
18
18
|
rescue
|
19
19
|
@default
|
20
20
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ConfigTemplates::Collections
|
2
|
+
class Extensions
|
3
|
+
def initialize
|
4
|
+
@extensions = {
|
5
|
+
/^.+\?$/ => ::ConfigTemplates::Extensions::Stage,
|
6
|
+
'include' => ::ConfigTemplates::Extensions::Include
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
def add(extensions)
|
11
|
+
@extensions.merge! extensions
|
12
|
+
end
|
13
|
+
|
14
|
+
def exists_with_name?(name)
|
15
|
+
find_by_name(name) != nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_by_name(name)
|
19
|
+
find_by ::ConfigTemplates::Criteria::Name.new name
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_by(criteria)
|
23
|
+
criteria.filter(@extensions).first.last
|
24
|
+
rescue
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ConfigTemplates::Collections
|
2
|
+
class Settings
|
3
|
+
include ::ConfigTemplates::Inject['files.locator']
|
4
|
+
|
5
|
+
def initialize(locator)
|
6
|
+
@locator = locator
|
7
|
+
end
|
8
|
+
|
9
|
+
def find_all
|
10
|
+
@find_all ||= @locator.settings.reduce({}) do |result, current|
|
11
|
+
::DeepMerge.deep_merge! ::YAML.load_file(current, Hash.new), result
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ConfigTemplates::Collections
|
2
|
+
class Templates
|
3
|
+
include ::ConfigTemplates::Inject['config', 'files.locator']
|
4
|
+
|
5
|
+
def initialize(config, locator)
|
6
|
+
@config = config
|
7
|
+
@locator = locator
|
8
|
+
end
|
9
|
+
|
10
|
+
def find_all
|
11
|
+
@locator.templates.map do |path|
|
12
|
+
::ConfigTemplates::Models::Template.new path, @config
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ConfigTemplates::Collections
|
2
|
+
class Validators
|
3
|
+
def initialize
|
4
|
+
@validators = {}
|
5
|
+
end
|
6
|
+
|
7
|
+
def add(validators)
|
8
|
+
@validators.merge! validators
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_by_file_name(file_name)
|
12
|
+
::ConfigTemplates::Validators::Composite.new find_all_by_file_name file_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_all_by_file_name(file_name)
|
16
|
+
find_all_by ::ConfigTemplates::Criteria::Name.new file_name
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_all_by(criteria)
|
20
|
+
criteria.filter(@validators).values
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module ConfigTemplates
|
2
2
|
class Config
|
3
3
|
include ConfigTemplates::Inject[
|
4
|
-
'
|
5
|
-
'
|
6
|
-
'
|
4
|
+
'collections.extensions',
|
5
|
+
'collections.validators',
|
6
|
+
'collections.engines',
|
7
|
+
'collections.outputs'
|
7
8
|
]
|
8
9
|
|
9
10
|
attr_accessor :templates_path, :destination_path
|
@@ -11,11 +12,12 @@ module ConfigTemplates
|
|
11
12
|
attr_accessor :stages
|
12
13
|
attr_reader :stage
|
13
14
|
|
14
|
-
def initialize(validators, engines, outputs)
|
15
|
+
def initialize(extensions, validators, engines, outputs)
|
15
16
|
@stages = []
|
16
17
|
@engines = engines
|
17
18
|
@outputs = outputs
|
18
19
|
@validators = validators
|
20
|
+
@extensions = extensions
|
19
21
|
end
|
20
22
|
|
21
23
|
def stage=(stage)
|
@@ -37,5 +39,9 @@ module ConfigTemplates
|
|
37
39
|
def validators(validators)
|
38
40
|
@validators.add validators
|
39
41
|
end
|
42
|
+
|
43
|
+
def extensions(extensions)
|
44
|
+
@extensions.add extensions
|
45
|
+
end
|
40
46
|
end
|
41
47
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module ConfigTemplates::Contexts
|
2
2
|
class Compilation
|
3
3
|
include ConfigTemplates::Inject[
|
4
|
-
'
|
5
|
-
'
|
6
|
-
'
|
4
|
+
'collections.templates',
|
5
|
+
'collections.validators',
|
6
|
+
'collections.engines'
|
7
7
|
]
|
8
8
|
|
9
9
|
def initialize(templates, validators, engines)
|
@@ -18,15 +18,19 @@ module ConfigTemplates::Contexts
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def components
|
21
|
-
|
22
|
-
::ConfigTemplates::
|
21
|
+
::ConfigTemplates::Collections::Components.new(@criteria).tap do |collection|
|
22
|
+
context = ::ConfigTemplates::Contexts::Rendering.new
|
23
|
+
context.components = collection
|
24
|
+
@templates.find_all.each { |template| collection << component(template, context) }
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
28
|
private
|
27
29
|
|
28
|
-
def context
|
29
|
-
|
30
|
+
def component(template, context)
|
31
|
+
validator = @validators.find_by_file_name template.source_path
|
32
|
+
engine = @engines.find_by_extension template.extension
|
33
|
+
::ConfigTemplates::Models::Component.new template, context, validator, engine
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
@@ -1,14 +1,25 @@
|
|
1
1
|
module ConfigTemplates::Contexts
|
2
2
|
class Rendering
|
3
|
-
include ::ConfigTemplates::Inject[
|
3
|
+
include ::ConfigTemplates::Inject[
|
4
|
+
'collections.extensions',
|
5
|
+
'collections.settings',
|
6
|
+
'config'
|
7
|
+
]
|
4
8
|
|
5
|
-
|
9
|
+
attr_accessor :components
|
10
|
+
|
11
|
+
def initialize(extensions, settings, config)
|
12
|
+
@extensions = extensions
|
6
13
|
@settings = settings
|
7
14
|
@config = config
|
8
15
|
end
|
9
16
|
|
10
|
-
def
|
11
|
-
|
17
|
+
def binding
|
18
|
+
::Kernel.binding
|
19
|
+
end
|
20
|
+
|
21
|
+
def param(xpath, default = nil)
|
22
|
+
xpath.split('.').reduce(@settings.find_all) { |value, key| value.fetch key }
|
12
23
|
rescue
|
13
24
|
default
|
14
25
|
end
|
@@ -17,24 +28,14 @@ module ConfigTemplates::Contexts
|
|
17
28
|
@config.stage
|
18
29
|
end
|
19
30
|
|
20
|
-
def method_missing(method_name)
|
21
|
-
|
22
|
-
|
23
|
-
|
31
|
+
def method_missing(method_name, *args, &block)
|
32
|
+
extension_class = @extensions.find_by_name method_name
|
33
|
+
invocation = ::ConfigTemplates::Extensions::Invocation.new method_name, args, block
|
34
|
+
extension_class.new.call(self, invocation) rescue super
|
24
35
|
end
|
25
36
|
|
26
37
|
def respond_to_missing?(method_name)
|
27
|
-
method_name
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def stage?(stage)
|
33
|
-
if @config.stages.include?(stage.to_sym)
|
34
|
-
@config.stage == stage.to_sym
|
35
|
-
else
|
36
|
-
raise ::ConfigTemplates::Errors::StageNotFound, stage
|
37
|
-
end
|
38
|
+
@extensions.exists_with_name?(method_name) || super
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
@@ -4,9 +4,9 @@ module ConfigTemplates::Criteria
|
|
4
4
|
@criteria = criteria
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
@criteria.
|
9
|
-
result
|
7
|
+
def filter(hash)
|
8
|
+
@criteria.reduce({}) do |result, criteria|
|
9
|
+
result.merge criteria.filter hash
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -5,8 +5,8 @@ module ConfigTemplates::Criteria
|
|
5
5
|
@straight = straight
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
@pattern.match?(cast
|
8
|
+
def filter(hash)
|
9
|
+
hash.select { |pattern| @pattern.match?(cast pattern) && @straight }
|
10
10
|
end
|
11
11
|
|
12
12
|
def cast(expression)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ConfigTemplates::Extensions
|
2
|
+
class Stage
|
3
|
+
include ::ConfigTemplates::Inject['config']
|
4
|
+
|
5
|
+
def initialize(config)
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(_, invocation)
|
10
|
+
check invocation.method[0..-2]
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def check(stage)
|
16
|
+
if @config.stages.include?(stage.to_sym)
|
17
|
+
@config.stage == stage.to_sym
|
18
|
+
else
|
19
|
+
raise ::ConfigTemplates::Errors::StageNotFound, stage
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module ConfigTemplates::Engines
|
2
2
|
class ERB
|
3
3
|
def evaluate(template, context)
|
4
|
-
::ERB.new(template).result
|
4
|
+
::ERB.new(template).result context.binding
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def destination_path(path)
|
8
|
+
path.sub '.erb', ''
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module ConfigTemplates::Models
|
2
2
|
class Compilation
|
3
|
-
include ::ConfigTemplates::Inject['
|
3
|
+
include ::ConfigTemplates::Inject['collections.outputs']
|
4
4
|
|
5
5
|
def initialize(outputs)
|
6
6
|
@outputs = outputs
|
@@ -18,10 +18,11 @@ module ConfigTemplates::Models
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def send_to(output_name)
|
21
|
-
@context.components.tap do |
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
@context.components.tap do |collection|
|
22
|
+
collection.find_all.each &:render
|
23
|
+
collection.find_all.each &:validate!
|
24
|
+
output = @outputs.find_by_name output_name
|
25
|
+
collection.find_all.each { |component| output.write component }
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
@@ -1,34 +1,37 @@
|
|
1
1
|
module ConfigTemplates::Models
|
2
2
|
class Component
|
3
|
-
def initialize(template, context,
|
3
|
+
def initialize(template, context, validator, engine)
|
4
4
|
@template = template
|
5
5
|
@context = context
|
6
|
-
@
|
7
|
-
@
|
6
|
+
@validator = validator
|
7
|
+
@engine = engine
|
8
|
+
@child = false
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
|
11
|
+
def child?
|
12
|
+
@child
|
12
13
|
end
|
13
14
|
|
14
|
-
def
|
15
|
-
|
16
|
-
raise ::ConfigTemplates::Errors::InvalidTemplate, @template.path
|
17
|
-
end
|
15
|
+
def child!
|
16
|
+
@child = true
|
18
17
|
end
|
19
18
|
|
20
|
-
def
|
21
|
-
@
|
19
|
+
def source_path
|
20
|
+
@template.source_path
|
22
21
|
end
|
23
22
|
|
24
|
-
|
23
|
+
def destination_path
|
24
|
+
@engine.destination_path @template.destination_path
|
25
|
+
end
|
25
26
|
|
26
|
-
def
|
27
|
-
@validator
|
27
|
+
def validate!
|
28
|
+
unless @validator.valid? render
|
29
|
+
raise ::ConfigTemplates::Errors::InvalidTemplate, source_path
|
30
|
+
end
|
28
31
|
end
|
29
32
|
|
30
|
-
def
|
31
|
-
@
|
33
|
+
def render
|
34
|
+
@render ||= @engine.evaluate @template.content, @context
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module ConfigTemplates::Models
|
2
2
|
class Template
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :source_path
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
@
|
5
|
+
def initialize(source_path, config)
|
6
|
+
@source_path = source_path
|
7
7
|
@config = config
|
8
8
|
end
|
9
9
|
|
10
10
|
def content
|
11
|
-
@content ||= ::File.read @
|
11
|
+
@content ||= ::File.read @source_path
|
12
12
|
end
|
13
13
|
|
14
14
|
def extension
|
15
|
-
::File.extname @
|
15
|
+
::File.extname @source_path
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
::File.join @config.destination_path, @config.stage.to_s, @
|
18
|
+
def destination_path
|
19
|
+
::File.join @config.destination_path, @config.stage.to_s, @source_path.sub(@config.templates_path, '')
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module ConfigTemplates::Outputs
|
2
2
|
class Filesystem
|
3
|
-
def
|
4
|
-
|
5
|
-
::FileUtils.mkdir_p ::File.dirname
|
6
|
-
::File.write
|
3
|
+
def write(component)
|
4
|
+
destination_path = component.destination_path
|
5
|
+
::FileUtils.mkdir_p ::File.dirname destination_path
|
6
|
+
::File.write destination_path, component.render
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
data/lib/config_templates.rb
CHANGED
data/lib/ioc_config.rb
CHANGED
@@ -10,11 +10,12 @@ require 'dry-container'
|
|
10
10
|
register(:locator, memoize: true) { ::ConfigTemplates::Filesystem::Locator.new }
|
11
11
|
end
|
12
12
|
|
13
|
-
container.namespace :
|
14
|
-
register(:engines, memoize: true) { ::ConfigTemplates::
|
15
|
-
register(:outputs, memoize: true) { ::ConfigTemplates::
|
16
|
-
register(:settings, memoize: true) { ::ConfigTemplates::
|
17
|
-
register(:templates, memoize: true) { ::ConfigTemplates::
|
18
|
-
register(:validators, memoize: true) { ::ConfigTemplates::
|
13
|
+
container.namespace :collections do
|
14
|
+
register(:engines, memoize: true) { ::ConfigTemplates::Collections::Engines.new }
|
15
|
+
register(:outputs, memoize: true) { ::ConfigTemplates::Collections::Outputs.new }
|
16
|
+
register(:settings, memoize: true) { ::ConfigTemplates::Collections::Settings.new }
|
17
|
+
register(:templates, memoize: true) { ::ConfigTemplates::Collections::Templates.new }
|
18
|
+
register(:validators, memoize: true) { ::ConfigTemplates::Collections::Validators.new }
|
19
|
+
register(:extensions, memoize: true) { ::ConfigTemplates::Collections::Extensions.new }
|
19
20
|
end
|
20
21
|
end
|
data/spec/mocks/outputs/test.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/templates_spec.rb
CHANGED
@@ -2,28 +2,46 @@ require 'config_templates'
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
RSpec.describe ::ConfigTemplates do
|
5
|
-
before(:all) { @output_mock = ::Mocks::Outputs::Test.new }
|
6
5
|
before(:all) do
|
7
|
-
|
6
|
+
@output = ::Mocks::Outputs::Test.new
|
7
|
+
@validator = ::Mocks::Validators::Test.new
|
8
8
|
end
|
9
9
|
|
10
|
-
before(:
|
10
|
+
before(:all) do
|
11
|
+
::ConfigTemplates.configure do |config|
|
12
|
+
config.outputs test: @output
|
13
|
+
config.validators config: @validator
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
@output.result = nil
|
19
|
+
@validator.valid = true
|
20
|
+
end
|
11
21
|
|
12
22
|
it 'renders selected template using configs and environment metadata' do
|
13
23
|
compilation = ::ConfigTemplates::Models::Compilation.new
|
14
|
-
compilation.reject(/.*/).select(Regexp.new 'config.erb')
|
15
|
-
|
24
|
+
compilation.reject(/.*/).select(Regexp.new 'config.erb')
|
25
|
+
compilation.send_to(:test)
|
26
|
+
expect(@output.result.strip).to eq('true')
|
16
27
|
end
|
17
28
|
|
18
29
|
it 'doesnt render not selected template' do
|
19
30
|
compilation = ::ConfigTemplates::Models::Compilation.new
|
20
31
|
compilation.reject(/.*/).send_to(:test)
|
21
|
-
expect(@
|
32
|
+
expect(@output.result).to be_nil
|
22
33
|
end
|
23
34
|
|
24
35
|
it 'doesnt render anything without explicitly selected templates' do
|
25
36
|
compilation = ::ConfigTemplates::Models::Compilation.new
|
26
37
|
compilation.send_to(:test)
|
27
|
-
expect(@
|
38
|
+
expect(@output.result).to be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'fails if validation doesnt pass' do
|
42
|
+
@validator.valid = false
|
43
|
+
compilation = ::ConfigTemplates::Models::Compilation.new
|
44
|
+
compilation.select(Regexp.new 'config.erb')
|
45
|
+
expect { compilation.send_to(:test) }.to raise_error(::ConfigTemplates::Errors::InvalidTemplate, /config/)
|
28
46
|
end
|
29
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- g.ivanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: deep_merge
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: dry-auto_inject
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,11 +117,22 @@ extra_rdoc_files: []
|
|
103
117
|
files:
|
104
118
|
- lib/autoload.rb
|
105
119
|
- lib/config_templates.rb
|
120
|
+
- lib/config_templates/collections/components.rb
|
121
|
+
- lib/config_templates/collections/engines.rb
|
122
|
+
- lib/config_templates/collections/extensions.rb
|
123
|
+
- lib/config_templates/collections/outputs.rb
|
124
|
+
- lib/config_templates/collections/settings.rb
|
125
|
+
- lib/config_templates/collections/templates.rb
|
126
|
+
- lib/config_templates/collections/validators.rb
|
106
127
|
- lib/config_templates/config.rb
|
107
128
|
- lib/config_templates/contexts/compilation.rb
|
108
129
|
- lib/config_templates/contexts/rendering.rb
|
109
130
|
- lib/config_templates/criteria/composite.rb
|
110
131
|
- lib/config_templates/criteria/name.rb
|
132
|
+
- lib/config_templates/criteria/path.rb
|
133
|
+
- lib/config_templates/directives/include.rb
|
134
|
+
- lib/config_templates/directives/invocation.rb
|
135
|
+
- lib/config_templates/directives/stage.rb
|
111
136
|
- lib/config_templates/engines/erb.rb
|
112
137
|
- lib/config_templates/engines/text.rb
|
113
138
|
- lib/config_templates/errors.rb
|
@@ -117,18 +142,15 @@ files:
|
|
117
142
|
- lib/config_templates/models/template.rb
|
118
143
|
- lib/config_templates/outputs/filesystem.rb
|
119
144
|
- lib/config_templates/outputs/stdout.rb
|
120
|
-
- lib/config_templates/repositories/engines.rb
|
121
|
-
- lib/config_templates/repositories/outputs.rb
|
122
|
-
- lib/config_templates/repositories/settings.rb
|
123
|
-
- lib/config_templates/repositories/templates.rb
|
124
|
-
- lib/config_templates/repositories/validators.rb
|
125
145
|
- lib/config_templates/validators/composite.rb
|
126
146
|
- lib/config_templates/version.rb
|
127
147
|
- lib/ioc_config.rb
|
128
148
|
- spec/fixtures/settings/settings.production.yml
|
129
149
|
- spec/fixtures/settings/settings.yml
|
130
150
|
- spec/fixtures/src/kapacitor/config.erb
|
151
|
+
- spec/fixtures/src/kapacitor/include.erb
|
131
152
|
- spec/mocks/outputs/test.rb
|
153
|
+
- spec/mocks/validators/test.rb
|
132
154
|
- spec/spec_helper.rb
|
133
155
|
- spec/templates_spec.rb
|
134
156
|
homepage:
|
@@ -156,8 +178,10 @@ specification_version: 4
|
|
156
178
|
summary: config_templates
|
157
179
|
test_files:
|
158
180
|
- spec/fixtures/src/kapacitor/config.erb
|
181
|
+
- spec/fixtures/src/kapacitor/include.erb
|
159
182
|
- spec/fixtures/settings/settings.yml
|
160
183
|
- spec/fixtures/settings/settings.production.yml
|
161
184
|
- spec/mocks/outputs/test.rb
|
185
|
+
- spec/mocks/validators/test.rb
|
162
186
|
- spec/templates_spec.rb
|
163
187
|
- spec/spec_helper.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ConfigTemplates::Repositories
|
2
|
-
class Settings
|
3
|
-
include ::ConfigTemplates::Inject['files.locator']
|
4
|
-
|
5
|
-
def initialize(locator)
|
6
|
-
@locator = locator
|
7
|
-
end
|
8
|
-
|
9
|
-
def find_all
|
10
|
-
@find_all ||= @locator.settings.reduce({}) {
|
11
|
-
|result, current| result.merge ::YAML.load_file current, Hash.new
|
12
|
-
}
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module ConfigTemplates::Repositories
|
2
|
-
class Templates
|
3
|
-
include ::ConfigTemplates::Inject['config', 'files.locator']
|
4
|
-
|
5
|
-
def initialize(config, locator)
|
6
|
-
@config = config
|
7
|
-
@locator = locator
|
8
|
-
end
|
9
|
-
|
10
|
-
def find_all_by(criteria)
|
11
|
-
@locator.templates
|
12
|
-
.select { |filename| criteria.matches? filename }
|
13
|
-
.map { |filename| ::ConfigTemplates::Models::Template.new filename, @config }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module ConfigTemplates::Repositories
|
2
|
-
class Validators
|
3
|
-
def initialize
|
4
|
-
@validators = {}
|
5
|
-
end
|
6
|
-
|
7
|
-
def add(validators)
|
8
|
-
@validators.merge! validators
|
9
|
-
end
|
10
|
-
|
11
|
-
def find_by_file_name(file_name)
|
12
|
-
::ConfigTemplates::Validators::Composite.new(
|
13
|
-
find_all_by ::ConfigTemplates::Criteria::Name.new file_name
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
def find_all_by(criteria)
|
18
|
-
@validators.select { |(k, _)| criteria.matches?(k) }.values
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|