itamae-default_attributes 0.1.0 → 0.1.1

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: 2c6d0e201cbff0a51d265c0bad1fa2eab1765254
4
- data.tar.gz: 8c33106007c1aa876f5f0643273e755a2884b755
3
+ metadata.gz: 957c6c9b309794648a67895b28dcdf1c62bf5a5b
4
+ data.tar.gz: fc5135ff3747da90969cc17d27e3f548a98cdd34
5
5
  SHA512:
6
- metadata.gz: 16095246a9af8e905bd544233153c49cb226f72595a9361f175fef40fef142483ea5f72a6096cf9c86f2c395a630992e374856cfbb86590bec2d8353a9098311
7
- data.tar.gz: 6fa61553abc0d612f622a172557f2f43f96c18d671b17b70dddc3ecbb45f059c9fb4130e86209443164f4553e97982a13828b0f8ec47ac06d72d65d09e33c1a2
6
+ metadata.gz: e558c319411b5ec1fbfe8722e6d6cdc64571de499b1f8443c76d6f2c5cac15338ff1b95732e04d3bfd1a70e0c134a56984b8bbbabd84b49d4bd72bc80e350c4d
7
+ data.tar.gz: 70624f1f52d9245149d9e16ae23b40eb25f0dd00332cd3d1be586847237e1c7d06430e00be2f205b6fc12db83ca28e095755be9b6e0a2186c1c5711c40ad0f0f
@@ -2,13 +2,12 @@ require "itamae/default_attributes/version"
2
2
 
3
3
  module Itamae
4
4
  module DefaultAttributes
5
- def self.loaded_paths
6
- @loaded_paths ||= []
7
- end
8
5
  end
9
6
  end
10
7
 
11
- require "itamae/default_attributes/eval_context"
8
+ require "itamae/default_attributes/attributes_loader"
12
9
  require "itamae/default_attributes/extension"
13
10
 
11
+ require "itamae/recipe"
12
+
14
13
  Itamae::Recipe.send(:prepend, Itamae::DefaultAttributes::Extension)
@@ -0,0 +1,36 @@
1
+ module Itamae
2
+ module DefaultAttributes
3
+ class AttributesLoader
4
+ class << self
5
+ def loaded?(path)
6
+ loaded_paths.include?(path)
7
+ end
8
+
9
+ def loaded_paths
10
+ @loaded_paths ||= []
11
+ end
12
+ end
13
+
14
+ attr_reader :recipe, :path
15
+
16
+ def initialize(recipe, path)
17
+ @recipe = recipe
18
+ @path = path
19
+ end
20
+
21
+ def load
22
+ return if self.class.loaded?(path)
23
+ return unless File.exist?(path)
24
+
25
+ instance_eval(File.read(path), path, 1)
26
+ self.class.loaded_paths << path
27
+ end
28
+
29
+ private
30
+
31
+ def attributes(attributes_hash)
32
+ recipe.runner.node.reverse_merge!(attributes_hash)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -2,15 +2,13 @@ module Itamae
2
2
  module DefaultAttributes
3
3
  module Extension
4
4
  def load(vars = {})
5
- load_default_attributes
5
+ attributes_loader.load
6
6
  super
7
7
  end
8
8
 
9
- def load_default_attributes
10
- return if Itamae::DefaultAttributes.loaded_paths.include?(attributes_path)
11
- context = Itamae::DefaultAttributes::EvalContext.new
12
- context.instance_eval(File.read(attributes_path), attributes_path, 1)
13
- Itamae::DefaultAttributes.loaded_paths << attributes_path
9
+ def attributes_loader
10
+ @attributes_loader ||=
11
+ Itamae::DefaultAttributes::AttributesLoader.new(self, attributes_path)
14
12
  end
15
13
 
16
14
  def attributes_path
@@ -1,5 +1,5 @@
1
1
  module Itamae
2
2
  module DefaultAttributes
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae-default_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nownabe
@@ -69,7 +69,7 @@ files:
69
69
  - bin/setup
70
70
  - itamae-default_attributes.gemspec
71
71
  - lib/itamae/default_attributes.rb
72
- - lib/itamae/default_attributes/eval_context.rb
72
+ - lib/itamae/default_attributes/attributes_loader.rb
73
73
  - lib/itamae/default_attributes/extension.rb
74
74
  - lib/itamae/default_attributes/version.rb
75
75
  homepage: https://github.com/nownabe/itamae-default_attributes
@@ -1,15 +0,0 @@
1
- module Itamae
2
- module DefaultAttributes
3
- class EvalContext
4
- attr_reader :recipe
5
-
6
- def initialize(recipe)
7
- @recipe = recipe
8
- end
9
-
10
- def attributes(attributes_hash)
11
- recipe.runner.node.reverse_merge!(attributes_hash)
12
- end
13
- end
14
- end
15
- end