railsmachine-shadow_puppet 0.1.17 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/shadow_puppet.rb +0 -1
- data/lib/shadow_puppet/core_ext.rb +17 -3
- data/lib/shadow_puppet/manifest.rb +32 -23
- metadata +2 -12
data/lib/shadow_puppet.rb
CHANGED
@@ -3,8 +3,22 @@ require 'active_support/core_ext/array'
|
|
3
3
|
require 'active_support/inflector'
|
4
4
|
require 'active_support/core_ext/class/inheritable_attributes'
|
5
5
|
require 'active_support/core_ext/duplicable'
|
6
|
-
class
|
7
|
-
def
|
8
|
-
|
6
|
+
class Hash #:nodoc:
|
7
|
+
def deep_merge(other_hash)
|
8
|
+
self.merge(other_hash) do |key, oldval, newval|
|
9
|
+
oldval = oldval.to_hash if oldval.respond_to?(:to_hash)
|
10
|
+
newval = newval.to_hash if newval.respond_to?(:to_hash)
|
11
|
+
oldval.is_a?(Hash) && newval.is_a?(Hash) ? oldval.deep_merge(newval) : newval
|
12
|
+
end
|
13
|
+
end
|
14
|
+
def deep_merge!(other_hash)
|
15
|
+
replace(deep_merge(other_hash))
|
16
|
+
end
|
17
|
+
def deep_symbolize_keys
|
18
|
+
self.inject({}) { |result, (key, value)|
|
19
|
+
value = value.deep_symbolize_keys if value.is_a?(Hash)
|
20
|
+
result[(key.to_sym rescue key) || key] = value
|
21
|
+
result
|
22
|
+
}
|
9
23
|
end
|
10
24
|
end
|
@@ -76,8 +76,8 @@ module ShadowPuppet
|
|
76
76
|
class_inheritable_accessor :recipes
|
77
77
|
write_inheritable_attribute(:recipes, [])
|
78
78
|
attr_reader :puppet_resources
|
79
|
-
class_inheritable_accessor :
|
80
|
-
write_inheritable_attribute(:
|
79
|
+
class_inheritable_accessor :__config__
|
80
|
+
write_inheritable_attribute(:__config__, Hash.new)
|
81
81
|
|
82
82
|
# Initialize a new instance of this manifest. This can take a
|
83
83
|
# config hash, which is immediately passed on to the configure
|
@@ -113,20 +113,12 @@ module ShadowPuppet
|
|
113
113
|
return nil if methods.nil? || methods == []
|
114
114
|
options = methods.extract_options!
|
115
115
|
methods.each do |meth|
|
116
|
-
options =
|
116
|
+
options = configuration[meth.to_sym] if options == {}
|
117
117
|
options ||= {}
|
118
118
|
recipes << [meth.to_sym, options]
|
119
119
|
end
|
120
120
|
end
|
121
121
|
|
122
|
-
def self.configatron
|
123
|
-
__configatron__
|
124
|
-
end
|
125
|
-
|
126
|
-
def configatron
|
127
|
-
self.class.__configatron__
|
128
|
-
end
|
129
|
-
|
130
122
|
# A hash describing any configuration that has been
|
131
123
|
# performed on the class. Modify this hash by calling configure:
|
132
124
|
#
|
@@ -135,15 +127,24 @@ module ShadowPuppet
|
|
135
127
|
# end
|
136
128
|
#
|
137
129
|
# >> SampleManifest.configuration
|
138
|
-
# => {
|
130
|
+
# => {:name => 'test'}
|
131
|
+
#
|
132
|
+
# All keys on this hash are coerced into symbols for ease of access.
|
139
133
|
#
|
140
134
|
# Subclasses of the Manifest class properly inherit the parent classes'
|
141
135
|
# configuration.
|
142
136
|
def self.configuration
|
143
|
-
|
137
|
+
__config__.deep_symbolize_keys
|
144
138
|
end
|
145
139
|
|
146
|
-
# Access to the configuration of the
|
140
|
+
# Access to the configuration of the class of this instance.
|
141
|
+
#
|
142
|
+
# class SampleManifest < ShadowPuppet::Manifest
|
143
|
+
# configure(:name => 'test')
|
144
|
+
# end
|
145
|
+
#
|
146
|
+
# @manifest = SampleManifest.new
|
147
|
+
# @manifest.configuration[:name] => "test"
|
147
148
|
def configuration
|
148
149
|
self.class.configuration
|
149
150
|
end
|
@@ -151,24 +152,32 @@ module ShadowPuppet
|
|
151
152
|
# Define configuration on this manifest. This is useful for storing things
|
152
153
|
# such as hostnames, password, or usernames that may change between
|
153
154
|
# different implementations of a shared manifest. Access this hash by
|
154
|
-
# calling configuration
|
155
|
+
# calling <tt>configuration</tt>:
|
155
156
|
#
|
156
157
|
# class SampleManifest < ShadowPuppet::Manifest
|
157
|
-
# configure(
|
158
|
+
# configure('name' => 'test')
|
158
159
|
# end
|
159
160
|
#
|
160
161
|
# >> SampleManifest.configuration
|
161
|
-
# => {
|
162
|
+
# => {:name => 'test'}
|
163
|
+
#
|
164
|
+
# All keys on this hash are coerced into symbols for ease of access.
|
162
165
|
#
|
163
|
-
# Subsequent calls to configure perform a deep_merge of the
|
164
|
-
#
|
166
|
+
# Subsequent calls to configure perform a deep_merge of the provided
|
167
|
+
# <tt>hash</tt> into the pre-existing configuration.
|
165
168
|
def self.configure(hash)
|
166
|
-
|
169
|
+
__config__.deep_merge!(hash)
|
167
170
|
end
|
168
171
|
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
+
# Update the configuration of this manifest instance's class.
|
173
|
+
#
|
174
|
+
# class SampleManifest < ShadowPuppet::Manifest
|
175
|
+
# configure({})
|
176
|
+
# end
|
177
|
+
#
|
178
|
+
# @manifest = SampleManifest.new
|
179
|
+
# @manifest.configure(:name => "test")
|
180
|
+
# @manifest.configuration[:name] => "test"
|
172
181
|
def configure(hash)
|
173
182
|
self.class.configure(hash)
|
174
183
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railsmachine-shadow_puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Newland
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-12 00:00:00 -07:00
|
13
13
|
default_executable: shadow_puppet
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -62,16 +62,6 @@ dependencies:
|
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: 2.0.0
|
64
64
|
version:
|
65
|
-
- !ruby/object:Gem::Dependency
|
66
|
-
name: configatron
|
67
|
-
type: :runtime
|
68
|
-
version_requirement:
|
69
|
-
version_requirements: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - ">="
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: 2.2.2
|
74
|
-
version:
|
75
65
|
description: A Ruby Puppet DSL
|
76
66
|
email:
|
77
67
|
- jesse@railsmachine.com
|