carioca 1.3 → 1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # coding: utf-8
2
2
  #---
3
3
  # Author : Romain GEORGES
4
4
  # type : gem component library
@@ -11,13 +11,13 @@ module Carioca
11
11
 
12
12
  # namespace Services for Registry AND buitlins
13
13
  module Services
14
- # class method returning full path in Carioca gem for builtin services files according to installed gem path.
14
+ # class method returning full path in Carioca gem for builtin services files according to installed gem path.
15
15
  # @note do not use directly for generale purpose (expert/hacks only)
16
16
  # @param [String] _name the name of a service
17
17
  # @return [String,false] the full path filename orfalse if not found
18
18
  def Services::search_builtins(_name)
19
19
  if Gem::Specification.respond_to?(:find_by_name)
20
- begin
20
+ begin
21
21
  spec = Gem::Specification.find_by_name('carioca')
22
22
  rescue LoadError
23
23
  spec = nil
@@ -44,13 +44,13 @@ module Carioca
44
44
  return false
45
45
  end
46
46
  end
47
-
47
+
48
48
  # class method returning the path of a file in gem if exist or false
49
49
  # @note do not use directly for generale purpose (expert/hacks only)
50
50
  # @return [String|FalseClass] the full path of a service file
51
51
  def Services::search_file_in_gem(_gem,_file)
52
52
  if Gem::Specification.respond_to?(:find_by_name)
53
- begin
53
+ begin
54
54
  spec = Gem::Specification.find_by_name(_gem)
55
55
  rescue LoadError
56
56
  spec = nil
@@ -79,7 +79,7 @@ module Carioca
79
79
  # @return [Hash] the [Carioca::Services::Registry]@list complement
80
80
  def Services::discover_builtins
81
81
  if Gem::Specification.respond_to?(:find_by_name)
82
- begin
82
+ begin
83
83
  spec = Gem::Specification.find_by_name('carioca')
84
84
  rescue LoadError
85
85
  spec = nil
@@ -114,7 +114,7 @@ module Carioca
114
114
  def Services::validate_service(file,res)
115
115
  init_options = {}
