kondate 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b4da7ca37a8a499eb627e22c30c879d0b001433
4
- data.tar.gz: 530957c521d781d58baa0fd2a6fe17711d0ac2e6
3
+ metadata.gz: 38db840e774d8575edff8aa3dbbd3d90d46e9dbb
4
+ data.tar.gz: 4988f05f9ff465ead90e59abc233c6101f46d0f7
5
5
  SHA512:
6
- metadata.gz: 10db83b8b9862625811e18ea88e31c483b4cf1ab2956fe25a37fed61da23cab6951c70ca3a4e3693285ae460cc82e6f46b63c9478f2b8659efa848f6fe436698
7
- data.tar.gz: bb83dc554b26890de637ec05f870af4d9a79d9450cea4c723a615847424bee8c3937ec32ba294e3b946e6f0174e50648fa467c19f6ca0306811923e89eddbfd4
6
+ metadata.gz: dcfa3c75c22e6915c0fe3f234b9c1046476ebcf311a346e5f029eeb9fb9722f63d0f8862513af02147127ab8eadf0920660a9ebfe9c4786967bc9d73d7fea988
7
+ data.tar.gz: 9caa081558c981e425fbb34d567b7be60bc1ccd7e7dd2f7a60c5951ad0e7c1eec07ec821ff920f729376bebd257a26d4680c24759ab6523036f7e05bdf577d40
data/.gitignore CHANGED
@@ -16,3 +16,4 @@
16
16
  /hosts.yml
17
17
  .ruby-version
18
18
  /kondate/
19
+ .vagrant
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.1.1 (2015/11/24)
2
+
3
+ Changes:
4
+
5
+ * Do not open Hash class to add deep_merge, instead use own HashExt class.
6
+
1
7
  # 0.1.0 (2015/11/23)
2
8
 
3
9
  first version
10
+
data/README.md CHANGED
@@ -223,6 +223,8 @@ set :set_property, YAML.load_file(ENV['TARGET_NODE_FILE'])
223
223
 
224
224
  because these ENVs are passed by `kondate serverspec`.
225
225
 
226
+ See [templates/spec/spec_helper.rb](./lib/kondate/templates/spec/spec_helper.rb) for an example.
227
+
226
228
  ## Host Plugin
227
229
 
228
230
  The default reads `hosts.yml` to resolve roles of a host, but
@@ -281,6 +283,18 @@ host_plugin:
281
283
 
282
284
  `config.type` and `config.path` is available in the above config.
283
285
 
286
+ ## Development
287
+
288
+ ```
289
+ bundle exec exe/kondate generate
290
+ vagrant up
291
+ ```
292
+
293
+ ```
294
+ bundle exec exe/kondate itamae vagrant-centos --role sample
295
+ bundle exec exe/kondate serverspec vagrant-centos --role sample
296
+ ```
297
+
284
298
  ## ToDo
285
299
 
286
300
  write tests
data/lib/kondate.rb CHANGED
@@ -1,8 +1,10 @@
1
- HOKKE_GEM_ROOT = File.expand_path('..', File.dirname(__FILE__)) unless defined?(HOKKE_GEM_ROOT)
1
+ module Kondate
2
+ ROOT = File.expand_path('../..', __FILE__)
3
+ end
2
4
 
3
5
  require "kondate/version"
4
6
  require "kondate/config"
5
7
  require "kondate/property_builder"
6
- require "ext/hash/deep_merge"
8
+ require "kondate/hash_ext"
7
9
  require "kondate/string_util"
8
10
  require "kondate/error"
data/lib/kondate/cli.rb CHANGED
@@ -31,7 +31,7 @@ module Kondate
31
31
  FileUtils.mkdir_p(File.join(target_dir, dir)) unless @options[:dry_run]
32
32
  end
33
33
 
34
- templates_dir = File.join(HOKKE_GEM_ROOT, 'lib', 'kondate', 'templates')
34
+ templates_dir = File.join(Kondate::ROOT, 'lib', 'kondate', 'templates')
35
35
  templates_dir_length = templates_dir.length
36
36
  Find.find(templates_dir).select {|f| File.file?(f) }.each do |src|
37
37
  dst = File.join(target_dir, src[templates_dir_length+1 .. -1])
