carioca 1.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -10
- data/Gemfile.lock +17 -21
- data/README.md +3 -0
- data/Rakefile +0 -1
- data/carioca.gemspec +10 -3
- data/lib/carioca.rb +43 -37
- data/lib/carioca/exceptions.rb +9 -0
- data/lib/carioca/helpers.rb +35 -0
- data/lib/carioca/private.rb +170 -0
- data/lib/carioca/services.rb +143 -0
- data/lib/{services → carioca/services}/configuration.rb +9 -6
- data/lib/{services → carioca/services}/debug.rb +1 -1
- data/lib/{services → carioca/services}/logger.rb +0 -0
- data/lib/carioca/tasks/rake.rb +23 -0
- data/lib/carioca/tasks/registry_init.rake +11 -0
- data/spec/carioca_spec.rb +108 -17
- data/spec/config/services.registry +31 -8
- data/test.rb +12 -0
- metadata +164 -63
- data/lib/carioca_private.rb +0 -100
- data/lib/services.rb +0 -82
@@ -5,17 +5,47 @@ uuid:
|
|
5
5
|
:description: a Rubygems called uuid to build UUID ids.
|
6
6
|
:service: UUID
|
7
7
|
logger:
|
8
|
+
# :distributed: true
|
8
9
|
:type: :builtin
|
9
10
|
:resource: logger
|
10
11
|
:init_options:
|
11
12
|
:target: /tmp/log.file
|
12
13
|
:description: The standard ruby Logger internal wrapper Service
|
13
14
|
:service: Carioca::Services::InternalLogger
|
15
|
+
configuration:
|
16
|
+
# :distributed: true
|
17
|
+
:type: :builtin
|
18
|
+
:resource: configuration
|
19
|
+
:description: The configuration service of Carioca
|
20
|
+
:service: Carioca::Services::Configuration
|
21
|
+
:init_options:
|
22
|
+
:config_file: ./spec/config/.config
|
23
|
+
dorsal:
|
24
|
+
:type: :gem
|
25
|
+
:resource: dorsal
|
26
|
+
:description: The Dorsal Distributed Services architecture
|
27
|
+
:service: Dorsal::Controller
|
28
|
+
:init_options:
|
29
|
+
:host: localhost
|
30
|
+
:port: 8686
|
31
|
+
:dir: /tmp/dorsal
|
32
|
+
:description: Ultragreen Ring Server
|
14
33
|
dummy:
|
15
34
|
:type: :file
|
16
|
-
:resource: spec/samples/dummy.rb
|
35
|
+
:resource: ./spec/samples/dummy.rb
|
36
|
+
:description: a dummy test service
|
37
|
+
:service: ExternalServices::Dummy
|
38
|
+
distdummy:
|
39
|
+
:type: :file
|
40
|
+
:resource: ./spec/samples/dummy.rb
|
17
41
|
:description: a dummy test service
|
18
42
|
:service: ExternalServices::Dummy
|
43
|
+
:distributed: true
|
44
|
+
uuidbygemfile:
|
45
|
+
:type: :gem_file
|
46
|
+
:resource: uuid:lib/uuid.rb
|
47
|
+
:description: uuid file in gem
|
48
|
+
:service: UUID
|
19
49
|
debug:
|
20
50
|
:type: :builtin
|
21
51
|
:resource: debug
|
@@ -23,10 +53,3 @@ debug:
|
|
23
53
|
:service: dummy
|
24
54
|
:description: Class Proxy debug logger Service
|
25
55
|
:service: Carioca::Services::ProxyDebug
|
26
|
-
configuration:
|
27
|
-
:type: :builtin
|
28
|
-
:resource: configuration
|
29
|
-
:description: The configuration service of Carioca
|
30
|
-
:service: Carioca::Services::Configuration
|
31
|
-
:init_options:
|
32
|
-
:config_file: spec/config/.config
|
data/test.rb
ADDED
metadata
CHANGED
@@ -1,60 +1,165 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: carioca
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
version: "1.0"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.1'
|
9
5
|
platform: ruby
|
10
|
-
authors:
|
6
|
+
authors:
|
11
7
|
- Romain GEORGES
|
12
8
|
autorequire:
|
13
|
-
bindir:
|
9
|
+
bindir: bin
|
14
10
|
cert_chain: []
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
date: 2013-02-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yard
|
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'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: roodi
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: uuid
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: code_statistics
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: dorsal
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
21
119
|
prerelease: false
|
22
|
-
|
23
|
-
requirements:
|
24
|
-
- -
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: methodic
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
30
132
|
type: :runtime
|
31
|
-
|
32
|
-
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: 'Carioca : provide a full IoC light Container for designing your applications'
|
33
140
|
email: romain@ultragreen.net
|
34
141
|
executables: []
|
35
|
-
|
36
142
|
extensions: []
|
37
|
-
|
38
143
|
extra_rdoc_files: []
|
39
|
-
|
40
|
-
|
144
|
+
files:
|
145
|
+
- lib/carioca/tasks/rake.rb
|
146
|
+
- lib/carioca/tasks/registry_init.rake
|
147
|
+
- lib/carioca/services/configuration.rb
|
148
|
+
- lib/carioca/services/debug.rb
|
149
|
+
- lib/carioca/services/logger.rb
|
41
150
|
- spec/samples/dummy.rb
|
42
151
|
- spec/samples/requireddummy.rb
|
43
152
|
- spec/samples/otherdummy.rb
|
44
153
|
- spec/config/services.registry
|
45
|
-
- lib/services
|
46
|
-
- lib/
|
47
|
-
- lib/
|
154
|
+
- lib/carioca/services.rb
|
155
|
+
- lib/carioca/private.rb
|
156
|
+
- lib/carioca/exceptions.rb
|
157
|
+
- lib/carioca/helpers.rb
|
158
|
+
- doc/manual.rdoc
|
48
159
|
- spec/init_spec.rb
|
49
160
|
- spec/spec_helper.rb
|
50
161
|
- spec/carioca_spec.rb
|
51
162
|
- lib/carioca.rb
|
52
|
-
- lib/services.rb
|
53
|
-
- lib/carioca_private.rb
|
54
|
-
- doc/manual.rdoc
|
55
|
-
- carioca.gemspec
|
56
|
-
- Rakefile
|
57
|
-
- INSTALL
|
58
163
|
- Gemfile.lock
|
59
164
|
- Gemfile
|
60
165
|
- ChangeLog
|
@@ -62,41 +167,37 @@ files:
|
|
62
167
|
- ultragreen_roodi_coding_convention.yml
|
63
168
|
- AUTHORS
|
64
169
|
- README.md
|
65
|
-
|
170
|
+
- test.rb
|
171
|
+
- carioca.gemspec
|
172
|
+
- Rakefile
|
173
|
+
- INSTALL
|
66
174
|
homepage: http://www.ultragreen.net
|
67
175
|
licenses: []
|
68
|
-
|
176
|
+
metadata: {}
|
69
177
|
post_install_message:
|
70
|
-
rdoc_options:
|
178
|
+
rdoc_options:
|
71
179
|
- --title
|
72
|
-
-
|
180
|
+
- 'Carioca : Gem documentation'
|
73
181
|
- --main
|
74
182
|
- doc/manual.rdoc
|
75
183
|
- --line-numbers
|
76
|
-
require_paths:
|
184
|
+
require_paths:
|
77
185
|
- lib
|
78
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
segments:
|
83
|
-
- 1
|
84
|
-
- 8
|
85
|
-
- 1
|
186
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - '>='
|
189
|
+
- !ruby/object:Gem::Version
|
86
190
|
version: 1.8.1
|
87
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
-
requirements:
|
89
|
-
- -
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
|
92
|
-
- 0
|
93
|
-
version: "0"
|
191
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - '>='
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
94
196
|
requirements: []
|
95
|
-
|
96
197
|
rubyforge_project: nowarning
|
97
|
-
rubygems_version:
|
198
|
+
rubygems_version: 2.0.7
|
98
199
|
signing_key:
|
99
|
-
specification_version:
|
100
|
-
summary:
|
200
|
+
specification_version: 4
|
201
|
+
summary: 'Carioca : Configuration Agent and Registry with Inversion Of Control for
|
202
|
+
your Applications'
|
101
203
|
test_files: []
|
102
|
-
|
data/lib/carioca_private.rb
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#---
|
3
|
-
# Author : Romain GEORGES
|
4
|
-
# type : gem component library
|
5
|
-
# obj : Carioca Private Module (mixin for Carioca::Services::Registry)
|
6
|
-
#---
|
7
|
-
|
8
|
-
# private methods to mixin Carioca::Services::Registry
|
9
|
-
# @private
|
10
|
-
module PrivateMethodsCariocaServicesRegistry
|
11
|
-
|
12
|
-
|
13
|
-
# private initializer
|
14
|
-
def initialize(_options)
|
15
|
-
@logger_not_in_reg = false
|
16
|
-
@debug = _options[:debug]
|
17
|
-
@registry_filename = _options[:file]
|
18
|
-
@list = Hash::new
|
19
|
-
load if File::exist?(@registry_filename)
|
20
|
-
unless @list.include?('logger') then
|
21
|
-
self.register_service({:name => 'logger',
|
22
|
-
:service => 'Carioca::Services::InternalLogger',
|
23
|
-
:resource => 'logger',
|
24
|
-
:description => "The standard ruby Logger internal wrapper Service",
|
25
|
-
:type => :builtin,
|
26
|
-
:init_options => { :target => "/tmp/log.file"}})
|
27
|
-
@logger_not_in_reg = true
|
28
|
-
end
|
29
|
-
@loaded_services = Hash::new
|
30
|
-
# preload logger service
|
31
|
-
@log = self.start_service :name => 'logger'
|
32
|
-
@log.level =(@debug)? Logger::DEBUG : Logger::INFO
|
33
|
-
@log.debug('Carioca') { "Registry started, service logger preloaded" }
|
34
|
-
@log.debug('Carioca') { "Logger registered, not in configured registry" } if @logger_not_in_reg
|
35
|
-
end
|
36
|
-
|
37
|
-
# verify dependancies in services structure
|
38
|
-
# in @list from a service defition
|
39
|
-
# in _options and start it if needed
|
40
|
-
def verify_requires_dependancies(_options)
|
41
|
-
_name = _options[:shortname]
|
42
|
-
if @list[_name].include?(:requires) then
|
43
|
-
@list[_name][:requires].each do |service|
|
44
|
-
raise RegistryError::new 'Missing Required depedancy #{service}' unless @list.keys.include? service
|
45
|
-
unless @loaded_services.include?(service) then
|
46
|
-
@log.debug('Carioca') { "Registry dependancy found and not loaded : #{service}" }
|
47
|
-
restart_service :name => service
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# require file for a service
|
54
|
-
# from a service definition in _options
|
55
|
-
def require_service(_options)
|
56
|
-
_name = _options[:shortname]
|
57
|
-
sym = ":#{@list[_name][:service].split('::').last}"
|
58
|
-
case @list[_name][:type]
|
59
|
-
when :file then
|
60
|
-
require @list[_name][:resource]
|
61
|
-
when :builtin then
|
62
|
-
_file = Carioca::Services::search_builtins _name
|
63
|
-
if _file then
|
64
|
-
require _file
|
65
|
-
else
|
66
|
-
raise RegistryError::new("Config failed")
|
67
|
-
end
|
68
|
-
when :gem then
|
69
|
-
eval("require '#{@list[_name][:resource]}'")
|
70
|
-
else
|
71
|
-
raise RegistryError::new("Config failed")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
# instanciate Object from class defintion of a service defined in
|
76
|
-
# the service definition in _options
|
77
|
-
def instanciate_service(_options)
|
78
|
-
|
79
|
-
_name = _options[:shortname]
|
80
|
-
@list[_name][:init_options].merge! _options[:params] unless _options[:params].nil?
|
81
|
-
if @list[_name][:init_options].nil? then
|
82
|
-
eval("@loaded_services[_options[:name]] = #{@list[_name][:service]}::new")
|
83
|
-
else
|
84
|
-
eval("@loaded_services[_options[:name]] = #{@list[_name][:service]}::new(@list[_name][:init_options])")
|
85
|
-
end
|
86
|
-
@log.debug('Carioca') { "Service #{_options[:name]} started" } if @log
|
87
|
-
return @loaded_services[_options[:name]]
|
88
|
-
end
|
89
|
-
|
90
|
-
# call the garbage method of a service if exist and
|
91
|
-
# Delete from the loaded services list
|
92
|
-
def kill_service(_name)
|
93
|
-
@loaded_services[_name].garbage if @loaded_services[_name].respond_to? :garbage
|
94
|
-
@loaded_services.delete(_name)
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
end # end of PrivateMethodsCariocaServicesRegistry
|
99
|
-
|
100
|
-
|
data/lib/services.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#---
|
3
|
-
# Author : Romain GEORGES
|
4
|
-
# type : gem component library
|
5
|
-
# obj : Carioca::Services Module
|
6
|
-
#---
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
module Carioca
|
11
|
-
|
12
|
-
# namespace Services for Registry AND buitlins
|
13
|
-
module Services
|
14
|
-
# class method returning full path in Carioca gem for builtin services files according to installed gem path.
|
15
|
-
# @note do not use directly for generale purpose (expert/hacks only)
|
16
|
-
# @param [String] _name the name of a service
|
17
|
-
# @return [String,false] the full path filename orfalse if not found
|
18
|
-
def Services::search_builtins(_name)
|
19
|
-
asearch = Gem.searcher
|
20
|
-
spec = asearch.find('carioca')
|
21
|
-
if spec then
|
22
|
-
res = asearch.lib_dirs_for(spec).split('/')
|
23
|
-
res.pop
|
24
|
-
services_path = res.join('/').concat('/lib/services')
|
25
|
-
else
|
26
|
-
services_path = "lib/services"
|
27
|
-
end
|
28
|
-
_file ="#{services_path}/#{_name}.rb"
|
29
|
-
if File::exist? _file then
|
30
|
-
return _file
|
31
|
-
else
|
32
|
-
return false
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
# class method returning the [Carioca::Services::Registry]@list complement for builtins service found for a carioca gem version
|
37
|
-
# @note do not use directly for generale purpose (expert/hacks only)
|
38
|
-
# @return [Hash] the [Carioca::Services::Registry]@list complement
|
39
|
-
def Services::discover_builtins
|
40
|
-
|
41
|
-
asearch = Gem.searcher
|
42
|
-
spec = asearch.find('carioca')
|
43
|
-
if spec then
|
44
|
-
res = asearch.lib_dirs_for(spec).split('/')
|
45
|
-
res.pop
|
46
|
-
services_path = res.join('/').concat('/lib/services')
|
47
|
-
else
|
48
|
-
services_path = "lib/services"
|
49
|
-
end
|
50
|
-
|
51
|
-
map = Dir["#{services_path}/*"]
|
52
|
-
map.delete_if { |item| not File::file?(item) }
|
53
|
-
map.delete_if { |item| File::basename(item) == 'logger.rb' }
|
54
|
-
|
55
|
-
res = {}
|
56
|
-
map.each do |file|
|
57
|
-
Services::validate_service(file,res)
|
58
|
-
end
|
59
|
-
return res
|
60
|
-
end
|
61
|
-
|
62
|
-
def Services::validate_service(file,res)
|
63
|
-
init_options = {}
|
64
|
-
if open(file).grep(/^# \$BUILTIN/).size > 0 then
|
65
|
-
service = open(file).grep(/# \$SERVICE/).first.split[2]
|
66
|
-
resource = open(file).grep(/# \$RESOURCE/).first.split[2]
|
67
|
-
desc = open(file).grep(/# \$DESCRIPTION/).first
|
68
|
-
desc = desc.split(' ')
|
69
|
-
desc.shift(2)
|
70
|
-
description= desc.join(' ')
|
71
|
-
open(file).grep(/# \$INIT_OPTIONS/).each do |opt|
|
72
|
-
prev = opt.split
|
73
|
-
init_options[prev[2].to_sym] = prev[4]
|
74
|
-
end
|
75
|
-
end
|
76
|
-
unless service.nil? or resource.nil? or description.nil? then
|
77
|
-
res[resource] = { :service => service, :type => :builtin, :description => description, :resource => resource}
|
78
|
-
res[resource][:init_options] = init_options unless init_options.empty?
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|