116
116
  if open(file).grep(/^# \$BUILTIN/).size > 0 then
117
- service = open(file).grep(/# \$SERVICE/).first.split[2]
117
+ service = open(file).grep(/# \$SERVICE/).first.split[2]
118
118
  resource = open(file).grep(/# \$RESOURCE/).first.split[2]
119
119
  desc = open(file).grep(/# \$DESCRIPTION/).first
120
120
  desc = desc.split(' ')
@@ -124,13 +124,13 @@ module Carioca
124
124
  prev = opt.split
125
125
  init_options[prev[2].to_sym] = prev[4]
126
126
  end
127
- distributed = (open(file).grep(/# \$DISTRIBUTED/))? true : false
127
+ distributed = (open(file).grep(/# \$DISTRIBUTED/))? true : false
128
128
  req = open(file).grep(/# \$REQUIRES/)
129
129
  if req.empty? then
130
130
  requires = []
131
131
  else
132
132
  requires = req.split
133
- requires.shift
133
+ requires.shift
134
134
  end
135
135
 
136
136
  end
@@ -138,6 +138,6 @@ module Carioca
138
138
  res[resource] = { :service => service, :type => :builtin, :description => description, :resource => resource}
139
139
  res[resource][:init_options] = init_options unless init_options.empty?
140
140
  end
141
- end
141
+ end
142
142
  end
143
143
  end
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
1
+ # coding: utf-8
2
2
  # $BUILTIN
3
3
  # $NAME configuration
4
- # $SERVICE Carioca::Services::Configuration
4
+ # $SERVICE Carioca::Services::Configuration
5
5
  # $RESOURCE configuration
6
6
  # $DESCRIPTION The Carioca Configuration Service
7
7
  # $INIT_OPTIONS config_file => ./.config
8
8
 
9
9
  # Copyright Ultragreen (c) 2005
10
10
  #---
11
- # Author : Romain GEORGES
11
+ # Author : Romain GEORGES
12
12
  # type : class definition Ruby
13
13
  # obj : Generic config library
14
14
  #---
@@ -21,12 +21,13 @@ require_relative '../services'
21
21
  require 'yaml'
22
22
  require 'drb/drb'
23
23
  require 'xmlsimple'
24
+ require 'active_support/all'
24
25
 
25
- # overwriting Hash class
26
+ # overwriting Hash class
26
27
  # @private
27
28
  class Hash
28
29
 
29
- # recursively transform Hash keys form String to Symbols
30
+ # recursively transform Hash keys form String to Symbols
30
31
  # come from Rails code
31
32
  # exist in Ruby 2.0
32
33
  def deep_symbolize
@@ -40,7 +41,7 @@ class Hash
40
41
 
41
42
  # pretty accessor for hash record
42
43
  # like ahash[:key] => ahash.key
43
- # r/w accessor
44
+ # r/w accessor
44
45
  def method_missing(name, *args, &block)
45
46
  if name.to_s =~ /(.+)=$/
46
47
  self[$1.to_sym] = args.first
@@ -49,14 +50,14 @@ class Hash
49
50
  end
50
51
  end
51
52
  end
52
-
53
+
53
54
 
54
55
 
55
56
 
56
57
 
57
58
  module Carioca
58
59
 
59
- module Services
60
+ module Services
60
61
 
61
62
  # settings Hash record utilities class
62
63
  # @note please do not use Standalone ( dependancy of Configuration class )
@@ -66,7 +67,7 @@ module Carioca
66
67
 
67
68
  # the name of the config file in YAML format
68
69
  attr_accessor :config_file
69
-
70
+
70
71
  # constructor (pre-open the config file in default:YAML)
71
72
  # @param [Hash] options the options records
72
73
  # @option options [String] :config_file (REQUIRED) the name of the config file
@@ -77,13 +78,14 @@ module Carioca
77
78
  @config_file = options[:config_file]
78
79
  @xml_input = options[:xml_input]
79
80
  @content = options[:content]
81
+ @force_array = options[:force_array]
80
82
  newsets = {}
81
83
  if @config_file then
82
84
  @content = File::readlines(@config_file).join if File::exist?(@config_file)
83
85
  end
84
86
  if options[:xml_input] then
85
87
  newsets = XmlSimple.xml_in( @content, {
86
- 'ForceArray' => [ 'sequence', 'step' ],
88
+ 'ForceArray' => @force_array,
87
89
  'KeepRoot' => true,
88
90
  }).deep_symbolize_keys
89
91
  else
@@ -92,7 +94,7 @@ module Carioca
92
94
  newsets = newsets[options[:context].to_sym] if options[:context] && newsets[options[:context].to_sym]
93
95
  deep_merge!(self, newsets)
94
96
  end
95
-
97
+
96
98
  # save the Hash(self) in the file named by @config_file
97
99
  # @return [TrueClass,FalseClass] true if save! successfull
98
100
  # @note TODO save in XML format
@@ -106,7 +108,7 @@ module Carioca
106
108
 
107
109
 
108
110
  private
109
- # full recursive merger for hash
111
+ # full recursive merger for hash
110
112
  def deep_merge!(target, data)
111
113
  merger = proc{|key, v1, v2|
112
114
  Settings === v1 && Settings === v2 ? v1.merge(v2, &merger) : v2 }
@@ -116,22 +118,22 @@ module Carioca
116
118
 
117
119
  end
118
120
 
119
-
120
-
121
-
121
+
122
+
123
+
122
124
  # Service Configuration of Carioca
123
- class Configuration
124
-
125
+ class Configuration
126
+
125
127
  include DRb::DRbUndumped
126
-
127
- # @example
128
+
129
+ # @example
128
130
  # config = Carioca::Services::Configuration::new :config_file => 'afilename', :context => 'production'
129
131
  # p config.config_file
130
132
  # config_file = 'newfilename'
131
133
  # @attr_reader [String] the filename of the YAML struct
132
134
  attr_accessor :settings
133
135
 
134
-
136
+
135
137
  # Configuration service constructor (open config)
136
138
  # @param [Hash] _options the params
137
139
  # @option _options [String] :config_file the filename of the config
@@ -143,28 +145,28 @@ module Carioca
143
145
  options.merge
144
146
  @settings = Carioca::Services::Settings.new(options)
145
147
  end
146
-
147
- # Proxy to @settings.save!
148
+
149
+ # Proxy to @settings.save!
148
150
  # save the Hash(self) in the file named by @config_file
149
151
  # @return [TrueClass,FalseClass] true if save! successfull
150
152
  # @example usage
151
153
  # config = Carioca::Services::Configuration::new :config_file => 'afilename', :context => 'production'
152
- # config.config_file = 'newfile'
154
+ # config.config_file = 'newfile'
153
155
  # config.save!
154
156
  def save!
155
157
  @settings.save!
156
158
  end
157
159
 
158
-
160
+
159
161
  # reading wrapper to @settings.config_file accessor
160
- # @return [String] @config_file the file name
162
+ # @return [String] @config_file the file name
161
163
  # @example usage
162
164
  # config = Carioca::Services::Configuration::new :config_file => 'afilename', :context => 'production'
163
- # p config.config_file
165
+ # p config.config_file
164
166
  def config_file
165
167
  @settings.config_file
166
168
  end
167
-
169
+
168
170
  # writting wrapper to @settings.config_file accessor
169
171
  # @param [String] name the file name
170
172
  # @example usage
@@ -182,7 +184,7 @@ module Carioca
182
184
  @settings = nil
183
185
  return true
184
186
  end
185
-
187
+
186
188
  end
187
189
  end
188
190
  end
@@ -191,7 +193,7 @@ end
191
193
 
192
194
 
193
195
 
194
- # interactive hacks
196
+ # interactive hacks
195
197
  if $0 == __FILE__ then
196
198
  conf =Carioca::Services::Configuration::new :config_file => 'spec/config/.config'
197
199
  p conf
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # coding: utf-8
2
2
  # $BUILTIN
3
3
  # $NAME debug
4
4
  # $SERVICE Carioca::Services::ProxyDebug
@@ -6,7 +6,7 @@
6
6
  # $DESCRIPTION Proxy class debugger Service for Carioca
7
7
  # Copyright Ultragreen (c) 2012
8
8
  #---
9
- # Author : Romain GEORGES
9
+ # Author : Romain GEORGES
10
10
  # type : class definition Ruby
11
11
  # obj : Generic Debugs tools library
12
12
  #---
@@ -18,12 +18,12 @@ require 'methodic'
18
18
 
19
19
  module Carioca
20
20
  module Services
21
-
22
-
21
+
22
+
23
23
  # Service Debug of Carioca
24
24
  # Proxy Class Debug for devs
25
25
  class ProxyDebug
26
-
26
+
27
27
  # ProxyDebug service constructor (has a class proxy => so a service proxy)
28
28
  # @param [Hash] _options the params
29
29
  # @option _options [String] :service the name of the service you want to proxyfying
@@ -41,10 +41,10 @@ module Carioca
41
41
  @log = Registry.init.get_service :name => 'logger'
42
42
  @mapped_service = options[:service]
43
43
  end
44
-
45
- # method_missing overload to make the class proxy efficient
44
+
45
+ # method_missing overload to make the class proxy efficient
46
46
  def method_missing(methodname, *args,&block)
47
- @log.debug("ProxyDebug") { "BEGIN CALL for mapped service #{@mapped_service} "}
47
+ @log.debug("ProxyDebug") { "BEGIN CALL for mapped service #{@mapped_service} "}
48
48
  @log.debug("ProxyDebug") { "called: #{methodname} " }
49
49
  @log.debug("ProxyDebug") { "args : #{args.join " "}" }
50
50
  if block_given? then
@@ -69,5 +69,3 @@ if $0 == __FILE__ then
69
69
  puts 'this is a RUBY library file'
70
70
  puts "Copyright (c) Ultragreen"
71
71
  end
72
-
73
-
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env ruby
1
+ # coding: utf-8
2
2
  # $BUILTIN
3
3
  # $NAME logger
4
4
  # $SERVICE Carioca::Services::InternalLogger
@@ -7,7 +7,7 @@
7
7
  # $INIT_OPTIONS target => /tmp/log.file
8
8
  # Copyright Ultragreen (c) 2005
9
9
  #---
10
- # Author : Romain GEORGES
10
+ # Author : Romain GEORGES
11
11
  # type : class definition Ruby
12
12
  # obj : Generic config library
13
13
  #---
@@ -18,16 +18,16 @@ require 'logger'
18
18
  require 'methodic'
19
19
 
20
20
  module Carioca
21
- module Services
21
+ module Services
22
22
 
23
23
  # Service Logger (InternalLogger) of Carioca,
24
24
  # @note integrally based on Logger from logger Gem
25
25
  class InternalLogger < Logger
26
-
26
+
27
27
  private
28
-
28
+
29
29
  # logger service constructor (open log)
30
- # @param [Hash] _options the params
30
+ # @param [Hash] _options the params
31
31
  # @option _options [String] :target the filename where to log
32
32
  def initialize(_options = {})
33
33
  options = Methodic.get_options(_options)
@@ -35,22 +35,22 @@ module Carioca
35
35
  options.merge
36
36
  super(options[:target])
37
37
  end
38
-
38
+
39
39
  # garbage service hook
40
- # @note close the logger
40
+ # @note close the logger
41
41
  def garbage
42
42
  self.close
43
43
  end
44
-
44
+
45
45
  end
46
46
  end
47
-
48
-
49
-
47
+
48
+
49
+
50
50
  end
51
51
 
52
52
 
53
- # interactive hacks
53
+ # interactive hacks
54
54
  if $0 == __FILE__ then
55
55
  puts "#{File::basename(__FILE__)}:"
56
56
  puts 'this is a RUBY library file'
@@ -1,5 +1,6 @@
1
+ # coding: utf-8
1
2
  require 'rake'
2
- require 'rubygems'
3
+ require 'rubygems'
3
4
  require 'carioca'
4
5
 
5
6
  $VERBOSE = nil
@@ -18,6 +19,5 @@ end
18
19
  res.pop
19
20
  tasks_path = res.join('/').concat('/lib/carioca/tasks/')
20
21
 
21
-
22
- Dir["#{tasks_path}/*.rake"].each { |ext| load ext }
23
22
 
23
+ Dir["#{tasks_path}/*.rake"].each { |ext| load ext }
@@ -1,4 +1,5 @@
1
- require 'carioca'
1
+ # coding: utf-8
2
+ require 'carioca'
2
3
  namespace :carioca do
3
4
  desc "initialize Carioca Registry"
4
5
  task :init_registry do
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require'rubygems'
2
3
  require'rspec'
3
4
  require 'carioca'
@@ -7,7 +8,7 @@ $debug = true
7
8
 
8
9
  describe Carioca do
9
10
 
10
- before :all do
11
+ before :all do
11
12
  FileUtils.rm_rf("/tmp/log.file")
12
13
  File::unlink('/tmp/dorsal/ringserver.pid') if File::exist?('/tmp/dorsal/ringserver.pid')
13
14
  File::unlink('/tmp/dorsal/service-distdummy.pid') if File::exist?('/tmp/dorsal/service-distdummy.pid')
@@ -20,25 +21,25 @@ describe Carioca do
20
21
  res = `kill -TERM #{pid.chomp}`
21
22
  end
22
23
  $carioca = Carioca::Services::Registry.init :file => 'spec/config/services.registry', :debug => $debug
23
- end
24
-
24
+ end
25
+
25
26
  subject { Carioca }
26
27
  it { should be_an_instance_of Module}
27
28
  context "Carioca::Services" do
28
29
  subject { Carioca::Services }
29
30
  it { should be_an_instance_of Module }
30
31
  end
31
-
32
+
32
33
  context "Carioca::Services::Registry" do
33
34
  subject { $carioca }
34
- context "#init" do
35
- it "should be a Singleton" do
35
+ context "#init" do
36
+ it "should be a Singleton" do
36
37
  carioca1 = Carioca::Services::Registry.init
37
38
  carioca2 = Carioca::Services::Registry.init
38
39
  test = (carioca1.inspect == carioca2.inspect)
39
40
  test.should be true
40
41
  end
41
-
42
+
42
43
 
43
44
  it { should be_an_instance_of Carioca::Services::Registry }
44
45
  it { $carioca.list.keys.should include "logger" }
@@ -52,7 +53,7 @@ describe Carioca do
52
53
 
53
54
  it "should be possible to log with this primary service" do
54
55
  $logger = subject.get_service :name => 'logger'
55
- $logger.info("test").should eq true
56
+ $logger.info("test").should eq true
56
57
  open('/tmp/log.file').grep(/INFO -- : test/).size.should eq 1
57
58
  $logger.warn("test").should eq true
58
59
  open('/tmp/log.file').grep(/WARN -- : test/).size.should eq 1
@@ -69,11 +70,11 @@ describe Carioca do
69
70
  context "#debug (RW)" do
70
71
  it { should respond_to :debug }
71
72
  it { should respond_to :debug= }
72
- it "should be true if debug mode", :if => $debug do
73
- subject.debug.should eq true
73
+ it "should be true if debug mode", :if => $debug do
74
+ subject.debug.should eq true
74
75
  end
75
76
  it "should be false if not debug mode", :unless => $debug do
76
- subject.debug.should eq false
77
+ subject.debug.should eq false
77
78
  end
78
79
  end
79
80
 
@@ -97,7 +98,7 @@ describe Carioca do
97
98
  it { subject.loaded_services.should be_an_instance_of Hash }
98
99
  it { $carioca.loaded_services.keys.should eq ["logger"] }
99
100
  end
100
-
101
+
101
102
  context "#registry_filename" do
102
103
  it { should respond_to :registry_filename }
103
104
  it { should respond_to :registry_filename= }
@@ -107,42 +108,42 @@ describe Carioca do
107
108
 
108
109
  end
109
110
 
110
- context "#start_service" do
111
+ context "#start_service" do
111
112
  it { should respond_to :start_service }
112
113
  it { should respond_to :get_service }
113
114
 
114
115
  context "Builtin services" do
115
116
  context "Logger service" do
116
- it "should be possible to get the builtin logger service" do
117
+ it "should be possible to get the builtin logger service" do
117
118
  $logger = subject.get_service :name => 'logger'
118
119
  end
119
- it "should log if debug mode", :if => $debug do
120
+ it "should log if debug mode", :if => $debug do
120
121
  open('/tmp/log.file').grep(/DEBUG -- Carioca: getting service logger/).size.should >= 1
121
122
  end
122
- it "should not log if debug mode", :unless => $debug do
123
+ it "should not log if debug mode", :unless => $debug do
123
124
  open('/tmp/log.file').grep(/DEBUG -- Carioca: getting service logger/).size.should eq 0
124
125
  end
125
126
  end
126
-
127
+
127
128
 
128
129
  context "Debug Proxy Service" do
129
- it "should start the builtin service debug" do
130
+ it "should start the builtin service debug" do
130
131
  myservice = subject.start_service :name => 'debug' , :params => {:service => 'dummy'}
131
- myservice.test 'titi'
132
+ myservice.test 'titi'
132
133
  end
133
134
  it { subject.list.keys.should include "debug" }
134
- it "should log a proxy service log sequence", :if => $debug do
135
- open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: BEGIN CALL for mapped service dummy/).size.should eq 1
136
- open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: called: test/).size.should eq 1
135
+ it "should log a proxy service log sequence", :if => $debug do
136
+ open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: BEGIN CALL for mapped service dummy/).size.should eq 1
137
+ open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: called: test/).size.should eq 1
137
138
  open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: args : titi/).size.should eq 1
138
- open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: => returned: OK/).size.should eq 1
139
+ open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: => returned: OK/).size.should eq 1
139
140
  open('/tmp/log.file').grep(/DEBUG -- ProxyDebug: END CALL/).size.should eq 1
140
141
  end
141
142
  end
142
-
143
+
143
144
  context "Configuration Service" do
144
145
  it "should start the builtin configuration service" do
145
- $conf = subject.start_service :name => 'configuration'
146
+ $conf = subject.start_service :name => 'configuration'
146
147
  end
147
148
  it "should access flat settings" do
148
149
  $conf.settings.context1.key0.should eq 'value'
@@ -150,21 +151,21 @@ describe Carioca do
150
151
  $conf.settings.context1.node.key2 eq 'value2'
151
152
  $conf.settings.context2.key0.should eq 'value'
152
153
  $conf.settings.context2.node.key1 eq 'value3'
153
- $conf.settings.context2.node.key2 eq 'value4'
154
+ $conf.settings.context2.node.key2 eq 'value4'
154
155
  end
155
156
  it "should access contextualized settings" do
156
157
  $conf = subject.restart_service :name => 'configuration', :params => { :context => 'context2' }
157
158
  $conf.settings.key0.should eq 'value'
158
159
  $conf.settings.node.key1 eq 'value3'
159
- $conf.settings.node.key2 eq 'value4'
160
+ $conf.settings.node.key2 eq 'value4'
160
161
  end
161
162
  it "should access inherited settings from YAML" do
162
163
  $conf = subject.restart_service :name => 'configuration', :params => { :context => 'context3' }
163
164
  $conf.settings.key0.should eq 'value'
164
165
  $conf.settings.node.key1 eq 'value3'
165
- $conf.settings.node.key2 eq 'value4'
166
+ $conf.settings.node.key2 eq 'value4'
166
167
  end
167
- it "should be possible to override a config value" do
168
+ it "should be possible to override a config value" do
168
169
  $conf.settings.node.key2 = 'value8'
169
170
  $conf.settings.node.key2.should eq 'value8'
170
171
  $conf.settings[:node][:key2] = 'value6'
@@ -173,23 +174,23 @@ describe Carioca do
173
174
  it { $conf.should respond_to :config_file }
174
175
  it { $conf.should respond_to :config_file= }
175
176
  it { $conf.should respond_to :save! }
176
-
177
- it "should be saved in other file" do
177
+
178
+ it "should be saved in other file" do
178
179
  $conf.config_file = '/tmp/.config'
179
180
  $conf.save!.should be true
180
-
181
+
181
182
  end
182
183
  it "should stop the configuration service" do
183
184
  subject.stop_service({:name => 'configuration'}).should eq true
184
185
  end
185
186
  end
186
-
187
+
187
188
  end
188
189
 
189
190
  context "External services" do
190
-
191
- it "should start a dummy service precised in registry YAML configuration" do
192
-
191
+
192
+ it "should start a dummy service precised in registry YAML configuration" do
193
+
193
194
  $dummy = subject.start_service :name => 'dummy'
194
195
  $dummy.should be_an_instance_of ExternalServices::Dummy
195
196
  end
@@ -218,10 +219,10 @@ describe Carioca do
218
219
 
219
220
 
220
221
  context "Distributed service" do
221
- it "should be possible to execute a distributed service" do
222
- $dummy_dist = subject.start_service :name => 'distdummy'
222
+ it "should be possible to execute a distributed service" do
223
+ $dummy_dist = subject.start_service :name => 'distdummy'
223
224
  end
224
- it "should exist a processus Ring server" do
225
+ it "should exist a processus Ring server" do
225
226
  File::exist?('/tmp/dorsal/ringserver.pid').should be true
226
227
  pid = `ps aux|grep ruby|grep -v grep |grep 'Ultragreen Ring Server'|awk '{ print $2}'`
227
228
  pid.should_not be_empty
@@ -235,12 +236,12 @@ describe Carioca do
235
236
  it "should include 'distdummy' in @loaded_services.keys" do
236
237
  subject.loaded_services.should include "distdummy"
237
238
  end
238
- it "should distdummy be a DRbObject" do
239
+ it "should distdummy be a DRbObject" do
239
240
  $dummy_dist.should be_a_kind_of DRb::DRbObject
240
241
  end
241
242
  it "should be possible to use test method of the distributed dummy service, and return 'OK'" do
242
243
  $dummy_dist.test.should eq 'OK'
243
- end
244
+ end
244
245
  end
245
246
 
246
247
  end
@@ -256,19 +257,19 @@ describe Carioca do
256
257
  it "should return true if service really stop" do
257
258
  subject.stop_service({:name => 'dummy'}).should eq true
258
259
  end
259
- it "should log if debug mode", :if => $debug do
260
+ it "should log if debug mode", :if => $debug do
260
261
  open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dummy stopped/).size.should >= 1
261
262
  end
262
- it "should not log if debug mode", :unless => $debug do
263
+ it "should not log if debug mode", :unless => $debug do
263
264
  open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dummy stopped/).size.should eq 0
264
265
  end
265
266
  it "should return false if service not already running" do
266
267
  subject.stop_service({:name => 'dum'}).should eq false
267
268
  end
268
- it "should log if debug mode and service not loaded", :if => $debug do
269
+ it "should log if debug mode and service not loaded", :if => $debug do
269
270
  open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dum not loaded/).size.should >= 1
