nugrant 2.0.0.dev2 → 2.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +6 -14
  2. data/.gitignore +2 -1
  3. data/.travis.yml +2 -2
  4. data/CHANGELOG.md +148 -3
  5. data/Gemfile +8 -20
  6. data/README.md +266 -72
  7. data/Rakefile +1 -0
  8. data/lib/nugrant.rb +14 -6
  9. data/lib/nugrant/bag.rb +116 -62
  10. data/lib/nugrant/helper/bag.rb +19 -19
  11. data/lib/nugrant/helper/env/exporter.rb +208 -0
  12. data/lib/nugrant/helper/env/namer.rb +47 -0
  13. data/lib/nugrant/helper/parameters.rb +12 -0
  14. data/lib/nugrant/helper/stack.rb +86 -0
  15. data/lib/nugrant/mixin/parameters.rb +98 -0
  16. data/lib/nugrant/parameters.rb +14 -68
  17. data/lib/nugrant/vagrant/errors.rb +27 -0
  18. data/lib/nugrant/vagrant/v2/command/env.rb +101 -0
  19. data/lib/nugrant/vagrant/v2/command/helper.rb +30 -0
  20. data/lib/nugrant/vagrant/v2/command/parameters.rb +16 -4
  21. data/lib/nugrant/vagrant/v2/command/restricted_keys.rb +60 -0
  22. data/lib/nugrant/vagrant/v2/command/root.rb +12 -2
  23. data/lib/nugrant/vagrant/v2/config/user.rb +9 -21
  24. data/lib/nugrant/vagrant/v2/plugin.rb +0 -1
  25. data/lib/nugrant/version.rb +1 -1
  26. data/locales/en.yml +13 -0
  27. data/nugrant.gemspec +3 -7
  28. data/test/lib/nugrant/helper/env/test_exporter.rb +238 -0
  29. data/test/lib/nugrant/helper/test_bag.rb +16 -0
  30. data/test/lib/nugrant/helper/test_parameters.rb +17 -0
  31. data/test/lib/nugrant/helper/test_stack.rb +152 -0
  32. data/test/lib/nugrant/test_bag.rb +132 -22
  33. data/test/lib/nugrant/test_config.rb +95 -92
  34. data/test/lib/nugrant/test_parameters.rb +232 -177
  35. data/test/lib/test_helper.rb +3 -0
  36. data/test/resources/json/params_user_nil_values.json +9 -0
  37. data/test/resources/vagrantfiles/v2.defaults_mixed_string_symbols +18 -0
  38. data/test/resources/vagrantfiles/v2.defaults_null_values_in_vagrantuser +23 -0
  39. data/test/resources/vagrantfiles/v2.defaults_using_string +18 -0
  40. data/test/resources/vagrantfiles/v2.defaults_using_symbol +18 -0
  41. data/test/resources/{Vagrantfile.v2.empty → vagrantfiles/v2.empty} +0 -2
  42. data/test/resources/{Vagrantfile.v2.fake → vagrantfiles/v2.fake} +4 -3
  43. data/test/resources/vagrantfiles/v2.missing_parameter +3 -0
  44. data/test/resources/{Vagrantfile.v2.real → vagrantfiles/v2.real} +0 -2
  45. data/test/resources/yaml/params_user_nil_values.yml +5 -0
  46. metadata +55 -88
  47. data/lib/nugrant/vagrant/v1/command/parameters.rb +0 -134
  48. data/lib/nugrant/vagrant/v1/command/root.rb +0 -81
  49. data/lib/nugrant/vagrant/v1/config/user.rb +0 -37
  50. data/lib/nugrant/vagrant/v1/plugin.rb +0 -6
  51. data/lib/vagrant_init.rb +0 -2
  52. data/test/resources/Vagrantfile.v1.empty +0 -2
  53. data/test/resources/Vagrantfile.v1.fake +0 -10
  54. data/test/resources/Vagrantfile.v1.real +0 -19
