config_templates 1.1.3 → 1.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97fc70c512563569519b377626daa1fed6184f16
4
- data.tar.gz: 467a9ddc3ec1cdbf156933b6371c1e67705b0abd
3
+ metadata.gz: ed2ef886ddd1d008ef5eac84a4ff9f09dbb8bbad
4
+ data.tar.gz: 575336494ebd01c60efcf01c8bcdae3de8943767
5
5
  SHA512:
6
- metadata.gz: 2c0739c8619d47b979fc00486aeea1fc6f9646cef9026fc9376b3934670193dbc749d072aeede38c3db2729e84bf36b563bfe14ce8fd6552004133e602e55471
7
- data.tar.gz: b66806f532521f416d3e32e788a9404edb8b6ce0f9f80a446667a58f702c827e283581d2bf0af546bf69b5d22291facad8137b07183b4e84e09d29a8bf6676a1
6
+ metadata.gz: b866e4680f05c4cd026d323637bf63b05d752f5250be05a2b56177a8408a07c97495685fbfb9e31c1fee27147b3640f20ab7c9303b422e214311462d39d253ef
7
+ data.tar.gz: 77c7a6a8cc40ed17bbbed10c67addb738be7300b64545c004f466eb5155d687e5568fb9974dc47e6e557b1c5311f3dc8bc350d824871f0313aa73843a452b1ed
@@ -2,6 +2,7 @@ require 'erb'
2
2
  require 'yaml'
3
3
  require 'fileutils'
4
4
  require 'deep_merge/core'
5
+ require 'pathname'
5
6
 
6
7
  module ConfigTemplates
7
8
  def self.configure
@@ -15,8 +15,8 @@ module ConfigTemplates::Collections
15
15
  .map { |_, component| component }
16
16
  end
17
17
 
18
- def find_by_path!(path)
19
- find_by! ConfigTemplates::Criteria::Path.new path
18
+ def find_by_path!(path, relative_to = nil)
19
+ find_by! ConfigTemplates::Criteria::Path.new path, relative_to
20
20
  rescue
21
21
  raise ConfigTemplates::Errors::ComponentNotFound, path
22
22
  end
@@ -1,11 +1,34 @@
1
1
  module ConfigTemplates::Criteria
2
2
  class Path
3
- def initialize(path)
3
+ def initialize(path, relative_to)
4
4
  @path = path
5
+ @relative_to = relative_to
5
6
  end
6
7
 
7
8
  def filter(hash)
8
- hash.key?(@path) ? { @path => hash[@path] } : {}
9
+ if @path.start_with? '@'
10
+ with_absolute_path hash
11
+ else
12
+ with_relative_path hash
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def with_absolute_path(hash)
19
+ hash.key?(@path.sub!('@', '')) ? { @path => hash[@path] } : {}
20
+ end
21
+
22
+ def with_relative_path(hash)
23
+ hash.key?(relative_path) ? { relative_path => hash[relative_path] } : {}
24
+ end
25
+
26
+ def relative_path
27
+ @relative_path ||= begin
28
+ path = ::File.join ::File.dirname(@relative_to), @path
29
+ pathname = ::Pathname.new path
30
+ pathname.cleanpath.to_s
31
+ end
9
32
  end
10
33
  end
11
34
  end
@@ -1,9 +1,12 @@
1
1
  module ConfigTemplates::Extensions
2
2
  class Include
3
3
  def call(context, invocation)
4
- component = context.components.find_by_path! invocation.args.first
5
- component.child!
6
- component.render
4
+ child_component = context.components.find_by_path!(
5
+ invocation.args.first,
6
+ context.component.source_path
7
+ )
8
+ child_component.child!
9
+ child_component.render
7
10
  end
8
11
  end
9
12
  end
@@ -1,3 +1,3 @@
1
1
  module ConfigTemplates
2
- VERSION = '1.1.3'.freeze
2
+ VERSION = '1.1.4'.freeze
3
3
  end
@@ -1 +1 @@
1
- <%= include('spec/fixtures/src/kapacitor/include.erb') %>
1
+ <%= include('include.erb') %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - g.ivanov