270
271
  end
271
- it "should not log if debug mode and service not loaded", :unless => $debug do
272
+ it "should not log if debug mode and service not loaded", :unless => $debug do
272
273
  open('/tmp/log.file').grep(/DEBUG -- Carioca: Service dum not loaded/).size.should eq 0
273
274
  end
274
275
  it "should return false if service :name is logger" do
@@ -283,8 +284,8 @@ describe Carioca do
283
284
 
284
285
  context "Distributed Service" do
285
286
  it "should be possible to stop a distributed service" do
286
- $dummy_dist = subject.start_service :name => 'distdummy'
287
- subject.stop_service({:name => 'distdummy'}).should be true
287
+ $dummy_dist = subject.start_service :name => 'distdummy'
288
+ subject.stop_service({:name => 'distdummy'}).should be true
288
289
  end
289
290
  it "should not exist forked daemon instance for this stopped service" do
290
291
  pid = `ps aux|grep ruby|grep -v grep |grep 'a dummy test service'|awk '{ print $2}'`
@@ -295,16 +296,16 @@ describe Carioca do
295
296
  $dummy_dist = subject.start_service :name => 'distdummy'
296
297
  end
297
298
  end
298
-
299
+
299
300
  end
300
301
 
301
302
  context "#restart_service" do
