carioca 0.1 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/ChangeLog
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
code_statistics (0.2.13)
|
4
5
|
diff-lcs (1.1.3)
|
5
6
|
json (1.6.5)
|
6
7
|
macaddr (1.0.0)
|
8
|
+
methodic (0.2)
|
7
9
|
rake (0.9.2.2)
|
8
10
|
rcov (1.0.0)
|
9
11
|
rdoc (3.12)
|
@@ -31,6 +33,8 @@ PLATFORMS
|
|
31
33
|
ruby
|
32
34
|
|
33
35
|
DEPENDENCIES
|
36
|
+
code_statistics
|
37
|
+
methodic
|
34
38
|
rake
|
35
39
|
rcov
|
36
40
|
rdoc
|
data/README.md
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
# Carioca
|
2
|
+
|
3
|
+
## Content
|
4
|
+
|
5
|
+
Author:: Romain GEORGES <romain@ultragreen.net>
|
6
|
+
Version:: 1.0
|
7
|
+
WWW:: http://www.ultragreen.net/projects/carioca
|
8
|
+
|
9
|
+
## Description
|
10
|
+
|
11
|
+
CARIOCA is Configuration Agent and Registry with Inversion Of Control for your Applications
|
12
|
+
Carioca provide a full IoC light Container for designing your applications
|
13
|
+
Carioca provide :
|
14
|
+
- a complete Configuration Agent
|
15
|
+
- A service Registry (base on IOC/DI pattern)
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
In a valid Ruby environment :
|
20
|
+
|
21
|
+
```
|
22
|
+
$ sudo zsh
|
23
|
+
# gem ins carioca
|
24
|
+
```
|
25
|
+
## Implementation
|
26
|
+
|
27
|
+
* [Carioca]
|
28
|
+
* [Carioca::Services]
|
29
|
+
* [Carioca:Services::Registry]
|
30
|
+
|
31
|
+
## Utilisation
|
32
|
+
|
33
|
+
Carioca may be used to create Ruby applications, based on a service registry
|
34
|
+
Carioca come with somes builtin services :
|
35
|
+
* logger : an Internal logger based on the logger gem.
|
36
|
+
* Configuration : a Configuration Service, with Yaml percistance, and pretty accessors.
|
37
|
+
* Debug : a Class Debugger, based on Proxy Design pattern and meta-programation like method_missing
|
38
|
+
|
39
|
+
### Getting start
|
40
|
+
|
41
|
+
#### Preparing Gem
|
42
|
+
|
43
|
+
Just after Installation, Carioca :
|
44
|
+
|
45
|
+
```
|
46
|
+
$ gem ins bundler # if needed
|
47
|
+
$ bunlde gem myapp
|
48
|
+
$ cd myapp
|
49
|
+
```
|
50
|
+
|
51
|
+
Edit your myapp.gemspec, add this line in Gem::Specification bloc :
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
gem.add_dependency 'carioca'
|
55
|
+
gem.add_development_dependency 'rake'
|
56
|
+
gem.add_development_dependency 'carioca'
|
57
|
+
```
|
58
|
+
|
59
|
+
Description and summary need to be changed to be correctly displayed on Rubygems.
|
60
|
+
|
61
|
+
so, execute bundle :
|
62
|
+
|
63
|
+
```
|
64
|
+
$ bundle
|
65
|
+
```
|
66
|
+
|
67
|
+
Your environment, is ready to create your app
|
68
|
+
|
69
|
+
#### Prepare Carioca
|
70
|
+
|
71
|
+
```
|
72
|
+
$ mkdir config
|
73
|
+
$ mkdir bin
|
74
|
+
```
|
75
|
+
|
76
|
+
edit bin/myapp :
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
require 'rubygems'
|
80
|
+
require 'carioca'
|
81
|
+
|
82
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry'
|
83
|
+
```
|
84
|
+
|
85
|
+
|
86
|
+
After, you could Run Carioca and discover Builtins Services, you need the write access to config path
|
87
|
+
|
88
|
+
|
89
|
+
```
|
90
|
+
$ ruby -e 'require "rubygems"; require "carioca"; reg = Carioca::Services::Registry.init :file => "config/myservices.registry"; reg.discover_builtins; reg.save!'
|
91
|
+
```
|
92
|
+
|
93
|
+
|
94
|
+
this create you, a New Registry config, with all builtins registered.
|
95
|
+
Default path :
|
96
|
+
* config file : ./.config
|
97
|
+
* log file : /tmp/log.file
|
98
|
+
Carioca Registry is a Singleton, and services also be unique instance.
|
99
|
+
|
100
|
+
Now you could continue coding your bin/myapp
|
101
|
+
|
102
|
+
#### Using Configuration Service
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
require 'rubygems'
|
106
|
+
require 'carioca'
|
107
|
+
|
108
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry'
|
109
|
+
config = registry.start_service :name => 'configuration'
|
110
|
+
config.setings.db = { :name => 'mydb' }
|
111
|
+
config.settings.db.host = "myhost"
|
112
|
+
config.settings.db.port = "4545"
|
113
|
+
config.settings.email = "my@email.com"
|
114
|
+
config.save!
|
115
|
+
```
|
116
|
+
|
117
|
+
#### Using Logger Service
|
118
|
+
|
119
|
+
logger is automatically loaded with Carioca, loading registry with :debug => true, let you see the Carioca traces.
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
require 'rubygems'
|
123
|
+
require 'carioca'
|
124
|
+
|
125
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry' :debug => true
|
126
|
+
log = registry.get_service :name => 'logger'
|
127
|
+
log.info('myapp') {'my message' }
|
128
|
+
```
|
129
|
+
|
130
|
+
#### Creating and using your own service
|
131
|
+
|
132
|
+
before create your own service :
|
133
|
+
|
134
|
+
```
|
135
|
+
$ mkdir services
|
136
|
+
```
|
137
|
+
|
138
|
+
Services, must be a class, if not do a wrapper
|
139
|
+
edit services/myservice.rb
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
class MyService
|
143
|
+
def initialize
|
144
|
+
end
|
145
|
+
|
146
|
+
def test(arg = nil)
|
147
|
+
return 'OK'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
```
|
152
|
+
|
153
|
+
You could use the #service_register API (See spec for all details)
|
154
|
+
but, you could write it directly in YAML in your config/myservices.registry :
|
155
|
+
add the following lines :
|
156
|
+
|
157
|
+
```yaml
|
158
|
+
...
|
159
|
+
myservice:
|
160
|
+
:type: :file
|
161
|
+
:resource: services/myservice.rb
|
162
|
+
:description: a test service
|
163
|
+
:service: MyServices
|
164
|
+
...
|
165
|
+
|
166
|
+
So in your app :
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
require 'rubygems'
|
170
|
+
require 'carioca'
|
171
|
+
|
172
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry'
|
173
|
+
service = registry.start_service :name => 'myservice'
|
174
|
+
service.test('titi')
|
175
|
+
```
|
176
|
+
|
177
|
+
#### Using Debug in multiple service instance
|
178
|
+
|
179
|
+
|
180
|
+
in your app, for debug you could use the Proxy Debug (you need to run Carioca Registry in debug mode ) :
|
181
|
+
(Using "debug_", you create an instance of service debug, so with this syntaxe you could create multiple services instances, with different parameters calling.)
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
require 'rubygems'
|
185
|
+
require 'carioca'
|
186
|
+
|
187
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry' :debug => true
|
188
|
+
proxy1 = registry.get_service :name => 'debug_myservice', :params => {:service => 'myservice'}
|
189
|
+
proxy1.test('titi')
|
190
|
+
```
|
191
|
+
|
192
|
+
|
193
|
+
see the log /tmp/log.file :
|
194
|
+
|
195
|
+
```
|
196
|
+
D, [2013-03-23T18:20:39.839826 #76641] DEBUG -- ProxyDebug: BEGIN CALL for mapped service myservice
|
197
|
+
D, [2013-03-23T18:20:39.839875 #76641] DEBUG -- ProxyDebug: called: test
|
198
|
+
D, [2013-03-23T18:20:39.839920 #76641] DEBUG -- ProxyDebug: args : titi
|
199
|
+
D, [2013-03-23T18:20:39.839970 #76641] DEBUG -- ProxyDebug: => returned: OK
|
200
|
+
D, [2013-03-23T18:20:39.840014 #76641] DEBUG -- ProxyDebug: END CALL
|
201
|
+
```
|
202
|
+
|
203
|
+
#### Using Gem for a service
|
204
|
+
|
205
|
+
|
206
|
+
For exemple install uuid gem :
|
207
|
+
|
208
|
+
```
|
209
|
+
$ gem ins uuid
|
210
|
+
```
|
211
|
+
|
212
|
+
add to your YAML config config/myservices.registry :
|
213
|
+
|
214
|
+
```yaml
|
215
|
+
uuid:
|
216
|
+
:type: :gem
|
217
|
+
:resource: uuid
|
218
|
+
:description: a Rubygems called uuid to build UUID ids.
|
219
|
+
:service: UUID
|
220
|
+
```
|
221
|
+
|
222
|
+
in your app :
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
require 'rubygems'
|
226
|
+
require 'carioca'
|
227
|
+
|
228
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry' :debug => true
|
229
|
+
uuid = registry.get_service :name => 'uuid'
|
230
|
+
uuid.generate
|
231
|
+
```
|
232
|
+
|
233
|
+
== Copyright
|
234
|
+
|
235
|
+
<pre>carioca (c) 2012-2013 Romain GEORGES <romain@ultragreen.net> for Ultragreen Software </pre>
|
236
|
+
|
data/carioca.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{carioca}
|
3
3
|
s.author = "Romain GEORGES"
|
4
|
-
s.version = "0
|
4
|
+
s.version = "1.0"
|
5
5
|
s.date = %q{2013-02-18}
|
6
6
|
s.summary = %q{Carioca : Configuration Agent and Registry with Inversion Of Control for your Applications}
|
7
7
|
s.email = %q{romain@ultragreen.net}
|
@@ -10,8 +10,8 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.has_rdoc = true
|
11
11
|
s.files = Dir['*/*/*/*'] + Dir['*/*/*'] + Dir['*/*'] + Dir['*']
|
12
12
|
s.bindir = nil
|
13
|
+
s.add_dependency('methodic', '>= 1.2')
|
13
14
|
s.required_ruby_version = '>= 1.8.1'
|
14
|
-
s.add_development_dependency "rspec", ">= 2.0.0"
|
15
15
|
s.rdoc_options << '--title' << 'Carioca : Gem documentation' << '--main' << 'doc/manual.rdoc' << '--line-numbers'
|
16
16
|
# << '--diagram'
|
17
17
|
s.rubyforge_project = "nowarning"
|
data/doc/manual.rdoc
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
== Content
|
4
4
|
|
5
5
|
Author:: Romain GEORGES <romain@ultragreen.net>
|
6
|
-
Version:: 1.
|
7
|
-
WWW:: http://www.ultragreen.net/projects/
|
6
|
+
Version:: 1.0
|
7
|
+
WWW:: http://www.ultragreen.net/projects/carioca
|
8
8
|
|
9
9
|
== Description
|
10
10
|
|
@@ -25,9 +25,198 @@ In a valid Ruby environment :
|
|
25
25
|
== Implementation
|
26
26
|
|
27
27
|
* [Carioca]
|
28
|
+
* [Carioca::Services]
|
29
|
+
* [Carioca:Services::Registry]
|
28
30
|
|
31
|
+
== Utilisation
|
29
32
|
|
30
|
-
|
33
|
+
Carioca may be used to create Ruby applications, based on a service registry
|
34
|
+
Carioca come with somes builtin services :
|
35
|
+
* logger : an Internal logger based on the logger gem.
|
36
|
+
* Configuration : a Configuration Service, with Yaml percistance, and pretty accessors.
|
37
|
+
* Debug : a Class Debugger, based on Proxy Design pattern and meta-programation like method_missing
|
38
|
+
|
39
|
+
|
40
|
+
=== Getting start
|
41
|
+
|
42
|
+
==== Preparing Gem
|
43
|
+
|
44
|
+
Just after Installation, Carioca :
|
45
|
+
|
46
|
+
$ gem ins bundler # if needed
|
47
|
+
$ bunlde gem myapp
|
48
|
+
$ cd myapp
|
49
|
+
|
50
|
+
|
51
|
+
Edit your myapp.gemspec, add this line in Gem::Specification bloc :
|
52
|
+
|
53
|
+
gem.add_dependency 'carioca'
|
54
|
+
gem.add_development_dependency 'rake'
|
55
|
+
gem.add_development_dependency 'carioca'
|
56
|
+
|
57
|
+
Description and summary need to be changed to be correctly displayed on Rubygems.
|
58
|
+
|
59
|
+
so, execute bundle :
|
60
|
+
|
61
|
+
$ bundle
|
62
|
+
|
63
|
+
Your environment, is ready to create your app
|
64
|
+
|
65
|
+
==== Prepare Carioca
|
66
|
+
|
67
|
+
|
68
|
+
$ mkdir config
|
69
|
+
$ mkdir bin
|
70
|
+
|
71
|
+
edit bin/myapp :
|
72
|
+
|
73
|
+
require 'rubygems'
|
74
|
+
require 'carioca'
|
75
|
+
|
76
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry'
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
After, you could Run Carioca and discover Builtins Services, you need the write access to config path
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
$ ruby -e 'require "rubygems"; require "carioca"; reg = Carioca::Services::Registry.init :file => "config/myservices.registry"; reg.discover_builtins; reg.save!'
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
this create you, a New Registry config, with all builtins registered.
|
89
|
+
Default path :
|
90
|
+
* config file : ./.config
|
91
|
+
* log file : /tmp/log.file
|
92
|
+
Carioca Registry is a Singleton, and services also be unique instance.
|
93
|
+
|
94
|
+
Now you could continue coding your bin/myapp
|
95
|
+
|
96
|
+
==== Using Configuration Service
|
97
|
+
|
98
|
+
|
99
|
+
require 'rubygems'
|
100
|
+
require 'carioca'
|
101
|
+
|
102
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry'
|
103
|
+
config = registry.start_service :name => 'configuration'
|
104
|
+
config.setings.db = { :name => 'mydb' }
|
105
|
+
config.settings.db.host = "myhost"
|
106
|
+
config.settings.db.port = "4545"
|
107
|
+
config.settings.email = "my@email.com"
|
108
|
+
config.save!
|
109
|
+
|
110
|
+
|
111
|
+
==== Using Logger Service
|
112
|
+
|
113
|
+
logger is automatically loaded with Carioca, loading registry with :debug => true, let you see the Carioca traces.
|
114
|
+
|
115
|
+
|
116
|
+
require 'rubygems'
|
117
|
+
require 'carioca'
|
118
|
+
|
119
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry' :debug => true
|
120
|
+
log = registry.get_service :name => 'logger'
|
121
|
+
log.info('myapp') {'my message' }
|
122
|
+
|
123
|
+
|
124
|
+
==== Creating and using your own service
|
125
|
+
|
126
|
+
before create your own service :
|
127
|
+
|
128
|
+
|
129
|
+
$ mkdir services
|
130
|
+
|
131
|
+
|
132
|
+
Services, must be a class, if not do a wrapper
|
133
|
+
edit services/myservice.rb
|
134
|
+
|
135
|
+
class MyService
|
136
|
+
def initialize
|
137
|
+
end
|
138
|
+
|
139
|
+
def test(arg = nil)
|
140
|
+
return 'OK'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
|
146
|
+
You could use the #service_register API (See spec for all details)
|
147
|
+
but, you could write it directly in YAML in your config/myservices.registry :
|
148
|
+
add the following lines :
|
149
|
+
|
150
|
+
...
|
151
|
+
myservice:
|
152
|
+
:type: :file
|
153
|
+
:resource: services/myservice.rb
|
154
|
+
:description: a test service
|
155
|
+
:service: MyServices
|
156
|
+
...
|
157
|
+
|
158
|
+
So in your app :
|
159
|
+
|
160
|
+
|
161
|
+
require 'rubygems'
|
162
|
+
require 'carioca'
|
163
|
+
|
164
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry'
|
165
|
+
service = registry.start_service :name => 'myservice'
|
166
|
+
service.test('titi')
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
==== Using Debug in multiple service instance
|
171
|
+
|
172
|
+
|
173
|
+
in your app, for debug you could use the Proxy Debug (you need to run Carioca Registry in debug mode ) :
|
174
|
+
(Using "debug_", you create an instance of service debug, so with this syntaxe you could create multiple services instances, with different parameters calling.)
|
175
|
+
|
176
|
+
|
177
|
+
require 'rubygems'
|
178
|
+
require 'carioca'
|
179
|
+
|
180
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry' :debug => true
|
181
|
+
proxy1 = registry.get_service :name => 'debug_myservice', :params => {:service => 'myservice'}
|
182
|
+
proxy1.test('titi')
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
see the log /tmp/log.file :
|
187
|
+
|
188
|
+
|
189
|
+
D, [2013-03-23T18:20:39.839826 #76641] DEBUG -- ProxyDebug: BEGIN CALL for mapped service myservice
|
190
|
+
D, [2013-03-23T18:20:39.839875 #76641] DEBUG -- ProxyDebug: called: test
|
191
|
+
D, [2013-03-23T18:20:39.839920 #76641] DEBUG -- ProxyDebug: args : titi
|
192
|
+
D, [2013-03-23T18:20:39.839970 #76641] DEBUG -- ProxyDebug: => returned: OK
|
193
|
+
D, [2013-03-23T18:20:39.840014 #76641] DEBUG -- ProxyDebug: END CALL
|
194
|
+
|
195
|
+
==== Using Gem for a service
|
196
|
+
|
197
|
+
|
198
|
+
For exemple install uuid gem :
|
199
|
+
|
200
|
+
$ gem ins uuid
|
201
|
+
|
202
|
+
|
203
|
+
add to your YAML config config/myservices.registry :
|
204
|
+
|
205
|
+
uuid:
|
206
|
+
:type: :gem
|
207
|
+
:resource: uuid
|
208
|
+
:description: a Rubygems called uuid to build UUID ids.
|
209
|
+
:service: UUID
|
210
|
+
|
211
|
+
|
212
|
+
in your app :
|
213
|
+
|
214
|
+
require 'rubygems'
|
215
|
+
require 'carioca'
|
216
|
+
|
217
|
+
registry = Carioca::Services::Registry.init :file => 'config/myservices.registry' :debug => true
|
218
|
+
uuid = registry.get_service :name => 'uuid'
|
219
|
+
uuid.generate
|
31
220
|
|
32
221
|
|
33
222
|
== Copyright
|