rabbitmq-definition 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +181 -0
- data/README.md +57 -0
- data/lib/rabbitmq-definition.rb +46 -0
- data/lib/rabbitmq_definition/command.rb +28 -0
- data/lib/rabbitmq_definition/create.rb +35 -0
- data/lib/rabbitmq_definition/drop.rb +36 -0
- data/lib/rabbitmq_definition/dump.rb +41 -0
- data/lib/rabbitmq_definition/engine.rb +7 -0
- data/lib/rabbitmq_definition/file_definition.rb +54 -0
- data/lib/rabbitmq_definition/load.rb +14 -0
- data/lib/rabbitmq_definition/logger.rb +19 -0
- data/lib/rabbitmq_definition/rabbitmq-definition.rake +21 -0
- data/lib/rabbitmq_definition/version.rb +5 -0
- data/rabbitmq-definition.gemspec +34 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/activity.rb +2 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +24 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +20 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +56 -0
- data/spec/dummy/db/migrate/20131203172849_create_activities.rb +9 -0
- data/spec/dummy/db/rabbitmq_definition.json +43 -0
- data/spec/dummy/db/schema.rb +26 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/log/development.log +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/fixtures/create.json +18 -0
- data/spec/fixtures/example1.json +41 -0
- data/spec/helpers/listing_helper.rb +23 -0
- data/spec/helpers/matchers.rb +29 -0
- data/spec/integration/rabbitmq_definition_spec.rb +101 -0
- data/spec/rabbitmq_definition/command_spec.rb +23 -0
- data/spec/rabbitmq_definition/create_spec.rb +60 -0
- data/spec/rabbitmq_definition/drop_spec.rb +74 -0
- data/spec/rabbitmq_definition/dump_spec.rb +147 -0
- data/spec/rabbitmq_definition/load_spec.rb +40 -0
- data/spec/rabbitmq_definition_spec.rb +39 -0
- data/spec/spec_helper.rb +25 -0
- metadata +347 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4a5b69f6d3566cbe892e1e312ec964d419dc54f4
|
4
|
+
data.tar.gz: 1ccdad0c6b305f9dcbf568f72309ee7017bf4963
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6d92e50075d452a393ec82ffe38fef987b530406217166c752dece0f8fc49ca25624d7aac83e0cbd4861a41987a49f201d89606ca5a16a7cb33da0c647fc9a9e
|
7
|
+
data.tar.gz: 1bd7fe5b7b6a88f865301c49301c6e792a93bf571ac8938cd1d8945b55e69f888c131c3c523748b420437eb4e1d01220146139f60af412f886e9fc92df3fc7d8
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
coverage/
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rabbitmq-definition (0.1.0)
|
5
|
+
colorize (~> 0.7)
|
6
|
+
highline (~> 1.7)
|
7
|
+
json (~> 1.8)
|
8
|
+
rabbitmq_http_api_client (>= 1.6)
|
9
|
+
rails (~> 4.0)
|
10
|
+
rake (~> 10.4)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: http://rubygems.org/
|
14
|
+
specs:
|
15
|
+
actionmailer (4.1.6)
|
16
|
+
actionpack (= 4.1.6)
|
17
|
+
actionview (= 4.1.6)
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
19
|
+
actionpack (4.1.6)
|
20
|
+
actionview (= 4.1.6)
|
21
|
+
activesupport (= 4.1.6)
|
22
|
+
rack (~> 1.5.2)
|
23
|
+
rack-test (~> 0.6.2)
|
24
|
+
actionview (4.1.6)
|
25
|
+
activesupport (= 4.1.6)
|
26
|
+
builder (~> 3.1)
|
27
|
+
erubis (~> 2.7.0)
|
28
|
+
activemodel (4.1.6)
|
29
|
+
activesupport (= 4.1.6)
|
30
|
+
builder (~> 3.1)
|
31
|
+
activerecord (4.1.6)
|
32
|
+
activemodel (= 4.1.6)
|
33
|
+
activesupport (= 4.1.6)
|
34
|
+
arel (~> 5.0.0)
|
35
|
+
activesupport (4.1.6)
|
36
|
+
i18n (~> 0.6, >= 0.6.9)
|
37
|
+
json (~> 1.7, >= 1.7.7)
|
38
|
+
minitest (~> 5.1)
|
39
|
+
thread_safe (~> 0.1)
|
40
|
+
tzinfo (~> 1.1)
|
41
|
+
addressable (2.3.6)
|
42
|
+
arel (5.0.1.20140414130214)
|
43
|
+
builder (3.2.2)
|
44
|
+
byebug (2.7.0)
|
45
|
+
columnize (~> 0.3)
|
46
|
+
debugger-linecache (~> 1.2)
|
47
|
+
codeclimate-test-reporter (0.3.0)
|
48
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
49
|
+
coderay (1.1.0)
|
50
|
+
colorize (0.7.5)
|
51
|
+
columnize (0.8.9)
|
52
|
+
coveralls (0.8.0)
|
53
|
+
multi_json (~> 1.10)
|
54
|
+
rest-client (>= 1.6.8, < 2)
|
55
|
+
simplecov (~> 0.9.1)
|
56
|
+
term-ansicolor (~> 1.3)
|
57
|
+
thor (~> 0.19.1)
|
58
|
+
crack (0.4.2)
|
59
|
+
safe_yaml (~> 1.0.0)
|
60
|
+
debugger-linecache (1.2.0)
|
61
|
+
diff-lcs (1.2.5)
|
62
|
+
docile (1.1.5)
|
63
|
+
domain_name (0.5.23)
|
64
|
+
unf (>= 0.0.5, < 1.0.0)
|
65
|
+
effin_utf8 (1.0)
|
66
|
+
erubis (2.7.0)
|
67
|
+
faraday (0.9.1)
|
68
|
+
multipart-post (>= 1.2, < 3)
|
69
|
+
faraday_middleware (0.9.1)
|
70
|
+
faraday (>= 0.7.4, < 0.10)
|
71
|
+
hashie (3.4.1)
|
72
|
+
highline (1.7.1)
|
73
|
+
http-cookie (1.0.2)
|
74
|
+
domain_name (~> 0.5)
|
75
|
+
i18n (0.6.11)
|
76
|
+
json (1.8.2)
|
77
|
+
mail (2.6.3)
|
78
|
+
mime-types (>= 1.16, < 3)
|
79
|
+
method_source (0.8.2)
|
80
|
+
mime-types (2.4.3)
|
81
|
+
minitest (5.5.0)
|
82
|
+
multi_json (1.11.0)
|
83
|
+
multipart-post (2.0.0)
|
84
|
+
netrc (0.10.3)
|
85
|
+
pry (0.9.12.6)
|
86
|
+
coderay (~> 1.0)
|
87
|
+
method_source (~> 0.8)
|
88
|
+
slop (~> 3.4)
|
89
|
+
pry-byebug (1.3.2)
|
90
|
+
byebug (~> 2.7)
|
91
|
+
pry (~> 0.9.12)
|
92
|
+
rabbitmq_http_api_client (1.6.0)
|
93
|
+
effin_utf8 (~> 1.0.0)
|
94
|
+
faraday (~> 0.9.0)
|
95
|
+
faraday_middleware (~> 0.9.0)
|
96
|
+
hashie (~> 3.2)
|
97
|
+
multi_json (~> 1.9)
|
98
|
+
rack (1.5.2)
|
99
|
+
rack-test (0.6.2)
|
100
|
+
rack (>= 1.0)
|
101
|
+
rails (4.1.6)
|
102
|
+
actionmailer (= 4.1.6)
|
103
|
+
actionpack (= 4.1.6)
|
104
|
+
actionview (= 4.1.6)
|
105
|
+
activemodel (= 4.1.6)
|
106
|
+
activerecord (= 4.1.6)
|
107
|
+
activesupport (= 4.1.6)
|
108
|
+
bundler (>= 1.3.0, < 2.0)
|
109
|
+
railties (= 4.1.6)
|
110
|
+
sprockets-rails (~> 2.0)
|
111
|
+
railties (4.1.6)
|
112
|
+
actionpack (= 4.1.6)
|
113
|
+
activesupport (= 4.1.6)
|
114
|
+
rake (>= 0.8.7)
|
115
|
+
thor (>= 0.18.1, < 2.0)
|
116
|
+
rake (10.4.2)
|
117
|
+
rest-client (1.8.0)
|
118
|
+
http-cookie (>= 1.0.2, < 2.0)
|
119
|
+
mime-types (>= 1.16, < 3.0)
|
120
|
+
netrc (~> 0.7)
|
121
|
+
rspec (3.2.0)
|
122
|
+
rspec-core (~> 3.2.0)
|
123
|
+
rspec-expectations (~> 3.2.0)
|
124
|
+
rspec-mocks (~> 3.2.0)
|
125
|
+
rspec-core (3.2.2)
|
126
|
+
rspec-support (~> 3.2.0)
|
127
|
+
rspec-expectations (3.2.0)
|
128
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
129
|
+
rspec-support (~> 3.2.0)
|
130
|
+
rspec-mocks (3.2.1)
|
131
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
132
|
+
rspec-support (~> 3.2.0)
|
133
|
+
rspec-rails (3.2.1)
|
134
|
+
actionpack (>= 3.0, < 4.3)
|
135
|
+
activesupport (>= 3.0, < 4.3)
|
136
|
+
railties (>= 3.0, < 4.3)
|
137
|
+
rspec-core (~> 3.2.0)
|
138
|
+
rspec-expectations (~> 3.2.0)
|
139
|
+
rspec-mocks (~> 3.2.0)
|
140
|
+
rspec-support (~> 3.2.0)
|
141
|
+
rspec-support (3.2.2)
|
142
|
+
safe_yaml (1.0.4)
|
143
|
+
simplecov (0.9.2)
|
144
|
+
docile (~> 1.1.0)
|
145
|
+
multi_json (~> 1.0)
|
146
|
+
simplecov-html (~> 0.9.0)
|
147
|
+
simplecov-html (0.9.0)
|
148
|
+
slop (3.6.0)
|
149
|
+
sprockets (3.0.0)
|
150
|
+
rack (~> 1.0)
|
151
|
+
sprockets-rails (2.2.4)
|
152
|
+
actionpack (>= 3.0)
|
153
|
+
activesupport (>= 3.0)
|
154
|
+
sprockets (>= 2.8, < 4.0)
|
155
|
+
term-ansicolor (1.3.0)
|
156
|
+
tins (~> 1.0)
|
157
|
+
thor (0.19.1)
|
158
|
+
thread_safe (0.3.4)
|
159
|
+
timecop (0.5.0)
|
160
|
+
tins (1.3.5)
|
161
|
+
tzinfo (1.2.2)
|
162
|
+
thread_safe (~> 0.1)
|
163
|
+
unf (0.1.4)
|
164
|
+
unf_ext
|
165
|
+
unf_ext (0.0.6)
|
166
|
+
webmock (1.20.4)
|
167
|
+
addressable (>= 2.3.6)
|
168
|
+
crack (>= 0.3.2)
|
169
|
+
|
170
|
+
PLATFORMS
|
171
|
+
ruby
|
172
|
+
|
173
|
+
DEPENDENCIES
|
174
|
+
codeclimate-test-reporter (~> 0.3)
|
175
|
+
coveralls (~> 0.8)
|
176
|
+
pry-byebug (~> 1.3)
|
177
|
+
rabbitmq-definition!
|
178
|
+
rspec (~> 3.2)
|
179
|
+
rspec-rails (~> 3.2)
|
180
|
+
timecop (= 0.5)
|
181
|
+
webmock (~> 1.20)
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Introduction
|
2
|
+
|
3
|
+
Manage RabbitMQ structure of your virtual hosts. Similary to ActiveRecord schema.rb or structure.sql that dumps the current database schema, rabbitmq-schema will dump a ```db/rabbitmq_structure.json``` timestamped file with the representation of the virtual hosts, queues, exchanges, bindings, users and permissions.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Include this to your development/test Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rabbitmq-schema'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Make sure you set an environment variable for the rabbitmq api (you can add the /api path or leave it out):
|
16
|
+
```
|
17
|
+
RABBITMQ_MANAGEMENT_URL=http://guest:guest@localhost:15672
|
18
|
+
```
|
19
|
+
|
20
|
+
### Create definition
|
21
|
+
|
22
|
+
Create a new vhost and definition for your application. It will create the vhosts of your choice and add permissions to the user in the environment variable to those vhosts.
|
23
|
+
```ruby
|
24
|
+
bundle exec rake rabbitmq:create # It will ask you what vhosts to create the definition with
|
25
|
+
# or
|
26
|
+
bundle exec rake rabbitmq:create[/hats] # It will directly create a vhost named '/hats'
|
27
|
+
```
|
28
|
+
|
29
|
+
### Drop definition
|
30
|
+
|
31
|
+
Drop the vhosts in from your RabbitMQ instance and remove the file:
|
32
|
+
```ruby
|
33
|
+
bundle exec rake rabbitmq:drop
|
34
|
+
```
|
35
|
+
|
36
|
+
### Dump definition
|
37
|
+
Dump the definition of the vhosts in your RabbitMQ instance into definition file:
|
38
|
+
```ruby
|
39
|
+
bundle exec rake rabbitmq:dump # To dump the vhosts specificed in the existing definition file
|
40
|
+
# or
|
41
|
+
bundle exec rake rabbitmq:dump[/hats] # To dump the specified vhost in a new definition few
|
42
|
+
```
|
43
|
+
|
44
|
+
### Load definition
|
45
|
+
Load the vhosts definition from your definition file into your RabbitMQ instance:
|
46
|
+
```ruby
|
47
|
+
bundle exec rake rabbitmq:load
|
48
|
+
```
|
49
|
+
|
50
|
+
### TODO
|
51
|
+
|
52
|
+
- [ ] Make it Rails independent
|
53
|
+
- [ ] There's a few uses of Hash#except.
|
54
|
+
- [ ] There's a few uses of Hash#with_indifferent_access.
|
55
|
+
- [ ] The Engine class should only be loaded when Rails is present.
|
56
|
+
- [ ] User should be able to indicate the file path for the structure.
|
57
|
+
- [ ] Rails dependency should be removed from gemspec.
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rake'
|
3
|
+
require 'uri'
|
4
|
+
require 'colorize'
|
5
|
+
require 'highline/import'
|
6
|
+
require 'rabbitmq/http/client'
|
7
|
+
require 'rabbitmq_definition/logger'
|
8
|
+
require 'rabbitmq_definition/file_definition'
|
9
|
+
require 'rabbitmq_definition/command'
|
10
|
+
require 'rabbitmq_definition/create'
|
11
|
+
require 'rabbitmq_definition/drop'
|
12
|
+
require 'rabbitmq_definition/load'
|
13
|
+
require 'rabbitmq_definition/dump'
|
14
|
+
require 'rabbitmq_definition/engine'
|
15
|
+
|
16
|
+
module RabbitMQ::Definition
|
17
|
+
def self.create(vhosts)
|
18
|
+
RabbitMQ::Definition::Create.run(client, verbose, vhosts)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.drop
|
22
|
+
RabbitMQ::Definition::Drop.run(client, verbose)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.dump(vhosts = nil)
|
26
|
+
RabbitMQ::Definition::Dump.run(client, verbose, vhosts)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.load
|
30
|
+
RabbitMQ::Definition::Load.run(client, verbose)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def self.client
|
36
|
+
RabbitMQ::HTTP::Client.new(rabbitmq_management_url)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.rabbitmq_management_url
|
40
|
+
ENV['RABBITMQ_MANAGEMENT_URL']
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.verbose
|
44
|
+
Rake.verbose == true
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RabbitMQ::Definition
|
2
|
+
class Command
|
3
|
+
attr_accessor :client, :verbose
|
4
|
+
|
5
|
+
def self.run(*args)
|
6
|
+
new(*args).execute
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(client, verbose)
|
10
|
+
@client = client
|
11
|
+
@verbose = !!verbose
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
raise NotImplementedError
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def uri_endpoint
|
21
|
+
@uri_endpoint ||= URI.parse(client.endpoint)
|
22
|
+
end
|
23
|
+
|
24
|
+
def user
|
25
|
+
@uri ||= uri_endpoint.user
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module RabbitMQ::Definition
|
2
|
+
class Create < Command
|
3
|
+
def initialize(client, verbose, vhosts)
|
4
|
+
super(client, verbose)
|
5
|
+
@vhosts = (vhosts || []).compact
|
6
|
+
if @vhosts.empty?
|
7
|
+
@vhosts = ask("-> What vhosts do you want to create? (comma separated list)".yellow, lambda { |str| str.split(/,\s*/) })
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute
|
12
|
+
if FileDefinition.exists?
|
13
|
+
Logger.error "Definition file already exists in #{FileDefinition.file_path}"
|
14
|
+
else
|
15
|
+
@vhosts.each do |vhost|
|
16
|
+
Logger.progress "Creating vhost '#{vhost}'" if verbose
|
17
|
+
client.create_vhost(vhost)
|
18
|
+
Logger.progress "Adding permissions for '#{user}' to vhost '#{vhost}'" if verbose
|
19
|
+
client.update_permissions_of(vhost, user, all_permissions)
|
20
|
+
end
|
21
|
+
Dump.run(client, false, @vhosts)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def all_permissions
|
28
|
+
{
|
29
|
+
:configure => ".*",
|
30
|
+
:write => ".*",
|
31
|
+
:read => ".*"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RabbitMQ::Definition
|
2
|
+
class Drop < Command
|
3
|
+
def execute
|
4
|
+
if !FileDefinition.exists?
|
5
|
+
Logger.error "No definition with vhosts exists"
|
6
|
+
else
|
7
|
+
if !agree("This will delete vhosts (#{vhost_names.join(',')}), continue? y/n".yellow)
|
8
|
+
Logger.error "Aborted by user"
|
9
|
+
else
|
10
|
+
delete_vhosts
|
11
|
+
Logger.progress "Removing definition..."
|
12
|
+
definition.destroy
|
13
|
+
Logger.success "Done"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def definition
|
21
|
+
@definition ||= FileDefinition.read
|
22
|
+
end
|
23
|
+
|
24
|
+
def vhost_names
|
25
|
+
@vhost_names ||= definition.vhosts.map { |vhost| vhost['name'] }
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_vhosts
|
29
|
+
vhost_names.each do |vhost|
|
30
|
+
Logger.progress "Deleting vhost '#{vhost}'..." if verbose
|
31
|
+
client.delete_vhost(vhost)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module RabbitMQ::Definition
|
2
|
+
class Dump < Command
|
3
|
+
def initialize(client, verbose, vhosts = nil)
|
4
|
+
super(client, verbose)
|
5
|
+
@vhosts = vhosts || FileDefinition.read.vhosts.map { |vhost| vhost['name'] }
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
FileDefinition.new(filtered_list_definition).tap do |definition|
|
10
|
+
Logger.info definition.to_json if verbose
|
11
|
+
Logger.progress "Saving definition..."
|
12
|
+
definition.save
|
13
|
+
Logger.success "Done"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def filtered_list_definition
|
20
|
+
client.list_definitions.reduce({}) do |result, (key, value)|
|
21
|
+
if key.to_s == "vhosts"
|
22
|
+
value = @vhosts.map {|name| {'name' => name} }
|
23
|
+
elsif value.is_a?(Array)
|
24
|
+
value = filter_vhost_items(value)
|
25
|
+
end
|
26
|
+
result[key] = value
|
27
|
+
result
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def filter_vhost_items(items)
|
32
|
+
items.reduce([]) do |array, item|
|
33
|
+
if !item.has_key?("vhost") || @vhosts.include?(item["vhost"])
|
34
|
+
array.push(item)
|
35
|
+
end
|
36
|
+
array
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|