@@ -0,0 +1,3 @@
1
+ require "minitest/reporters"
2
+
3
+ Minitest::Reporters.use!
@@ -0,0 +1,9 @@
1
+ {
2
+ "nil": null,
3
+ "deep": {
4
+ "nil": null,
5
+ "deeper": {
6
+ "nil": null
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,18 @@
1
+ Vagrant.configure("2") do |config|
2
+ config.user.defaults = {
3
+ 'single' => 1,
4
+ :local => {
5
+ 'first' => "value1",
6
+ :second => "value2"
7
+ }
8
+ }
9
+
10
+ puts config.user.single
11
+ puts config.user[:single]
12
+
13
+ puts config.user.local.first
14
+ puts config.user[:local]["first"]
15
+
16
+ puts config.user.local.second
17
+ puts config.user["local"][:second]
18
+ end
@@ -0,0 +1,23 @@
1
+ # Source from https://github.com/maoueh/nugrant/issues/12#issuecomment-27054150
2
+ # but slightly modified
3
+ Vagrant.configure('2') do |config|
4
+ config.user.defaults = {
5
+ "host" => {
6
+ "rails_server_port" => 3000,
7
+ "apps_folder" => "../../rails-apps/" },
8
+ "plugins" => {
9
+ "vagrant_cachier" => {
10
+ "enabled" => false
11
+ }
12
+ }
13
+ }
14
+
15
+ puts "Host Rails Server Port: #{config.user.host.rails_server_port}"
16
+ puts "Host App Folder: #{config.user.host.apps_folder}"
17
+ puts "Gitconfig Name: #{config.user.gitconfig.name}"
18
+ puts "Gitconfig Email: #{config.user.gitconfig.email}"
19
+
20
+ if config.user.plugins.vagrant_cachier.enabled
21
+ puts "Vagrant Cachier is Enabled!"
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ Vagrant.configure("2") do |config|
2
+ config.user.defaults = {
3
+ 'single' => 1,
4
+ 'local' => {
5
+ 'first' => "value1",
6
+ 'second' => "value2"
7
+ }
8
+ }
9
+
10
+ puts config.user.single
11
+ puts config.user[:single]
12
+
13
+ puts config.user.local.first
14
+ puts config.user[:local]["first"]
15
+
16
+ puts config.user.local.second
17
+ puts config.user["local"][:second]
18
+ end
@@ -0,0 +1,18 @@
1
+ Vagrant.configure("2") do |config|
2
+ config.user.defaults = {
3
+ :single => 1,
4
+ :local => {
5
+ :first => "value1",
6
+ :second => "value2"
7
+ }
8
+ }
9
+
10
+ puts config.user.single
11
+ puts config.user[:single]
12
+
13
+ puts config.user.local.first
14
+ puts config.user[:local]["first"]
15
+
16
+ puts config.user.local.second
17
+ puts config.user["local"][:second]
18
+ end
@@ -1,4 +1,2 @@
1
- Vagrant.require_plugin('nugrant')
2
-
3
1
  Vagrant.configure("2") do |config|
4
2
  end
@@ -1,5 +1,3 @@
1
- Vagrant.require_plugin('nugrant')
2
-
3
1
  Vagrant.configure("2") do |config|
4
2
  config.user.defaults = {
5
3
  'local' => {
@@ -7,8 +5,11 @@ Vagrant.configure("2") do |config|
7
5
  'second' => "value2"
8
6
  }
9
7
  }
10
-
8
+
11
9
  config.user.local.each do |name, value|
12
10
  puts "Parameters #{name}: #{value}"
13
11
  end
12
+
13
+ puts "User has local (symbol)" if config.user.has?(:local)
14
+ puts "User has local (string)" if config.user.has?("local")
14
15
  end
@@ -0,0 +1,3 @@
1
+ Vagrant.configure("2") do |config|
2
+ puts config.user.unkown_for_sure
3
+ end
@@ -1,5 +1,3 @@
1
- Vagrant.require_plugin('nugrant')
2
-
3
1
  Vagrant.configure("2") do |config|
4
2
  config.vm.box = "base"
5
3
  config.vm.box_url = "http://domain.com/path/to/above.box"
@@ -0,0 +1,5 @@
1
+ nil:
2
+ deep:
3
+ nil:
4
+ deeper:
5
+ nil:
metadata CHANGED
@@ -1,64 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nugrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.dev2
4
+ version: 2.0.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthieu Vachon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-06 00:00:00.000000000 Z
11
+ date: 2014-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: multi_json
14
+ name: insensitive_hash
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '0.3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ! '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ! '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
26
+ version: '0.3'
41
27
  - !ruby/object:Gem::Dependency
42
- name: json
28
+ name: multi_json
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - ! '>='
31
+ - - ~>
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
33
+ version: '1.8'
34
+ type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ! '>='
38
+ - - ~>
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
55
- description: ! " Nugrant is a library to easily handle parameters that need to
56
- be\n injected into an application via different sources (system, user,\n project,
57
- defaults).\n\n Nugrant can also be directly used as a Vagrant plugin. By activating\n
58
- \ this gem with Vagrant, it will be possible to define user specific\n parameters
59
- that will be injected directly into the Vagrantfile. This\n is useful if you
60
- need to share a Vagrantfile to multiple developers\n but would like to customize
61
- some parameters for each user differently.\n"
40
+ version: '1.8'
41
+ description: |2
42
+ Nugrant is a library to easily handle parameters that need to be
43
+ injected into an application via different sources (system, user,
44
+ project, defaults).
45
+
46
+ Nugrant can also be directly used as a Vagrant plugin. By activating
47
+ this gem with Vagrant, it will be possible to define user specific
48
+ parameters that will be injected directly into the Vagrantfile. This
49
+ is useful if you need to share a Vagrantfile to multiple developers
50
+ but would like to customize some parameters for each user differently.
62
51
  email:
63
52
  - matthieu.o.vachon@gmail.com
64
53
  executables: []
@@ -80,30 +69,34 @@ files:
80
69
  - lib/nugrant/bag.rb
81
70
  - lib/nugrant/config.rb
82
71
  - lib/nugrant/helper/bag.rb
72
+ - lib/nugrant/helper/env/exporter.rb
73
+ - lib/nugrant/helper/env/namer.rb
74
+ - lib/nugrant/helper/parameters.rb
75
+ - lib/nugrant/helper/stack.rb
83
76
  - lib/nugrant/helper/yaml.rb
77
+ - lib/nugrant/mixin/parameters.rb
84
78
  - lib/nugrant/parameters.rb
85
- - lib/nugrant/vagrant/v1/command/parameters.rb
86
- - lib/nugrant/vagrant/v1/command/root.rb
87
- - lib/nugrant/vagrant/v1/config/user.rb
88
- - lib/nugrant/vagrant/v1/plugin.rb
79
+ - lib/nugrant/vagrant/errors.rb
80
+ - lib/nugrant/vagrant/v2/command/env.rb
81
+ - lib/nugrant/vagrant/v2/command/helper.rb
89
82
  - lib/nugrant/vagrant/v2/command/parameters.rb
83
+ - lib/nugrant/vagrant/v2/command/restricted_keys.rb
90
84
  - lib/nugrant/vagrant/v2/command/root.rb
91
85
  - lib/nugrant/vagrant/v2/config/user.rb
92
86
  - lib/nugrant/vagrant/v2/plugin.rb
93
87
  - lib/nugrant/version.rb
94
- - lib/vagrant_init.rb
88
+ - locales/en.yml
95
89
  - nugrant.gemspec
90
+ - test/lib/nugrant/helper/env/test_exporter.rb
91
+ - test/lib/nugrant/helper/test_bag.rb
92
+ - test/lib/nugrant/helper/test_parameters.rb
93
+ - test/lib/nugrant/helper/test_stack.rb
96
94
  - test/lib/nugrant/test_bag.rb
97
95
  - test/lib/nugrant/test_config.rb
98
96
  - test/lib/nugrant/test_parameters.rb
97
+ - test/lib/test_helper.rb
99
98
  - test/resources/.vagrantuser
100
99
  - test/resources/README.md
101
- - test/resources/Vagrantfile.v1.empty
102
- - test/resources/Vagrantfile.v1.fake
103
- - test/resources/Vagrantfile.v1.real
104
- - test/resources/Vagrantfile.v2.empty
105
- - test/resources/Vagrantfile.v2.fake
106
- - test/resources/Vagrantfile.v2.real
107
100
  - test/resources/json/params_array.json
108
101
  - test/resources/json/params_boolean.json
109
102
  - test/resources/json/params_combinations.json
@@ -119,7 +112,16 @@ files:
119
112
  - test/resources/json/params_unix_eol.json
120
113
  - test/resources/json/params_user_1.json
121
114
  - test/resources/json/params_user_2.json
115
+ - test/resources/json/params_user_nil_values.json
122
116
  - test/resources/json/params_windows_eol.json
117
+ - test/resources/vagrantfiles/v2.defaults_mixed_string_symbols
118
+ - test/resources/vagrantfiles/v2.defaults_null_values_in_vagrantuser
119
+ - test/resources/vagrantfiles/v2.defaults_using_string
120
+ - test/resources/vagrantfiles/v2.defaults_using_symbol
121
+ - test/resources/vagrantfiles/v2.empty
122
+ - test/resources/vagrantfiles/v2.fake
123
+ - test/resources/vagrantfiles/v2.missing_parameter
124
+ - test/resources/vagrantfiles/v2.real
123
125
  - test/resources/yaml/params_array.yml
124
126
  - test/resources/yaml/params_boolean.yml
125
127
  - test/resources/yaml/params_combinations.yml
@@ -135,6 +137,7 @@ files:
135
137
  - test/resources/yaml/params_unix_eol.yml
136
138
  - test/resources/yaml/params_user_1.yml
137
139
  - test/resources/yaml/params_user_2.yml
140
+ - test/resources/yaml/params_user_nil_values.yml
138
141
  - test/resources/yaml/params_windows_eol.yml
139
142
  homepage: https://github.com/maoueh/nugrant
140
143
  licenses: []
@@ -145,62 +148,26 @@ require_paths:
145
148
  - lib
146
149
  required_ruby_version: !ruby/object:Gem::Requirement
147
150
  requirements:
148
- - - ! '>='
151
+ - - '>='
149
152
  - !ruby/object:Gem::Version
150
153
  version: '0'
151
154
  required_rubygems_version: !ruby/object:Gem::Requirement
152
155
  requirements:
153
- - - ! '>'
156
+ - - '>'
154
157
  - !ruby/object:Gem::Version
155
158
  version: 1.3.1
156
- requirements:
157
- - json if you plan to use json parameters format
159
+ requirements: []
158
160
  rubyforge_project:
159
- rubygems_version: 2.0.3
161
+ rubygems_version: 2.2.1
160
162
  signing_key:
161
163
  specification_version: 4
162
164
  summary: Library to handle user specific parameters from various location.
163
165
  test_files:
166
+ - test/lib/nugrant/helper/env/test_exporter.rb
167
+ - test/lib/nugrant/helper/test_bag.rb
168
+ - test/lib/nugrant/helper/test_parameters.rb
169
+ - test/lib/nugrant/helper/test_stack.rb
164
170
  - test/lib/nugrant/test_bag.rb
165
171
  - test/lib/nugrant/test_config.rb
166
172
  - test/lib/nugrant/test_parameters.rb
167
- - test/resources/.vagrantuser
168
- - test/resources/README.md
169
- - test/resources/Vagrantfile.v1.empty
170
- - test/resources/Vagrantfile.v1.fake
171
- - test/resources/Vagrantfile.v1.real
172
- - test/resources/Vagrantfile.v2.empty
173
- - test/resources/Vagrantfile.v2.fake
174
- - test/resources/Vagrantfile.v2.real
175
- - test/resources/json/params_array.json
176
- - test/resources/json/params_boolean.json
177
- - test/resources/json/params_combinations.json
178
- - test/resources/json/params_current_1.json
179
- - test/resources/json/params_current_2.json
180
- - test/resources/json/params_defaults_at_root.json
181
- - test/resources/json/params_defaults_not_at_root.json
182
- - test/resources/json/params_empty.json
183
- - test/resources/json/params_list.json
184
- - test/resources/json/params_simple.json
185
- - test/resources/json/params_system_1.json
186
- - test/resources/json/params_system_2.json
187
- - test/resources/json/params_unix_eol.json
188
- - test/resources/json/params_user_1.json
189
- - test/resources/json/params_user_2.json
190
- - test/resources/json/params_windows_eol.json
191
- - test/resources/yaml/params_array.yml
192
- - test/resources/yaml/params_boolean.yml
193
- - test/resources/yaml/params_combinations.yml
194
- - test/resources/yaml/params_current_1.yml
195
- - test/resources/yaml/params_current_2.yml
196
- - test/resources/yaml/params_defaults_at_root.yml
197
- - test/resources/yaml/params_defaults_not_at_root.yml
198
- - test/resources/yaml/params_empty.yml
199
- - test/resources/yaml/params_list.yml
200
- - test/resources/yaml/params_simple.yml
201
- - test/resources/yaml/params_system_1.yml
202
- - test/resources/yaml/params_system_2.yml
203
- - test/resources/yaml/params_unix_eol.yml
204
- - test/resources/yaml/params_user_1.yml
205
- - test/resources/yaml/params_user_2.yml
206
- - test/resources/yaml/params_windows_eol.yml
173
+ - test/lib/test_helper.rb
@@ -1,134 +0,0 @@
1
- require 'nugrant'
2
- require 'nugrant/helper/yaml'
3
-
4
- module Nugrant
5
- module Vagrant
6
- module V1
7
- module Command
8
- class Parameters < ::Vagrant::Command::Base
9
- def initialize(arguments, environment)
10
- super(arguments, environment)
11
-
12
- @show_help = false
13
- @show_defaults = false
14
- @show_system = false
15
- @show_user = false
16
- @show_project = false
17
- end
18
-
19
- def create_parser()
20
- return OptionParser.new do |parser|
21
- parser.banner = "Usage: vagrant user parameters [<options>]"
22
- parser.separator ""
23
-
24
- parser.separator "Available options:"
25
- parser.separator ""
26
-
27
- parser.on("-h", "--help", "Print this help") do
28
- @show_help = true
29
- end
30
-
31
- parser.on("-d", "--defaults", "Show only defaults parameters") do
32
- @show_defaults = true
33
- end
34
-
35
- parser.on("-s", "--system", "Show only system parameters") do
36
- @show_system = true
37
- end
38
-
39
- parser.on("-u", "--user", "Show only user parameters") do
40
- @show_user = true
41
- end
42
-
43
- parser.on("-p", "--project", "Show only project parameters") do
44
- @show_project = true
45
- end
46
-
47
- parser.separator ""
48
- parser.separator "When no options is provided, the command prints the names and values \n" +
49
- "of all parameters that would be available for usage in the Vagrantfile.\n" +
50
- "The hierarchy of the parameters is respected, so the final values are\n" +
51
- "displayed."
52
- end
53
- end
54
-
55
- def execute
56
- parser = create_parser()
57
- arguments = parse_options(parser)
58
-
59
- return help(parser) if @show_help
60
-
61
- @logger.debug("'Parameters' each target VM...")
62
- with_target_vms(arguments) do |vm|
63
- config = vm.config.keys[:user]
64
- parameters = config ? config.parameters : Nugrant::Parameters.new()
65
-
66
- @env.ui.info("# Vm '#{vm.name}'", :prefix => false)
67
-
68
- defaults(parameters) if @show_defaults
69
- system(parameters) if @show_system
70
- user(parameters) if @show_user
71
- project(parameters) if @show_project
72
-
73
- all(parameters) if !@show_defaults && !@show_system && !@show_user && !@show_project
74
- end
75
-
76
- return 0
77
- end
78
-
79
- def help(parser)
80
- @env.ui.info(parser.help, :prefix => false)
81
- end
82
-
83
- def defaults(parameters)
84
- print_bag("Defaults", parameters.__defaults)
85
- end
86
-
87
- def system(parameters)
88
- print_bag("System", parameters.__system)
89
- end
90
-
91
- def user(parameters)
92
- print_bag("User", parameters.__user)
93
- end
94
-
95
- def project(parameters)
96
- print_bag("Project", parameters.__project)
97
- end
98
-
99
- def all(parameters)
100
- print_bag("All", parameters.__all)
101
- end
102
-
103
- def print_bag(kind, bag)
104
- if !bag || bag.empty?()
105
- print_header(kind)
106
- @env.ui.info(" Empty", :prefix => false)
107
- @env.ui.info("", :prefix => false)
108
- return
109
- end
110
-
111
- print_parameters(kind, {
112
- 'config' => {
113
- 'user' => bag.__to_hash()
114
- }
115
- })
116
- end
117
-
118
- def print_parameters(kind, data)
119
- string = Nugrant::Helper::Yaml.format(data.to_yaml, :indent => 1)
120
-
121
- print_header(kind)
122
- @env.ui.info(string, :prefix => false)
123
- @env.ui.info("", :prefix => false)
124
- end
125
-
126
- def print_header(kind, length = 50)
127
- @env.ui.info(" #{kind.capitalize} Parameters", :prefix => false)
128
- @env.ui.info(" " + "-" * length, :prefix => false)
129
- end
130
- end
131
- end
132
- end
133
- end
134
- end