302
303
  it { should respond_to :start_service }
303
- it "should start an instance of a service like dummy_one" do
304
+ it "should start an instance of a service like dummy_one" do
304
305
  $dummy = subject.restart_service :name => 'dummy_one'
305
306
  $dummy = subject.restart_service :name => 'dummy'
306
307
  $dummy.should be_an_instance_of ExternalServices::Dummy
307
- $carioca.loaded_services.keys.should include 'dummy'
308
+ $carioca.loaded_services.keys.should include 'dummy'
308
309
  $carioca.loaded_services.keys.should include 'dummy_one'
309
310
  end
310
311
  it "should restart a service already loaded and log it" do
@@ -332,7 +333,7 @@ describe Carioca do
332
333
 
333
334
  context "#unregister_service" do
334
335
  it { should respond_to :unregister_service }
335
- it "should be possible te unregistered the configuration service" do
336
+ it "should be possible te unregistered the configuration service" do
336
337
  subject.list.keys.should include "configuration"
337
338
  subject.unregister_service :name => "configuration"
338
339
  subject.list.keys.should_not include "configuration"
@@ -343,23 +344,23 @@ describe Carioca do
343
344
  it "should raise RegistryError if trying to unregister a loaded service" do
344
345
  lambda { subject.unregister_service :name => "dummy"}.should raise_error RegistryError