@@ -0,0 +1,42 @@
1
+ # activesupport/core_ext/hash/deep_merge.rb
2
+ module Kondate
3
+ class HashExt < ::Hash
4
+ # Returns a new hash with +self+ and +other_hash+ merged recursively.
5
+ #
6
+ # h1 = { a: true, b: { c: [1, 2, 3] } }
7
+ # h2 = { a: false, b: { x: [3, 4, 5] } }
8
+ #
9
+ # h1.deep_merge(h2) #=> { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
10
+ #
11
+ # Like with Hash#merge in the standard library, a block can be provided
12
+ # to merge values:
13
+ #
14
+ # h1 = { a: 100, b: 200, c: { c1: 100 } }
15
+ # h2 = { b: 250, c: { c1: 200 } }
16
+ # h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
17
+ # # => { a: 100, b: 450, c: { c1: 300 } }
18
+ def deep_merge(other_hash, &block)
19
+ dup.deep_merge!(other_hash, &block)
20
+ end
21
+
22
+ # Same as +deep_merge+, but modifies +self+.
23
+ def deep_merge!(other_hash, &block)
24
+ other_hash.each_pair do |current_key, other_value|
25
+ this_value = self[current_key]
26
+
27
+ self[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
28
+ _this_value = HashExt.new.replace(this_value)
29
+ _this_value.deep_merge(other_value, &block).to_h
30
+ else
31
+ if block_given? && key?(current_key)
32
+ block.call(current_key, this_value, other_value)
33
+ else
34
+ other_value
35
+ end
36
+ end
37
+ end
38
+
39
+ self
40
+ end
41
+ end
42
+ end
@@ -74,14 +74,14 @@ module Kondate
74
74
  role_property = get_content(role_file(role))
75
75
  secret_role_property = get_content(secret_role_file(role))
76
76
 
77
- property = {
77
+ property = HashExt.new.deep_merge!({
78
78
  'role' => role,
79
79
  'roles' => roles,
80
80
  'attributes' => {},
81
- }.deep_merge!(role_property).
81
+ }).deep_merge!(role_property).
82
82
  deep_merge!(secret_role_property).
83
83
  deep_merge!(node_property).
84
- deep_merge!(secret_node_property)
84
+ deep_merge!(secret_node_property).to_h
85
85
 
86
86
  # filter out the recipe
87
87
  if filter_recipes and !filter_recipes.empty?
@@ -1,3 +1,3 @@
1
1
  module Kondate
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kondate
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
  - sonots
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-23 00:00:00.000000000 Z
11
+ date: 2015-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: itamae
@@ -133,7 +133,6 @@ files:
133
133
  - exe/kondate
134
134
  - exe/serverspec-kondate
135
135
  - kondate.gemspec
136
- - lib/ext/hash/deep_merge.rb
137
136
  - lib/ext/itamae/attributes.rb
138
137
  - lib/ext/itamae/kondate.rb
139
138
  - lib/ext/serverspec/attributes.rb
@@ -142,6 +141,7 @@ files:
142
141
  - lib/kondate/cli.rb
143
142
  - lib/kondate/config.rb
144
143
  - lib/kondate/error.rb
144
+ - lib/kondate/hash_ext.rb
145
145
  - lib/kondate/host_plugin/file.rb
146
146
  - lib/kondate/property_builder.rb
147
147
  - lib/kondate/string_util.rb
@@ -1,39 +0,0 @@
1
- # activesupport/core_ext/hash/deep_merge.rb
2
- class Hash
3
- # Returns a new hash with +self+ and +other_hash+ merged recursively.
4
- #
5
- # h1 = { a: true, b: { c: [1, 2, 3] } }
6
- # h2 = { a: false, b: { x: [3, 4, 5] } }
7
- #
8
- # h1.deep_merge(h2) #=> { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
9
- #
10
- # Like with Hash#merge in the standard library, a block can be provided
11
- # to merge values:
12
- #
13
- # h1 = { a: 100, b: 200, c: { c1: 100 } }
14
- # h2 = { b: 250, c: { c1: 200 } }
15
- # h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
16
- # # => { a: 100, b: 450, c: { c1: 300 } }
17
- def deep_merge(other_hash, &block)
18
- dup.deep_merge!(other_hash, &block)
19
- end
20
-
21
- # Same as +deep_merge+, but modifies +self+.
22
- def deep_merge!(other_hash, &block)
23
- other_hash.each_pair do |current_key, other_value|
24
- this_value = self[current_key]
25
-
26
- self[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
27
- this_value.deep_merge(other_value, &block)
28
- else
29
- if block_given? && key?(current_key)
30
- block.call(current_key, this_value, other_value)
31
- else
32
- other_value
33
- end
34
- end
35
- end
36
-
37
- self
38
- end
39
- end