carioca 0.1 → 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +3 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +4 -0
- data/README.md +236 -0
- data/carioca.gemspec +2 -2
- data/doc/manual.rdoc +192 -3
- data/lib/carioca.rb +277 -187
- data/lib/carioca_private.rb +100 -0
- data/lib/services.rb +58 -2
- data/lib/services/configuration.rb +150 -18
- data/lib/services/debug.rb +15 -12
- data/lib/services/logger.rb +18 -12
- data/spec/carioca_spec.rb +157 -19
- data/spec/config/services.registry +14 -14
- data/spec/samples/dummy.rb +1 -1
- data/spec/samples/otherdummy.rb +10 -0
- data/spec/samples/requireddummy.rb +10 -0
- data/ultragreen_roodi_coding_convention.yml +1 -1
- metadata +10 -7
data/spec/carioca_spec.rb
CHANGED
@@ -20,6 +20,14 @@ describe Carioca do
|
|
20
20
|
context "Carioca::Services::Registry" do
|
21
21
|
subject { $carioca }
|
22
22
|
context "#init" do
|
23
|
+
it "should be a Singleton" do
|
24
|
+
carioca1 = Carioca::Services::Registry.init
|
25
|
+
carioca2 = Carioca::Services::Registry.init
|
26
|
+
test = (carioca1.inspect == carioca2.inspect)
|
27
|
+
test.should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
|
23
31
|
it { should be_an_instance_of Carioca::Services::Registry }
|
24
32
|
it { $carioca.list.keys.should include "logger" }
|
25
33
|
it "should log Registry starting and logger init if debug mode", :if => $debug do
|
@@ -71,6 +79,14 @@ describe Carioca do
|
|
71
79
|
it { subject.loaded_services.should be_an_instance_of Hash }
|
72
80
|
it { $carioca.loaded_services.keys.should eq ["logger"] }
|
73
81
|
end
|
82
|
+
|
83
|
+
context "#registry_filename" do
|
84
|
+
it { should respond_to :registry_filename }
|
85
|
+
it { should respond_to :registry_filename= }
|
86
|
+
it { subject.registry_filename.should be_an_instance_of String }
|
87
|
+
it { $carioca.registry_filename.should eq "spec/config/services.registry" }
|
88
|
+
end
|
89
|
+
|
74
90
|
end
|
75
91
|
|
76
92
|
context "#start_service" do
|
@@ -79,7 +95,7 @@ describe Carioca do
|
|
79
95
|
|
80
96
|
context "Builtin services" do
|
81
97
|
context "Logger service" do
|
82
|
-
it "should be possible to get the logger service" do
|
98
|
+
it "should be possible to get the builtin logger service" do
|
83
99
|
$logger = subject.get_service :name => 'logger'
|
84
100
|
end
|
85
101
|
it "should log if debug mode", :if => $debug do
|
@@ -92,20 +108,61 @@ describe Carioca do
|
|
92
108
|
|
93
109
|
|
94
110
|
context "Debug Proxy Service" do
|
95
|
-
it "should start the
|
96
|
-
myservice = subject.start_service :name => 'debug' , :params => {:service => '
|
111
|
+
it "should start the builtin service debug" do
|
112
|
+
myservice = subject.start_service :name => 'debug' , :params => {:service => 'dummy'}
|
97
113
|
myservice.test 'titi'
|
98
114
|
end
|
99
115
|
it { subject.list.keys.should include "debug" }
|
100
116
|
it "should log a proxy service log sequence" do
|
101
|
-
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: BEGIN CALL for mapped service
|
117
|
+
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: BEGIN CALL for mapped service dummy/).size.should eq 1
|
102
118
|
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: called: test/).size.should eq 1
|
103
119
|
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: args : titi/).size.should eq 1
|
104
|
-
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: => returned:
|
120
|
+
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: => returned: OK/).size.should eq 1
|
105
121
|
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: END CALL/).size.should eq 1
|
106
122
|
end
|
107
|
-
|
108
123
|
end
|
124
|
+
|
125
|
+
context "Configuration Service" do
|
126
|
+
it "should start the builtin configuration service" do
|
127
|
+
$conf = subject.start_service :name => 'configuration'
|
128
|
+
end
|
129
|
+
it "should access flat settings" do
|
130
|
+
$conf.settings.context1.key.should eq 'value'
|
131
|
+
$conf.settings.context1.node.key1 eq 'value1'
|
132
|
+
$conf.settings.context1.node.key2 eq 'value2'
|
133
|
+
$conf.settings.context2.key.should eq 'value'
|
134
|
+
$conf.settings.context2.node.key1 eq 'value3'
|
135
|
+
$conf.settings.context2.node.key2 eq 'value4'
|
136
|
+
end
|
137
|
+
it "should access contextualized settings" do
|
138
|
+
$conf = subject.restart_service :name => 'configuration', :params => { :context => 'context2' }
|
139
|
+
$conf.settings.key.should eq 'value'
|
140
|
+
$conf.settings.node.key1 eq 'value3'
|
141
|
+
$conf.settings.node.key2 eq 'value4'
|
142
|
+
end
|
143
|
+
it "should access inherited settings from YAML" do
|
144
|
+
$conf = subject.restart_service :name => 'configuration', :params => { :context => 'context3' }
|
145
|
+
$conf.settings.key.should eq 'value'
|
146
|
+
$conf.settings.node.key1 eq 'value3'
|
147
|
+
$conf.settings.node.key2 eq 'value4'
|
148
|
+
end
|
149
|
+
it "should be possible to override a config value" do
|
150
|
+
$conf.settings.node.key2 = 'value8'
|
151
|
+
$conf.settings.node.key2.should eq 'value8'
|
152
|
+
end
|
153
|
+
it { $conf.should respond_to :config_file }
|
154
|
+
it { $conf.should respond_to :config_file= }
|
155
|
+
it { $conf.should respond_to :save! }
|
156
|
+
|
157
|
+
it "should be saved in other file" do
|
158
|
+
$conf.config_file = '/tmp/.config'
|
159
|
+
$conf.save!.should be_true
|
160
|
+
end
|
161
|
+
it "should stop the configuration service" do
|
162
|
+
subject.stop_service({:name => 'configuration'}).should eq true
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
109
166
|
end
|
110
167
|
context "External services" do
|
111
168
|
|
@@ -154,34 +211,115 @@ describe Carioca do
|
|
154
211
|
it "should not log if debug mode and service not loaded", :unless => $debug do
|
155
212
|
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dum not loaded/).size.should = 0
|
156
213
|
end
|
214
|
+
it "should return false if service :name is logger" do
|
215
|
+
subject.stop_service({:name => 'logger'}).should eq false
|
216
|
+
end
|
217
|
+
it "should log if debug mode and service :name is logger", :if => $debug do
|
218
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service logger can't be unloaded/).size.should >= 1
|
219
|
+
end
|
220
|
+
it "should not log if debug mode and service :name is logger", :unless => $debug do
|
221
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service logger can't be unloaded/).size.should = 0
|
222
|
+
end
|
157
223
|
|
158
224
|
|
159
225
|
end
|
160
226
|
|
161
227
|
context "#restart_service" do
|
162
|
-
|
163
|
-
|
228
|
+
it { should respond_to :start_service }
|
229
|
+
it "should start an instance of a service like dummy_one" do
|
230
|
+
$dummy = subject.restart_service :name => 'dummy_one'
|
231
|
+
$dummy = subject.restart_service :name => 'dummy'
|
232
|
+
$dummy.should be_an_instance_of ExternalServices::Dummy
|
233
|
+
$carioca.loaded_services.keys.should include 'dummy'
|
234
|
+
$carioca.loaded_services.keys.should include 'dummy_one'
|
235
|
+
end
|
236
|
+
it "should restart a service already loaded and log it" do
|
237
|
+
$dummy = subject.restart_service :name => 'dummy'
|
238
|
+
end
|
239
|
+
it "should log it if debug mode", :if => $debug do
|
240
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Restarting service dummy/).size.should eq 1
|
241
|
+
end
|
242
|
+
it "should not log it if not debug mode", :if => $debug do
|
243
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Restarting service dummy/).size.should eq 1
|
244
|
+
end
|
164
245
|
|
246
|
+
end
|
165
247
|
|
166
248
|
|
249
|
+
context "#unregister_service" do
|
250
|
+
it { should respond_to :unregister_service }
|
251
|
+
it "should be possible te unregistered the configuration service" do
|
252
|
+
subject.list.keys.should include "configuration"
|
253
|
+
subject.unregister_service :name => "configuration"
|
254
|
+
subject.list.keys.should_not include "configuration"
|
255
|
+
end
|
256
|
+
it "should raise RegistryError if trying to unregister logger" do
|
257
|
+
lambda { subject.unregister_service :name => "logger"}.should raise_error RegistryError
|
258
|
+
end
|
259
|
+
it "should raise RegistryError if trying to unregister a loaded service" do
|
260
|
+
lambda { subject.unregister_service :name => "dummy"}.should raise_error RegistryError
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
167
264
|
|
168
|
-
context "#
|
169
|
-
|
265
|
+
context "#discover_builtins" do
|
266
|
+
it { should respond_to :discover_builtins }
|
267
|
+
it "should rebuild builtin service in @list" do
|
268
|
+
subject.discover_builtins
|
269
|
+
subject.list.keys.should include "configuration"
|
270
|
+
end
|
170
271
|
end
|
272
|
+
|
171
273
|
context "#register_service" do
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
274
|
+
it { should respond_to :register_service }
|
275
|
+
it "should add a new service" do
|
276
|
+
subject.register_service :name => 'otherdummy',
|
277
|
+
:type => :file,
|
278
|
+
:resource => 'spec/samples/otherdummy.rb',
|
279
|
+
:service =>'ExternalServices::OtherDummy',
|
280
|
+
:description => 'An other Dummy Service',
|
281
|
+
:requires => ['requireddummy']
|
282
|
+
end
|
283
|
+
it "should raised RegistryError if started without a registered required service" do
|
284
|
+
lambda { subject.start_service :name => 'otherdummy' }.should raise_error RegistryError
|
285
|
+
end
|
286
|
+
it "should follow requires when started" do
|
287
|
+
subject.register_service :name => 'requireddummy',
|
288
|
+
:type => :file,
|
289
|
+
:resource => 'spec/samples/requireddummy.rb',
|
290
|
+
:service =>'ExternalServices::RequiredDummy',
|
291
|
+
:description => 'An other Dummy Service'
|
292
|
+
subject.start_service :name => 'otherdummy'
|
293
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Registry dependancy found and not loaded : requireddummy/).size.should eq 1
|
294
|
+
subject.loaded_services.keys.should include 'requireddummy'
|
295
|
+
subject.loaded_services.keys.should include 'otherdummy'
|
296
|
+
end
|
297
|
+
it "should raise Argument error if :type is not :gem, :file or :builtin" do
|
298
|
+
lambda { subject.register_service :name => 'otherdummy',
|
299
|
+
:type => :error,
|
300
|
+
:resource => 'spec/samples/otherdummy.rb',
|
301
|
+
:service =>'ExternalServices::OtherDummy',
|
302
|
+
:description => 'An other Dummy Service'}.should raise_error ArgumentError
|
303
|
+
|
304
|
+
end
|
176
305
|
end
|
177
306
|
|
307
|
+
|
308
|
+
|
178
309
|
|
179
310
|
|
180
311
|
context "#save!" do
|
181
312
|
it { should respond_to :save! }
|
182
|
-
it "should save the config" do
|
183
|
-
|
184
|
-
|
313
|
+
it "should save the config to an other file @registry_filename" do
|
314
|
+
File::unlink('/tmp/test.reg') if File::exist?('/tmp/test.reg')
|
315
|
+
prev = subject.registry_filename
|
316
|
+
subject.registry_filename = '/tmp/test.reg'
|
317
|
+
subject.save!
|
318
|
+
File::exist?('/tmp/test.reg').should be_true
|
319
|
+
subject.registry_filename = prev
|
320
|
+
subject.registry_filename.should eq "spec/config/services.registry"
|
321
|
+
end
|
322
|
+
|
185
323
|
end
|
186
324
|
|
187
325
|
|
@@ -199,12 +337,12 @@ describe Carioca do
|
|
199
337
|
open('/tmp/log.file').grep(/DEBUG -- Carioca: closing Registry .../).size.should eq 0
|
200
338
|
end
|
201
339
|
it "should log a stopping notification for each services if debug mode", :if => $debug do
|
202
|
-
['debug','uuid'
|
340
|
+
['debug','uuid'].each do |service|
|
203
341
|
open('/tmp/log.file').grep(/DEBUG -- Carioca: Stopping service #{service} .../).size.should eq 1
|
204
342
|
end
|
205
343
|
end
|
206
344
|
it "should not log a stopping notification for each services if not debug mode", :unless => $debug do
|
207
|
-
['debug','uuid'
|
345
|
+
['debug','uuid'].each do |service|
|
208
346
|
open('/tmp/log.file').grep(/DEBUG -- Carioca: Stopping service #{service} .../).size.should eq 0
|
209
347
|
end
|
210
348
|
end
|
@@ -1,32 +1,32 @@
|
|
1
1
|
---
|
2
2
|
uuid:
|
3
3
|
:type: :gem
|
4
|
-
:service: UUID
|
5
|
-
:description: a Rubygems called uuid to build UUID ids.
|
6
4
|
:resource: uuid
|
5
|
+
:description: a Rubygems called uuid to build UUID ids.
|
6
|
+
:service: UUID
|
7
7
|
logger:
|
8
8
|
:type: :builtin
|
9
|
-
:service: Carioca::Services::InternalLogger
|
10
|
-
:description: The standard ruby Logger internal wrapper Service
|
11
9
|
:resource: logger
|
12
10
|
:init_options:
|
13
11
|
:target: /tmp/log.file
|
12
|
+
:description: The standard ruby Logger internal wrapper Service
|
13
|
+
:service: Carioca::Services::InternalLogger
|
14
14
|
dummy:
|
15
15
|
:type: :file
|
16
|
-
:service: ExternalServices::Dummy
|
17
|
-
:description: a dummy test service
|
18
16
|
:resource: spec/samples/dummy.rb
|
17
|
+
:description: a dummy test service
|
18
|
+
:service: ExternalServices::Dummy
|
19
19
|
debug:
|
20
20
|
:type: :builtin
|
21
|
-
:service: Carioca::Services::ProxyDebug
|
22
|
-
:description: Class Proxy debug logger Service
|
23
21
|
:resource: debug
|
24
22
|
:init_options:
|
25
|
-
:service:
|
26
|
-
|
23
|
+
:service: dummy
|
24
|
+
:description: Class Proxy debug logger Service
|
25
|
+
:service: Carioca::Services::ProxyDebug
|
26
|
+
configuration:
|
27
27
|
:type: :builtin
|
28
|
-
:service: Carioca::Services::Configuration
|
29
|
-
:description: Configuration Agent Service
|
30
28
|
:resource: configuration
|
31
|
-
:
|
32
|
-
|
29
|
+
:description: The configuration service of Carioca
|
30
|
+
:service: Carioca::Services::Configuration
|
31
|
+
:init_options:
|
32
|
+
:config_file: spec/config/.config
|
data/spec/samples/dummy.rb
CHANGED
metadata
CHANGED
@@ -3,9 +3,9 @@ name: carioca
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
-
- 0
|
7
6
|
- 1
|
8
|
-
|
7
|
+
- 0
|
8
|
+
version: "1.0"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Romain GEORGES
|
@@ -17,18 +17,17 @@ date: 2013-02-18 00:00:00 +01:00
|
|
17
17
|
default_executable:
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
|
-
name:
|
20
|
+
name: methodic
|
21
21
|
prerelease: false
|
22
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
segments:
|
27
|
+
- 1
|
27
28
|
- 2
|
28
|
-
|
29
|
-
|
30
|
-
version: 2.0.0
|
31
|
-
type: :development
|
29
|
+
version: "1.2"
|
30
|
+
type: :runtime
|
32
31
|
version_requirements: *id001
|
33
32
|
description: "Carioca : provide a full IoC light Container for designing your applications"
|
34
33
|
email: romain@ultragreen.net
|
@@ -40,6 +39,8 @@ extra_rdoc_files: []
|
|
40
39
|
|
41
40
|
files:
|
42
41
|
- spec/samples/dummy.rb
|
42
|
+
- spec/samples/requireddummy.rb
|
43
|
+
- spec/samples/otherdummy.rb
|
43
44
|
- spec/config/services.registry
|
44
45
|
- lib/services/configuration.rb
|
45
46
|
- lib/services/debug.rb
|
@@ -49,6 +50,7 @@ files:
|
|
49
50
|
- spec/carioca_spec.rb
|
50
51
|
- lib/carioca.rb
|
51
52
|
- lib/services.rb
|
53
|
+
- lib/carioca_private.rb
|
52
54
|
- doc/manual.rdoc
|
53
55
|
- carioca.gemspec
|
54
56
|
- Rakefile
|
@@ -59,6 +61,7 @@ files:
|
|
59
61
|
- COPYRIGHT
|
60
62
|
- ultragreen_roodi_coding_convention.yml
|
61
63
|
- AUTHORS
|
64
|
+
- README.md
|
62
65
|
has_rdoc: true
|
63
66
|
homepage: http://www.ultragreen.net
|
64
67
|
licenses: []
|