nugrant 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +9 -2
- data/lib/nugrant.rb +0 -1
- data/lib/nugrant/bag.rb +44 -0
- data/lib/nugrant/parameters.rb +3 -1
- data/lib/nugrant/version.rb +1 -1
- data/nugrant.gemspec +2 -2
- data/test/lib/nugrant/test_parameters.rb +3 -3
- data/test/lib/nugrant/test_parameters_bag.rb +3 -3
- metadata +7 -7
- data/lib/nugrant/parameter_bag.rb +0 -53
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# 0.0.14
|
2
|
+
|
3
|
+
* Renamed `ParameterBag` to `Bag`
|
4
|
+
* Cleanup `Bag` api
|
5
|
+
* Renamed method `has_param?` to `has_key?` in `Bag`
|
6
|
+
* Removed method `get_params` from `Bag`
|
7
|
+
|
1
8
|
# 0.0.13
|
2
9
|
|
3
10
|
* Cleanup `Parameters` and `ParameterBag` interface
|
@@ -24,8 +31,8 @@
|
|
24
31
|
|
25
32
|
# 0.0.10
|
26
33
|
|
27
|
-
* Added a subcommand `parameters` for vagrant command `user
|
28
|
-
* Added a vagrant command `vagrant user subcommand [options]
|
34
|
+
* Added a subcommand `parameters` for vagrant command `user`
|
35
|
+
* Added a vagrant command `vagrant user subcommand [options]`
|
29
36
|
|
30
37
|
# 0.0.9
|
31
38
|
|
data/lib/nugrant.rb
CHANGED
data/lib/nugrant/bag.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Nugrant
|
2
|
+
class Bag
|
3
|
+
def initialize(hash)
|
4
|
+
@bag = recompute(hash)
|
5
|
+
end
|
6
|
+
|
7
|
+
def recompute(hash)
|
8
|
+
@bag = {}
|
9
|
+
return @bag if hash == nil
|
10
|
+
|
11
|
+
hash.each do |key, value|
|
12
|
+
if not value.is_a?(Hash)
|
13
|
+
@bag[key] = value
|
14
|
+
next
|
15
|
+
end
|
16
|
+
|
17
|
+
# It is a hash, transform it into a bag
|
18
|
+
@bag[key] = Nugrant::Bag.new(value)
|
19
|
+
end
|
20
|
+
|
21
|
+
return @bag
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](key)
|
25
|
+
return fetch(key)
|
26
|
+
end
|
27
|
+
|
28
|
+
def method_missing(method, *args, &block)
|
29
|
+
return fetch(method.to_s)
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_key?(key)
|
33
|
+
return @bag.has_key?(key)
|
34
|
+
end
|
35
|
+
|
36
|
+
def fetch(key)
|
37
|
+
if not has_key?(key)
|
38
|
+
raise KeyError, "Undefined parameter '#{key}'"
|
39
|
+
end
|
40
|
+
|
41
|
+
return @bag[key]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/nugrant/parameters.rb
CHANGED
@@ -3,8 +3,10 @@ require 'json'
|
|
3
3
|
require 'ostruct'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
+
require 'nugrant/bag'
|
7
|
+
|
6
8
|
module Nugrant
|
7
|
-
class Parameters < Nugrant::
|
9
|
+
class Parameters < Nugrant::Bag
|
8
10
|
attr_reader :defaults, :system, :user, :project, :all
|
9
11
|
|
10
12
|
def initialize(config = nil)
|
data/lib/nugrant/version.rb
CHANGED
data/nugrant.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.name = "nugrant"
|
9
9
|
gem.version = Nugrant::VERSION
|
10
10
|
gem.authors = ["Matthieu Vachon"]
|
11
|
-
gem.email = ["matthieu.
|
12
|
-
gem.homepage = "https://github.com/
|
11
|
+
gem.email = ["matthieu.o.vachon@gmail.com"]
|
12
|
+
gem.homepage = "https://github.com/maoueh/nugrant"
|
13
13
|
gem.summary = "Vagrant plugin to enable user specific configuration parameters."
|
14
14
|
gem.description = <<-EOF
|
15
15
|
This gem is in fact a Vagrant plugin. By installing this gem, it will be
|
@@ -28,7 +28,7 @@ class Nugrant::TestParameters < Test::Unit::TestCase
|
|
28
28
|
assert_equal(value, parameters[key], "array[#{key}]")
|
29
29
|
end
|
30
30
|
|
31
|
-
assert_equal(false, parameters.
|
31
|
+
assert_equal(false, parameters.has_key?("0.0.0"))
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_params_level_1()
|
@@ -109,7 +109,7 @@ class Nugrant::TestParameters < Test::Unit::TestCase
|
|
109
109
|
"0.0.1" => "system",
|
110
110
|
})
|
111
111
|
|
112
|
-
assert_equal(false, parameters.
|
112
|
+
assert_equal(false, parameters.has_key?("0.0.0"))
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
@@ -117,7 +117,7 @@ class Nugrant::TestParameters < Test::Unit::TestCase
|
|
117
117
|
assert_level(parameters.send(key), results)
|
118
118
|
assert_level(parameters[key], results)
|
119
119
|
|
120
|
-
assert_equal(false, parameters.
|
120
|
+
assert_equal(false, parameters.has_key?("0.0.0"))
|
121
121
|
end
|
122
122
|
|
123
123
|
def test_file_nil()
|
@@ -2,13 +2,13 @@ require 'nugrant'
|
|
2
2
|
require 'nugrant/parameters'
|
3
3
|
require 'test/unit'
|
4
4
|
|
5
|
-
class Nugrant::
|
5
|
+
class Nugrant::TestBag < Test::Unit::TestCase
|
6
6
|
def create_bag(parameters)
|
7
|
-
return Nugrant::
|
7
|
+
return Nugrant::Bag.new(parameters)
|
8
8
|
end
|
9
9
|
|
10
10
|
def assert_bag(parameters, bag)
|
11
|
-
assert_kind_of(Nugrant::
|
11
|
+
assert_kind_of(Nugrant::Bag, bag)
|
12
12
|
|
13
13
|
parameters.each do |key, value|
|
14
14
|
if not value.is_a?(Hash)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nugrant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: deep_merge
|
@@ -65,7 +65,7 @@ description: ! " This gem is in fact a Vagrant plugin. By installing this ge
|
|
65
65
|
to\n share a Vagrantfile to multiple developers but would like to customize\n
|
66
66
|
\ some parameters for each users differently.\n"
|
67
67
|
email:
|
68
|
-
- matthieu.
|
68
|
+
- matthieu.o.vachon@gmail.com
|
69
69
|
executables: []
|
70
70
|
extensions: []
|
71
71
|
extra_rdoc_files: []
|
@@ -81,9 +81,9 @@ files:
|
|
81
81
|
- README.md
|
82
82
|
- Rakefile
|
83
83
|
- lib/nugrant.rb
|
84
|
+
- lib/nugrant/bag.rb
|
84
85
|
- lib/nugrant/config.rb
|
85
86
|
- lib/nugrant/helper/yaml.rb
|
86
|
-
- lib/nugrant/parameter_bag.rb
|
87
87
|
- lib/nugrant/parameters.rb
|
88
88
|
- lib/nugrant/vagrant/command/parameters.rb
|
89
89
|
- lib/nugrant/vagrant/command/root.rb
|
@@ -127,7 +127,7 @@ files:
|
|
127
127
|
- test/resources/yml/params_user_1.yml
|
128
128
|
- test/resources/yml/params_user_2.yml
|
129
129
|
- test/resources/yml/params_windows_eol.yml
|
130
|
-
homepage: https://github.com/
|
130
|
+
homepage: https://github.com/maoueh/nugrant
|
131
131
|
licenses: []
|
132
132
|
post_install_message:
|
133
133
|
rdoc_options: []
|
@@ -141,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
segments:
|
143
143
|
- 0
|
144
|
-
hash:
|
144
|
+
hash: 2259077300766997655
|
145
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
146
|
none: false
|
147
147
|
requirements:
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
segments:
|
152
152
|
- 0
|
153
|
-
hash:
|
153
|
+
hash: 2259077300766997655
|
154
154
|
requirements: []
|
155
155
|
rubyforge_project:
|
156
156
|
rubygems_version: 1.8.24
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module Nugrant
|
2
|
-
class ParameterBag
|
3
|
-
def initialize(parameters)
|
4
|
-
@bag = recompute(parameters)
|
5
|
-
end
|
6
|
-
|
7
|
-
def recompute(parameters)
|
8
|
-
@bag = transform(parameters)
|
9
|
-
return @bag
|
10
|
-
end
|
11
|
-
|
12
|
-
def transform(parameters)
|
13
|
-
bag = {}
|
14
|
-
return bag if parameters == nil
|
15
|
-
|
16
|
-
parameters.each do |key, value|
|
17
|
-
if not value.is_a?(Hash)
|
18
|
-
bag[key] = value
|
19
|
-
next
|
20
|
-
end
|
21
|
-
|
22
|
-
# It is a hash, transform it into a bag
|
23
|
-
bag[key] = Nugrant::ParameterBag.new(value)
|
24
|
-
end
|
25
|
-
|
26
|
-
return bag
|
27
|
-
end
|
28
|
-
|
29
|
-
def [](param_name)
|
30
|
-
return get_param(param_name)
|
31
|
-
end
|
32
|
-
|
33
|
-
def method_missing(method, *args, &block)
|
34
|
-
return get_param(method.to_s)
|
35
|
-
end
|
36
|
-
|
37
|
-
def has_param?(param_name)
|
38
|
-
return @bag.has_key?(param_name)
|
39
|
-
end
|
40
|
-
|
41
|
-
def get_param(param_name)
|
42
|
-
if not has_param?(param_name)
|
43
|
-
raise KeyError, "Undefined parameter '#{param_name}'"
|
44
|
-
end
|
45
|
-
|
46
|
-
return @bag[param_name]
|
47
|
-
end
|
48
|
-
|
49
|
-
def get_params()
|
50
|
-
return @bag
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|