carioca 0.1
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/AUTHORS +8 -0
- data/COPYRIGHT +24 -0
- data/ChangeLog +4 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +41 -0
- data/INSTALL +7 -0
- data/Rakefile +63 -0
- data/carioca.gemspec +18 -0
- data/doc/manual.rdoc +36 -0
- data/lib/carioca.rb +228 -0
- data/lib/services.rb +26 -0
- data/lib/services/configuration.rb +52 -0
- data/lib/services/debug.rb +70 -0
- data/lib/services/logger.rb +52 -0
- data/spec/carioca_spec.rb +230 -0
- data/spec/config/services.registry +32 -0
- data/spec/init_spec.rb +1 -0
- data/spec/samples/dummy.rb +10 -0
- data/spec/spec_helper.rb +11 -0
- data/ultragreen_roodi_coding_convention.yml +25 -0
- metadata +99 -0
data/AUTHORS
ADDED
data/COPYRIGHT
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
carioca Copyright (c) 2013 Ultragreen Software, Romain GEORGES
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions
|
6
|
+
are met:
|
7
|
+
1. Redistributions of source code must retain the above copyright
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
11
|
+
documentation and/or other materials provided with the distribution.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
14
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
15
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
16
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
17
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
18
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
19
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
20
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
21
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
22
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
23
|
+
SUCH DAMAGE.
|
24
|
+
|
data/ChangeLog
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
json (1.6.5)
|
6
|
+
macaddr (1.0.0)
|
7
|
+
rake (0.9.2.2)
|
8
|
+
rcov (1.0.0)
|
9
|
+
rdoc (3.12)
|
10
|
+
json (~> 1.4)
|
11
|
+
roodi (2.2.0)
|
12
|
+
ruby_parser (~> 2.3.0)
|
13
|
+
rspec (2.9.0)
|
14
|
+
rspec-core (~> 2.9.0)
|
15
|
+
rspec-expectations (~> 2.9.0)
|
16
|
+
rspec-mocks (~> 2.9.0)
|
17
|
+
rspec-core (2.9.0)
|
18
|
+
rspec-expectations (2.9.0)
|
19
|
+
diff-lcs (~> 1.1.3)
|
20
|
+
rspec-mocks (2.9.0)
|
21
|
+
ruby_parser (2.3.1)
|
22
|
+
sexp_processor (~> 3.0)
|
23
|
+
sexp_processor (3.2.0)
|
24
|
+
uuid (2.3.1)
|
25
|
+
macaddr (~> 1.0)
|
26
|
+
yard (0.7.5)
|
27
|
+
yard-rspec (0.1)
|
28
|
+
yard
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
rake
|
35
|
+
rcov
|
36
|
+
rdoc
|
37
|
+
roodi
|
38
|
+
rspec
|
39
|
+
uuid
|
40
|
+
yard
|
41
|
+
yard-rspec
|
data/INSTALL
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'rspec'
|
4
|
+
require 'rake'
|
5
|
+
require "rake/clean"
|
6
|
+
require "rubygems/package_task"
|
7
|
+
require "rdoc/task"
|
8
|
+
require 'code_statistics'
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
require 'yard'
|
11
|
+
require 'yard/rake/yardoc_task.rb'
|
12
|
+
require "rake/tasklib"
|
13
|
+
require "roodi"
|
14
|
+
require "roodi_task"
|
15
|
+
|
16
|
+
|
17
|
+
RoodiTask.new() do | t |
|
18
|
+
t.patterns = %w(lib/**/*.rb)
|
19
|
+
t.config = "ultragreen_roodi_coding_convention.yml"
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
CLEAN.include('*.tmp','*.old')
|
24
|
+
CLOBBER.include('*.tmp', 'build/*','#*#')
|
25
|
+
|
26
|
+
|
27
|
+
content = File::readlines(File.join(File.dirname(__FILE__), 'carioca.gemspec')).join
|
28
|
+
spec = eval(content)
|
29
|
+
|
30
|
+
RSpec::Core::RakeTask.new('spec')
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
YARD::Rake::YardocTask.new do |t|
|
35
|
+
t.files = [ 'lib/**/*.rb', '-', 'doc/**/*','spec/**/*_spec.rb']
|
36
|
+
t.options += ['--title', "Gem Documentation"]
|
37
|
+
t.options += ['-o', "yardoc"]
|
38
|
+
t.options += ['-r', "doc/manual.rdoc"]
|
39
|
+
end
|
40
|
+
YARD::Config.load_plugin('yard-rspec')
|
41
|
+
|
42
|
+
namespace :yardoc do
|
43
|
+
task :clobber do
|
44
|
+
rm_r "yardoc" rescue nil
|
45
|
+
rm_r ".yardoc" rescue nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
task :clobber => "yardoc:clobber"
|
49
|
+
|
50
|
+
|
51
|
+
Gem::PackageTask.new(spec) do |pkg|
|
52
|
+
pkg.need_tar = true
|
53
|
+
pkg.need_zip = true
|
54
|
+
end
|
55
|
+
|
56
|
+
Rake::RDocTask.new('rdoc') do |d|
|
57
|
+
d.rdoc_files.include('doc/**/*','bin/*')
|
58
|
+
d.main = 'doc/manual.rdoc'
|
59
|
+
d.title = 'Uglibs : Ultragreen libraries'
|
60
|
+
d.options << '--line-numbers' << '--diagram' << '-SHN'
|
61
|
+
end
|
62
|
+
|
63
|
+
task :default => [:gem]
|
data/carioca.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = %q{carioca}
|
3
|
+
s.author = "Romain GEORGES"
|
4
|
+
s.version = "0.1"
|
5
|
+
s.date = %q{2013-02-18}
|
6
|
+
s.summary = %q{Carioca : Configuration Agent and Registry with Inversion Of Control for your Applications}
|
7
|
+
s.email = %q{romain@ultragreen.net}
|
8
|
+
s.homepage = %q{http://www.ultragreen.net}
|
9
|
+
s.description = %q{Carioca : provide a full IoC light Container for designing your applications}
|
10
|
+
s.has_rdoc = true
|
11
|
+
s.files = Dir['*/*/*/*'] + Dir['*/*/*'] + Dir['*/*'] + Dir['*']
|
12
|
+
s.bindir = nil
|
13
|
+
s.required_ruby_version = '>= 1.8.1'
|
14
|
+
s.add_development_dependency "rspec", ">= 2.0.0"
|
15
|
+
s.rdoc_options << '--title' << 'Carioca : Gem documentation' << '--main' << 'doc/manual.rdoc' << '--line-numbers'
|
16
|
+
# << '--diagram'
|
17
|
+
s.rubyforge_project = "nowarning"
|
18
|
+
end
|
data/doc/manual.rdoc
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
= Carioca
|
2
|
+
|
3
|
+
== Content
|
4
|
+
|
5
|
+
Author:: Romain GEORGES <romain@ultragreen.net>
|
6
|
+
Version:: 1.2
|
7
|
+
WWW:: http://www.ultragreen.net/projects/methodic
|
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
|
+
|
18
|
+
== Installation
|
19
|
+
|
20
|
+
In a valid Ruby environment :
|
21
|
+
|
22
|
+
$ sudo zsh
|
23
|
+
# gem ins carioca
|
24
|
+
|
25
|
+
== Implementation
|
26
|
+
|
27
|
+
* [Carioca]
|
28
|
+
|
29
|
+
|
30
|
+
== Example
|
31
|
+
|
32
|
+
|
33
|
+
== Copyright
|
34
|
+
|
35
|
+
<pre>carioca (c) 2012-2013 Romain GEORGES <romain@ultragreen.net> for Ultragreen Software </pre>
|
36
|
+
|
data/lib/carioca.rb
ADDED
@@ -0,0 +1,228 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'methodic'
|
4
|
+
require 'services'
|
5
|
+
require 'daemons'
|
6
|
+
|
7
|
+
module Carioca
|
8
|
+
|
9
|
+
module Services
|
10
|
+
class Registry
|
11
|
+
|
12
|
+
|
13
|
+
private_class_method :new
|
14
|
+
@@inst = nil
|
15
|
+
def Registry.init(_options = {})
|
16
|
+
options = Methodic::get_options(_options) do |m|
|
17
|
+
m.specify_defaults_value :file => './services.registry', :debug => false
|
18
|
+
m.merge!
|
19
|
+
end
|
20
|
+
|
21
|
+
@@inst = new(options) if @@inst.nil?
|
22
|
+
|
23
|
+
|
24
|
+
return @@inst
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
attr_reader :list
|
30
|
+
attr_reader :loaded_services
|
31
|
+
attr_reader :debug
|
32
|
+
|
33
|
+
|
34
|
+
def debug=(_value)
|
35
|
+
@log.level =(_value)? Logger::DEBUG : Logger::INFO
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def stop_service(_options)
|
40
|
+
options = Methodic.get_options(_options)
|
41
|
+
options.specify_class_of :name => String
|
42
|
+
options.specify_presence_of([:name])
|
43
|
+
options.validate!
|
44
|
+
if @loaded_services.include?(options[:name]) then
|
45
|
+
@loaded_engines[options[:name]].garbage if @loaded_services[options[:name]].respond_to? :garbage
|
46
|
+
@loaded_services.delete(options[:name])
|
47
|
+
@log.debug('Carioca') { "Service #{options[:name]} stopped" } if @log
|
48
|
+
return true
|
49
|
+
else
|
50
|
+
@log.debug('Carioca') { "Service #{options[:name]} not loaded" } if @log
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def register_service(_options)
|
57
|
+
options = Methodic.get_options(_options)
|
58
|
+
options.specify_classes_of({:name => String, :resource => String, :description => String, :type => Symbol, :init_options => Hash, :service => String })
|
59
|
+
options.specify_presences_of([:name,:type,:resource,:service])
|
60
|
+
options.validate!
|
61
|
+
_name = _options.delete(:name)
|
62
|
+
@list[_name] = _options
|
63
|
+
return true
|
64
|
+
end
|
65
|
+
|
66
|
+
def unregister_service(_options)
|
67
|
+
options = Methodic.get_options(_options = {})
|
68
|
+
options.specify_class_of :name => String
|
69
|
+
options.specify_presence_of :name
|
70
|
+
options.validate!
|
71
|
+
raise RegistryError::new("FONDATION : Can't unregistered the logger service" ) if options[:name] == 'logger'
|
72
|
+
raise RegistryError::new("Can't unregistered a loaded service" ) if @loaded_services.include?(options[:name])
|
73
|
+
@list.delete(options[:name])
|
74
|
+
return true
|
75
|
+
end
|
76
|
+
|
77
|
+
def discover_builtin
|
78
|
+
Carioca::Services::discover_builtin
|
79
|
+
end
|
80
|
+
|
81
|
+
def save!
|
82
|
+
res = false
|
83
|
+
File.open(@registry_filename, "w") do |f|
|
84
|
+
res = true if f.write(@list.to_yaml)
|
85
|
+
end
|
86
|
+
return res
|
87
|
+
end
|
88
|
+
|
89
|
+
def start_service(_options)
|
90
|
+
options = Methodic.get_options(_options)
|
91
|
+
options.specify_classes_of :name => String, :params => Hash
|
92
|
+
options.specify_presences_of([:name])
|
93
|
+
options.validate!
|
94
|
+
@log.debug('Carioca') { "getting service #{options[:name]}"} if @log
|
95
|
+
self.restart_service(options) unless @loaded_services.include? options[:name]
|
96
|
+
return @loaded_services[options[:name]]
|
97
|
+
end
|
98
|
+
|
99
|
+
alias :get_service :start_service
|
100
|
+
|
101
|
+
def restart_service(_options)
|
102
|
+
options = Methodic.get_options(_options)
|
103
|
+
options.specify_classes_of :name => String, :params => Hash
|
104
|
+
options.specify_presences_of [:name]
|
105
|
+
options.validate!
|
106
|
+
self.stop_service :name => options[:name] if @loaded_services.include? options[:name]
|
107
|
+
if options[:name] =~ /.*_.*/ then
|
108
|
+
(options[:instance],options[:shortname]) = options[:name].split(/_/)
|
109
|
+
else
|
110
|
+
options[:shortname] = options[:name]
|
111
|
+
end
|
112
|
+
verify_requires_dependancies(options)
|
113
|
+
require_service(options)
|
114
|
+
return instanciate_service(options)
|
115
|
+
end
|
116
|
+
|
117
|
+
def close
|
118
|
+
@log.debug('Carioca') { "closing Registry ..." }
|
119
|
+
@loaded_services.keys.each do |service|
|
120
|
+
next if service == 'logger'
|
121
|
+
@log.debug('Carioca') { "Stopping service #{service} ..."}
|
122
|
+
self.stop_service :name => service
|
123
|
+
end
|
124
|
+
@log.debug('Carioca') { "Registry services closed, logger will be closed asynchronously" }
|
125
|
+
self.stop_service :name => 'logger'
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
private
|
130
|
+
# private initializer
|
131
|
+
# @param [String] _filename default = '/data/config/service.registry' filename of the service Registry
|
132
|
+
# @return [Registry] Singleton
|
133
|
+
def initialize(_options)
|
134
|
+
@logger_not_in_reg = false
|
135
|
+
@debug = _options[:debug]
|
136
|
+
@registry_filename = _options[:file]
|
137
|
+
@list = Hash::new
|
138
|
+
load if File::exist?(@registry_filename)
|
139
|
+
unless @list.include?('logger') then
|
140
|
+
self.register_service({:name => 'logger',
|
141
|
+
:service => 'Carioca::Services::InternalLogger',
|
142
|
+
:resource => 'logger',
|
143
|
+
:description => "The standard ruby Logger internal wrapper Service",
|
144
|
+
:type => :builtin,
|
145
|
+
:init_options => { :target => "/tmp/log.file"}})
|
146
|
+
@logger_not_in_reg = true
|
147
|
+
end
|
148
|
+
|
149
|
+
@loaded_services = Hash::new
|
150
|
+
|
151
|
+
@log = self.start_service :name => 'logger'
|
152
|
+
@log.level =(@debug)? Logger::DEBUG : Logger::INFO
|
153
|
+
@log.debug('Carioca') { "Registry started, service logger preloaded" }
|
154
|
+
@log.debug('Carioca') { "Logger registered, not in configured registry" } if @logger_not_in_reg
|
155
|
+
end
|
156
|
+
|
157
|
+
def load
|
158
|
+
@list = YAML.load_file(@registry_filename)
|
159
|
+
end
|
160
|
+
|
161
|
+
private
|
162
|
+
|
163
|
+
def verify_requires_dependancies(options)
|
164
|
+
_name = options[:shortname]
|
165
|
+
if @list[_name].include?(:requires) then
|
166
|
+
@list[_name][:requires].each do |service|
|
167
|
+
unless @loaded_services.include?(service) then
|
168
|
+
@log.debug('Carioca') { "Registry dependancy found and not loaded : #{service}" }
|
169
|
+
restart_service :name => service
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def require_service(options)
|
176
|
+
_name = options[:shortname]
|
177
|
+
sym = ":#{@list[_name][:service].split('::').last}"
|
178
|
+
case @list[_name][:type]
|
179
|
+
when :file then
|
180
|
+
require @list[_name][:resource]
|
181
|
+
when :builtin then
|
182
|
+
_file = Carioca::Services::search_builtins _name
|
183
|
+
if _file then
|
184
|
+
require _file
|
185
|
+
else
|
186
|
+
raise RegistryError::new("Config failed")
|
187
|
+
end
|
188
|
+
when :gem then
|
189
|
+
eval("require '#{@list[_name][:resource]}'")
|
190
|
+
else
|
191
|
+
raise RegistryError::new("Config failed")
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def instanciate_service(options)
|
196
|
+
_name = options[:shortname]
|
197
|
+
@list[_name][:init_options] = options[:params] unless options[:params].nil?
|
198
|
+
if @list[_name][:init_options].nil? then
|
199
|
+
eval("@loaded_services[options[:name]] = #{@list[_name][:service]}::new")
|
200
|
+
else
|
201
|
+
eval("@loaded_services[options[:name]] = #{@list[_name][:service]}::new(@list[_name][:init_options])")
|
202
|
+
end
|
203
|
+
@log.debug('Carioca') { "Service #{options[:name]} started" } if @log
|
204
|
+
return @loaded_services[options[:name]]
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
class RegistryError < Exception; end
|
217
|
+
|
218
|
+
|
219
|
+
Module.class_eval do
|
220
|
+
def init_registry _options={}
|
221
|
+
options = Methodic.get_options(_options)
|
222
|
+
options.specify_classes_of :with_file => String
|
223
|
+
options.specify_default_value_of :with_file => './services.registry'
|
224
|
+
options.merge
|
225
|
+
options.validate!
|
226
|
+
Carioca::Services::Registry.init options[:with_file]
|
227
|
+
end
|
228
|
+
end
|
data/lib/services.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Carioca
|
2
|
+
module Services
|
3
|
+
def Services::search_builtins(_name)
|
4
|
+
asearch = Gem.searcher
|
5
|
+
spec = asearch.find('carioca')
|
6
|
+
if spec then
|
7
|
+
res = asearch.lib_dirs_for(spec).split('/')
|
8
|
+
res.pop
|
9
|
+
services_path = res.join('/').concat('/lib/services')
|
10
|
+
else
|
11
|
+
services_path = "lib/services"
|
12
|
+
end
|
13
|
+
_file ="#{services_path}/#{_name}.rb"
|
14
|
+
if File::exist? _file then
|
15
|
+
return _file
|
16
|
+
else
|
17
|
+
return false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def Services::discover_builtin
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright Ultragreen (c) 2005
|
3
|
+
#---
|
4
|
+
# Author : Romain GEORGES
|
5
|
+
# type : class definition Ruby
|
6
|
+
# obj : Generic config library
|
7
|
+
#---
|
8
|
+
# $Id$
|
9
|
+
|
10
|
+
|
11
|
+
require 'rubygems'
|
12
|
+
require 'methodic'
|
13
|
+
require 'services'
|
14
|
+
|
15
|
+
module Carioca
|
16
|
+
module Services
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
|
20
|
+
private
|
21
|
+
# constructor type could be a section name in <get_sections> result
|
22
|
+
# override could be true of false and precise if the block of the application have
|
23
|
+
# to override the main config hash result, default is true
|
24
|
+
def initialize(_options)
|
25
|
+
options = Methodic.get_options(_options)
|
26
|
+
options.specify_classes_of :config_file => String
|
27
|
+
options.validate!
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def test(params)
|
36
|
+
return 'toto'
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# interactive hacks
|
48
|
+
if $0 == __FILE__ then
|
49
|
+
puts "#{File::basename(__FILE__)}:"
|
50
|
+
puts 'this is a RUBY library file'
|
51
|
+
puts "Copyright (c) Ultragreen"
|
52
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright Ultragreen (c) 2012
|
3
|
+
#---
|
4
|
+
# Author : Romain GEORGES
|
5
|
+
# type : class definition Ruby
|
6
|
+
# obj : Generic Debugs tools library
|
7
|
+
#---
|
8
|
+
|
9
|
+
|
10
|
+
require 'rubygems'
|
11
|
+
require 'methodic'
|
12
|
+
|
13
|
+
|
14
|
+
module Carioca
|
15
|
+
module Services
|
16
|
+
|
17
|
+
# standard RAA dependency
|
18
|
+
|
19
|
+
|
20
|
+
class ProxyDebug
|
21
|
+
|
22
|
+
def initialize(_options)
|
23
|
+
options = Methodic.get_options(_options)
|
24
|
+
options.specify_classes_of :service => String, :params => Hash
|
25
|
+
options.specify_presence_of([:service])
|
26
|
+
options.validate!
|
27
|
+
if options[:params] then
|
28
|
+
@obj = Registry.init.start_service :name => options[:service], :params => options[:params]
|
29
|
+
else
|
30
|
+
@obj = Registry.init.start_service :name => options[:service]
|
31
|
+
end
|
32
|
+
@log = Registry.init.get_service :name => 'logger'
|
33
|
+
@mapped_service = options[:service]
|
34
|
+
end
|
35
|
+
|
36
|
+
def method_missing(methodname, *args,&block)
|
37
|
+
@log.debug("ProxyDebug") { "BEGIN CALL for mapped service #{@mapped_service} "}
|
38
|
+
@log.debug("ProxyDebug") { "called: #{methodname} " }
|
39
|
+
@log.debug("ProxyDebug") { "args : #{args}" }
|
40
|
+
|
41
|
+
if block_given? then
|
42
|
+
@log.debug("ProxyDebug") { "block given" }
|
43
|
+
a = @obj.send(methodname, *args,&block)
|
44
|
+
else
|
45
|
+
|
46
|
+
a = @obj.send(methodname, *args)
|
47
|
+
end
|
48
|
+
|
49
|
+
@log.debug("ProxyDebug") { "=> returned: #{a} " }
|
50
|
+
@log.debug("ProxyDebug") { 'END CALL' }
|
51
|
+
return a
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# protection for loading libs
|
60
|
+
if $0 == __FILE__ then
|
61
|
+
puts "#{File::basename(__FILE__)}:"
|
62
|
+
puts 'this is a RUBY library file'
|
63
|
+
puts "Copyright (c) Ultragreen"
|
64
|
+
puts "Version : #{Agents::LIB_VERSION}"
|
65
|
+
puts "Author : #{Agents::AUTHOR}"
|
66
|
+
puts "Date release : #{Agents::DATE}"
|
67
|
+
puts "Observation : #{Agents::OBS}"
|
68
|
+
end
|
69
|
+
|
70
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Copyright Ultragreen (c) 2005
|
3
|
+
#---
|
4
|
+
# Author : Romain GEORGES
|
5
|
+
# type : class definition Ruby
|
6
|
+
# obj : Generic config library
|
7
|
+
#---
|
8
|
+
# $Id$
|
9
|
+
|
10
|
+
|
11
|
+
require 'rubygems'
|
12
|
+
require 'logger'
|
13
|
+
require 'methodic'
|
14
|
+
|
15
|
+
module Carioca
|
16
|
+
module Services
|
17
|
+
|
18
|
+
class InternalLogger < Logger
|
19
|
+
|
20
|
+
private
|
21
|
+
# constructor type could be a section name in <get_sections> result
|
22
|
+
# override could be true of false and precise if the block of the application have
|
23
|
+
# to override the main config hash result, default is true
|
24
|
+
def initialize(_options)
|
25
|
+
options = Methodic.get_options(_options)
|
26
|
+
options.specify_default_value_of :target => STDOUT
|
27
|
+
options.validate!
|
28
|
+
|
29
|
+
super(options[:target])
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def garbage
|
36
|
+
self.close
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# interactive hacks
|
48
|
+
if $0 == __FILE__ then
|
49
|
+
puts "#{File::basename(__FILE__)}:"
|
50
|
+
puts 'this is a RUBY library file'
|
51
|
+
puts "Copyright (c) Ultragreen"
|
52
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require'rubygems'
|
2
|
+
require'rspec'
|
3
|
+
require 'carioca'
|
4
|
+
|
5
|
+
$debug = true
|
6
|
+
|
7
|
+
describe Carioca do
|
8
|
+
before :all do
|
9
|
+
FileUtils.rm_rf("/tmp/log.file")
|
10
|
+
$carioca = Carioca::Services::Registry.init :file => 'spec/config/services.registry', :debug => $debug
|
11
|
+
end
|
12
|
+
|
13
|
+
subject { Carioca }
|
14
|
+
it { should be_an_instance_of Module}
|
15
|
+
context "Carioca::Services" do
|
16
|
+
subject { Carioca::Services }
|
17
|
+
it { should be_an_instance_of Module }
|
18
|
+
end
|
19
|
+
|
20
|
+
context "Carioca::Services::Registry" do
|
21
|
+
subject { $carioca }
|
22
|
+
context "#init" do
|
23
|
+
it { should be_an_instance_of Carioca::Services::Registry }
|
24
|
+
it { $carioca.list.keys.should include "logger" }
|
25
|
+
it "should log Registry starting and logger init if debug mode", :if => $debug do
|
26
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Registry started, service logger preloaded/).size.should eq 1
|
27
|
+
end
|
28
|
+
it "should not log Registry starting and logger init if not debug mode", :unless => $debug do
|
29
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Registry started, service logger preloaded/).size.should eq 0
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
it "should be possible to log with this primary service" do
|
34
|
+
$logger = subject.get_service :name => 'logger'
|
35
|
+
$logger.info("test").should eq true
|
36
|
+
open('/tmp/log.file').grep(/INFO -- : test/).size.should eq 1
|
37
|
+
$logger.warn("test").should eq true
|
38
|
+
open('/tmp/log.file').grep(/WARN -- : test/).size.should eq 1
|
39
|
+
$logger.error("test").should eq true
|
40
|
+
open('/tmp/log.file').grep(/ERROR -- : test/).size.should eq 1
|
41
|
+
$logger.fatal("test").should eq true
|
42
|
+
open('/tmp/log.file').grep(/FATAL -- : test/).size.should eq 1
|
43
|
+
$logger.info("Program") { "running" }
|
44
|
+
open('/tmp/log.file').grep(/INFO -- Program: running/).size.should eq 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "attributs" do
|
49
|
+
context "#debug (RW)" do
|
50
|
+
it { should respond_to :debug }
|
51
|
+
it { should respond_to :debug= }
|
52
|
+
it "should be true if debug mode", :if => $debug do
|
53
|
+
subject.debug.should eq true
|
54
|
+
end
|
55
|
+
it "should be false if not debug mode", :unless => $debug do
|
56
|
+
subject.debug.should eq false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
context "#list (RO)" do
|
62
|
+
it { should respond_to :list }
|
63
|
+
it { should_not respond_to :list= }
|
64
|
+
it { subject.list.should be_an_instance_of Hash }
|
65
|
+
it { $carioca.list.keys.sort.should eq ["configuration", "debug", "dummy", "logger", "uuid"] }
|
66
|
+
end
|
67
|
+
|
68
|
+
context "#loaded_services (RO)" do
|
69
|
+
it { should respond_to :loaded_services }
|
70
|
+
it { should_not respond_to :loaded_services= }
|
71
|
+
it { subject.loaded_services.should be_an_instance_of Hash }
|
72
|
+
it { $carioca.loaded_services.keys.should eq ["logger"] }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "#start_service" do
|
77
|
+
it { should respond_to :start_service }
|
78
|
+
it { should respond_to :get_service }
|
79
|
+
|
80
|
+
context "Builtin services" do
|
81
|
+
context "Logger service" do
|
82
|
+
it "should be possible to get the logger service" do
|
83
|
+
$logger = subject.get_service :name => 'logger'
|
84
|
+
end
|
85
|
+
it "should log if debug mode", :if => $debug do
|
86
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: getting service logger/).size.should >= 1
|
87
|
+
end
|
88
|
+
it "should not log if debug mode", :unless => $debug do
|
89
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: getting service logger/).size.should eq 0
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
context "Debug Proxy Service" do
|
95
|
+
it "should start the registry with a service debug" do
|
96
|
+
myservice = subject.start_service :name => 'debug' , :params => {:service => 'configuration'}
|
97
|
+
myservice.test 'titi'
|
98
|
+
end
|
99
|
+
it { subject.list.keys.should include "debug" }
|
100
|
+
it "should log a proxy service log sequence" do
|
101
|
+
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: BEGIN CALL for mapped service configuration/).size.should eq 1
|
102
|
+
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: called: test/).size.should eq 1
|
103
|
+
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: args : titi/).size.should eq 1
|
104
|
+
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: => returned: toto/).size.should eq 1
|
105
|
+
open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: END CALL/).size.should eq 1
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
context "External services" do
|
111
|
+
|
112
|
+
it "should start a dummy service precised in registry YAML configuration" do
|
113
|
+
|
114
|
+
$dummy = subject.start_service :name => 'dummy'
|
115
|
+
$dummy.should be_an_instance_of ExternalServices::Dummy
|
116
|
+
end
|
117
|
+
it { subject.list.keys.should include "dummy" }
|
118
|
+
it "should be possible to use test method of the dummy service, and return 'OK'" do
|
119
|
+
$dummy.test.should eq 'OK'
|
120
|
+
end
|
121
|
+
it "should start a gem service precised in registry YAML configuration" do
|
122
|
+
$uuid = subject.start_service :name => 'uuid'
|
123
|
+
$uuid.should be_an_instance_of UUID
|
124
|
+
end
|
125
|
+
it { subject.list.keys.should include "uuid" }
|
126
|
+
it "should be possible to execute a method with the gem service" do
|
127
|
+
$uuid.generate.should be_a_kind_of String
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
context "#stop_service" do
|
134
|
+
it { should respond_to :stop_service }
|
135
|
+
it "should raise ArgumentError if the option hash argument passed not include :name" do
|
136
|
+
lambda { subject.stop_service }.should raise_error ArgumentError
|
137
|
+
lambda { subject.stop_service(:notname => 'debug') }.should raise_error ArgumentError
|
138
|
+
end
|
139
|
+
it "should return true if service really stop" do
|
140
|
+
subject.stop_service({:name => 'dummy'}).should eq true
|
141
|
+
end
|
142
|
+
it "should log if debug mode", :if => $debug do
|
143
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dummy stopped/).size.should >= 1
|
144
|
+
end
|
145
|
+
it "should not log if debug mode", :unless => $debug do
|
146
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dummy stopped/).size.should = 0
|
147
|
+
end
|
148
|
+
it "should return false if service not already running" do
|
149
|
+
subject.stop_service({:name => 'dum'}).should eq false
|
150
|
+
end
|
151
|
+
it "should log if debug mode and service not loaded", :if => $debug do
|
152
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dum not loaded/).size.should >= 1
|
153
|
+
end
|
154
|
+
it "should not log if debug mode and service not loaded", :unless => $debug do
|
155
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dum not loaded/).size.should = 0
|
156
|
+
end
|
157
|
+
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
context "#restart_service" do
|
162
|
+
pending
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
context "#discover_builtin" do
|
169
|
+
pending
|
170
|
+
end
|
171
|
+
context "#register_service" do
|
172
|
+
pending
|
173
|
+
end
|
174
|
+
context "#unregister_service" do
|
175
|
+
pending
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
context "#save!" do
|
181
|
+
it { should respond_to :save! }
|
182
|
+
it "should save the config" do
|
183
|
+
subject.save!.should eq true
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
context "#close" do
|
190
|
+
context "Closing the Carioca registry" do
|
191
|
+
it { should respond_to :close }
|
192
|
+
it "should close" do
|
193
|
+
subject.close.should eq true
|
194
|
+
end
|
195
|
+
it "should log a registry closing notification if debug mode", :if => $debug do
|
196
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: closing Registry .../).size.should eq 1
|
197
|
+
end
|
198
|
+
it "should not log a registry closing notification if not debug mode", :unless => $debug do
|
199
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: closing Registry .../).size.should eq 0
|
200
|
+
end
|
201
|
+
it "should log a stopping notification for each services if debug mode", :if => $debug do
|
202
|
+
['debug','uuid','configuration'].each do |service|
|
203
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Stopping service #{service} .../).size.should eq 1
|
204
|
+
end
|
205
|
+
end
|
206
|
+
it "should not log a stopping notification for each services if not debug mode", :unless => $debug do
|
207
|
+
['debug','uuid','configuration'].each do |service|
|
208
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Stopping service #{service} .../).size.should eq 0
|
209
|
+
end
|
210
|
+
end
|
211
|
+
it "should log a registry closing confirmation if debug mode", :if => $debug do
|
212
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Registry services closed, logger will be closed asynchronously/).size.should eq 1
|
213
|
+
end
|
214
|
+
it "should not log a registry closing confirmation if not debug mode", :unless => $debug do
|
215
|
+
open('/tmp/log.file').grep(/DEBUG -- Carioca: Registry services closed, logger will be closed asynchronously/).size.should eq 0
|
216
|
+
end
|
217
|
+
it "should loaded services empty" do
|
218
|
+
subject.loaded_services.empty?.should eq true
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
---
|
2
|
+
uuid:
|
3
|
+
:type: :gem
|
4
|
+
:service: UUID
|
5
|
+
:description: a Rubygems called uuid to build UUID ids.
|
6
|
+
:resource: uuid
|
7
|
+
logger:
|
8
|
+
:type: :builtin
|
9
|
+
:service: Carioca::Services::InternalLogger
|
10
|
+
:description: The standard ruby Logger internal wrapper Service
|
11
|
+
:resource: logger
|
12
|
+
:init_options:
|
13
|
+
:target: /tmp/log.file
|
14
|
+
dummy:
|
15
|
+
:type: :file
|
16
|
+
:service: ExternalServices::Dummy
|
17
|
+
:description: a dummy test service
|
18
|
+
:resource: spec/samples/dummy.rb
|
19
|
+
debug:
|
20
|
+
:type: :builtin
|
21
|
+
:service: Carioca::Services::ProxyDebug
|
22
|
+
:description: Class Proxy debug logger Service
|
23
|
+
:resource: debug
|
24
|
+
:init_options:
|
25
|
+
:service: configuration
|
26
|
+
configuration:
|
27
|
+
:type: :builtin
|
28
|
+
:service: Carioca::Services::Configuration
|
29
|
+
:description: Configuration Agent Service
|
30
|
+
:resource: configuration
|
31
|
+
:init_options:
|
32
|
+
:config_file: ./.config
|
data/spec/init_spec.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "spec_helper"
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
# config.filter_run :focus
|
11
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
AssignmentInConditionalCheck:
|
2
|
+
CaseMissingElseCheck:
|
3
|
+
ClassLineCountCheck:
|
4
|
+
line_count: 300
|
5
|
+
ClassNameCheck:
|
6
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
7
|
+
#ClassVariableCheck:
|
8
|
+
CyclomaticComplexityBlockCheck:
|
9
|
+
complexity: 4
|
10
|
+
CyclomaticComplexityMethodCheck:
|
11
|
+
complexity: 10
|
12
|
+
EmptyRescueBodyCheck:
|
13
|
+
ForLoopCheck:
|
14
|
+
MethodLineCountCheck:
|
15
|
+
line_count: 30
|
16
|
+
MethodNameCheck:
|
17
|
+
pattern: !ruby/regexp /^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
|
18
|
+
# MissingForeignKeyIndexCheck:
|
19
|
+
ModuleLineCountCheck:
|
20
|
+
line_count: 500
|
21
|
+
ModuleNameCheck:
|
22
|
+
pattern: !ruby/regexp /^[A-Z][a-zA-Z0-9]*$/
|
23
|
+
ParameterNumberCheck:
|
24
|
+
parameter_count: 5
|
25
|
+
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carioca
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
version: "0.1"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Romain GEORGES
|
12
|
+
autorequire:
|
13
|
+
bindir:
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2013-02-18 00:00:00 +01:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: rspec
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
segments:
|
27
|
+
- 2
|
28
|
+
- 0
|
29
|
+
- 0
|
30
|
+
version: 2.0.0
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
description: "Carioca : provide a full IoC light Container for designing your applications"
|
34
|
+
email: romain@ultragreen.net
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
files:
|
42
|
+
- spec/samples/dummy.rb
|
43
|
+
- spec/config/services.registry
|
44
|
+
- lib/services/configuration.rb
|
45
|
+
- lib/services/debug.rb
|
46
|
+
- lib/services/logger.rb
|
47
|
+
- spec/init_spec.rb
|
48
|
+
- spec/spec_helper.rb
|
49
|
+
- spec/carioca_spec.rb
|
50
|
+
- lib/carioca.rb
|
51
|
+
- lib/services.rb
|
52
|
+
- doc/manual.rdoc
|
53
|
+
- carioca.gemspec
|
54
|
+
- Rakefile
|
55
|
+
- INSTALL
|
56
|
+
- Gemfile.lock
|
57
|
+
- Gemfile
|
58
|
+
- ChangeLog
|
59
|
+
- COPYRIGHT
|
60
|
+
- ultragreen_roodi_coding_convention.yml
|
61
|
+
- AUTHORS
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://www.ultragreen.net
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --title
|
69
|
+
- "Carioca : Gem documentation"
|
70
|
+
- --main
|
71
|
+
- doc/manual.rdoc
|
72
|
+
- --line-numbers
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 1
|
81
|
+
- 8
|
82
|
+
- 1
|
83
|
+
version: 1.8.1
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project: nowarning
|
94
|
+
rubygems_version: 1.3.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: "Carioca : Configuration Agent and Registry with Inversion Of Control for your Applications"
|
98
|
+
test_files: []
|
99
|
+
|