buff-config 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/buff/config/ruby.rb +21 -11
- data/lib/buff/config/version.rb +1 -1
- data/spec/buff/config/ruby_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a66d7f7a16bcd62f2884b59fd2349aaca08f4f0
|
4
|
+
data.tar.gz: e2cc963b2f0cb10683667276b5bdc8109bdd6993
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ac38fb86f8601394d17a474c23f54565cbace252555db22df59259bca49bbc564e1531aacd85abe042a1343ce57940b5324c60cd6e80060c4817b5f5ad85d2d
|
7
|
+
data.tar.gz: a80b37ee7c68da0df03c8717e905d41fe3db6bacfa37cd49253344440b95230027e87ab541f832bf9db6300f955fc35669a80318c68a094b2c18c90a88cdb7d9
|
data/lib/buff/config/ruby.rb
CHANGED
@@ -8,17 +8,24 @@ module Buff
|
|
8
8
|
# Parse the contents of the Ruby file into a Hash.
|
9
9
|
#
|
10
10
|
# @param [String] contents
|
11
|
+
# @param [String] path file that should be used as __FILE__
|
12
|
+
# during eval
|
13
|
+
# @param [Object] context the parent Config object
|
11
14
|
#
|
12
15
|
# @return [Hash]
|
13
|
-
def parse(contents)
|
14
|
-
self.new(contents).send(:attributes)
|
16
|
+
def parse(contents, path=nil, context=nil)
|
17
|
+
self.new(contents, path, context).send(:attributes)
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
21
|
# @param [String] contents
|
19
|
-
|
22
|
+
# @param [String] path
|
23
|
+
# @param [Object] context
|
24
|
+
def initialize(contents, path=nil, context=nil)
|
25
|
+
path ||= "(buff-config)"
|
26
|
+
@context = context
|
20
27
|
@attributes = Hash.new
|
21
|
-
instance_eval(contents)
|
28
|
+
instance_eval(contents, path)
|
22
29
|
rescue Exception => ex
|
23
30
|
raise Errors::InvalidConfig, ex
|
24
31
|
end
|
@@ -31,6 +38,8 @@ module Buff
|
|
31
38
|
def method_missing(m, *args, &block)
|
32
39
|
if args.size > 0
|
33
40
|
attributes[m.to_sym] = (args.length == 1) ? args[0] : args
|
41
|
+
elsif @context && @context.respond_to?(m)
|
42
|
+
@context.send(m, *args, &block)
|
34
43
|
else
|
35
44
|
super
|
36
45
|
end
|
@@ -42,11 +51,12 @@ module Buff
|
|
42
51
|
end
|
43
52
|
|
44
53
|
class << self
|
45
|
-
# @param [String]
|
54
|
+
# @param [String] contents
|
55
|
+
# @param [String] path
|
46
56
|
#
|
47
57
|
# @return [Buff::Config::Ruby]
|
48
|
-
def from_ruby(contents)
|
49
|
-
new.from_ruby(contents)
|
58
|
+
def from_ruby(contents, path=nil)
|
59
|
+
new.from_ruby(contents, path)
|
50
60
|
end
|
51
61
|
|
52
62
|
# @param [String] path
|
@@ -57,7 +67,7 @@ module Buff
|
|
57
67
|
def from_file(path)
|
58
68
|
path = File.expand_path(path)
|
59
69
|
contents = File.read(path)
|
60
|
-
new(path).from_ruby(contents)
|
70
|
+
new(path).from_ruby(contents, path)
|
61
71
|
rescue TypeError, Errno::ENOENT, Errno::EISDIR
|
62
72
|
raise Errors::ConfigNotFound, "No configuration found at: '#{path}'"
|
63
73
|
end
|
@@ -93,14 +103,14 @@ module Buff
|
|
93
103
|
|
94
104
|
def initialize(path = nil, options = {})
|
95
105
|
super
|
96
|
-
from_ruby(File.read(path)) if path && File.exists?(path)
|
106
|
+
from_ruby(File.read(path), path) if path && File.exists?(path)
|
97
107
|
end
|
98
108
|
|
99
109
|
# @raise [Buff::Errors::InvalidConfig]
|
100
110
|
#
|
101
111
|
# @return [Buff::Config::Ruby]
|
102
|
-
def from_ruby(contents)
|
103
|
-
hash = Buff::Config::Ruby::Evaluator.parse(contents)
|
112
|
+
def from_ruby(contents, path=nil)
|
113
|
+
hash = Buff::Config::Ruby::Evaluator.parse(contents, path, self)
|
104
114
|
mass_assign(hash)
|
105
115
|
self
|
106
116
|
end
|
data/lib/buff/config/version.rb
CHANGED
@@ -4,9 +4,12 @@ require 'buff/config/ruby'
|
|
4
4
|
describe Buff::Config::Ruby do
|
5
5
|
let(:ruby) do
|
6
6
|
%(
|
7
|
+
current_dir = File.dirname(__FILE__)
|
7
8
|
log_level :info
|
8
9
|
log_location STDOUT
|
9
10
|
cookbook_path ['cookbooks']
|
11
|
+
knife[:foo] = 'bar'
|
12
|
+
knife[:key] = "\#{current_dir}/key.pem"
|
10
13
|
)
|
11
14
|
end
|
12
15
|
|
@@ -16,6 +19,7 @@ describe Buff::Config::Ruby do
|
|
16
19
|
attribute :log_location
|
17
20
|
attribute :node_name, default: 'bacon'
|
18
21
|
attribute :cookbook_path
|
22
|
+
attribute :knife, default: {}
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
@@ -34,6 +38,13 @@ describe Buff::Config::Ruby do
|
|
34
38
|
expect(config[:log_location]).to eq(STDOUT)
|
35
39
|
expect(config[:node_name]).to eq('bacon')
|
36
40
|
expect(config[:cookbook_path]).to eq(['cookbooks'])
|
41
|
+
expect(config[:knife][:foo]).to eq('bar')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'properly sets the calling file' do
|
45
|
+
config = subject.from_ruby(ruby, '/home/annie/.chef/knife.rb')
|
46
|
+
|
47
|
+
expect(config[:knife][:key]).to eq ('/home/annie/.chef/key.pem')
|
37
48
|
end
|
38
49
|
end
|
39
50
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buff-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Winsor
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: varia_model
|