345
346
  end
346
-
347
+
347
348
  end
348
349
 
349
350
  context "#discover_builtins" do
350
351
  it { should respond_to :discover_builtins }
351
- it "should rebuild builtin service in @list" do
352
+ it "should rebuild builtin service in @list" do
352
353
  subject.discover_builtins
353
- subject.list.keys.should include "configuration"
354
+ subject.list.keys.should include "configuration"
354
355
  end
355
356
  end
356
357
 
357
358
  context "#register_service" do
358
359
  it { should respond_to :register_service }
359
- it "should add a new service" do
360
- subject.register_service :name => 'otherdummy',
361
- :type => :file,
362
- :resource => './spec/samples/otherdummy.rb',
360
+ it "should add a new service" do
361
+ subject.register_service :name => 'otherdummy',
362
+ :type => :file,
363
+ :resource => './spec/samples/otherdummy.rb',
363
364
  :service =>'ExternalServices::OtherDummy',
364
365
  :description => 'An other Dummy Service',
365
366
  :requires => ['requireddummy']
@@ -378,10 +379,10 @@ describe Carioca do
378
379
  subject.loaded_services.keys.should include 'requireddummy'
379
380
  subject.loaded_services.keys.should include 'otherdummy'
380
381
  end
381
- it "should raise Argument error if :type is not :gem, :file, :gem_file or :builtin" do
382
- lambda { subject.register_service :name => 'otherdummy',
383
- :type => :error,
384
- :resource => 'spec/samples/otherdummy.rb',
382
+ it "should raise Argument error if :type is not :gem, :file, :gem_file or :builtin" do
383
+ lambda { subject.register_service :name => 'otherdummy',
384
+ :type => :error,
385
+ :resource => 'spec/samples/otherdummy.rb',
385
386
  :service =>'ExternalServices::OtherDummy',
386
387
  :description => 'An other Dummy Service'}.should raise_error ArgumentError
387
388
 
@@ -390,11 +391,11 @@ describe Carioca do
390
391
 
391
392
 
392
393
 
393
-
394
-
394
+
395
+
395
396
  context "#save!" do
396
397
  it { should respond_to :save! }
397
- it "should save the config to an other file @registry_filename" do
398
+ it "should save the config to an other file @registry_filename" do
398
399
  File::unlink('/tmp/test.reg') if File::exist?('/tmp/test.reg')
399
400
  prev = subject.registry_filename
400
401
  subject.registry_filename = '/tmp/test.reg'
@@ -405,14 +406,14 @@ describe Carioca do
405
406
  end
406
407
 
407
408
  end
408
-
409
-
410
-
411
- context "#close" do
409
+
410
+
411
+
412
+ context "#close" do
412
413
  context "Closing the Carioca registry" do
413
414
  it { should respond_to :close }
414
415
  it "should close" do
415
- subject.close.should eq true
416
+ subject.close.should eq true
416
417
  end
417
418
  it "should log a registry closing notification if debug mode", :if => $debug do
418
419
  open('/tmp/log.file').grep(/DEBUG -- Carioca: closing Registry .../).size.should eq 1
@@ -444,7 +445,7 @@ describe Carioca do
444
445
  end
445
446
  it "should loaded services empty" do
446
447
  subject.loaded_services.empty?.should eq true
447
- end
448
+ end
448
449
  context "Distributed service" do
449
450
  end
450
451
  end
@@ -465,10 +466,3 @@ describe Carioca do
465
466
  end
466
467
 
467
468
  end
468
-
469
-
470
-
471
-
472
-
473
-
474
-