langrove 0.0.4.5 → 0.0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +29 -38
- data/Gemfile +13 -7
- data/Gemfile.lock +35 -32
- data/Guardfile +11 -0
- data/README.md +34 -0
- data/Rakefile +8 -6
- data/bin/README.md +3 -0
- data/bin/langrove +1 -2
- data/langrove.gemspec +35 -0
- data/lib/langrove/README.md +82 -0
- data/lib/langrove/adaptor/README.md +92 -0
- data/lib/langrove/adaptor/adaptor_base.rb +123 -0
- data/lib/langrove/adaptor/base.rb +12 -2
- data/lib/langrove/adaptor/default.rb +8 -0
- data/lib/langrove/adaptor/event_machine_adaptor.rb +152 -0
- data/lib/langrove/adaptor/query_adaptor.rb +271 -0
- data/lib/langrove/behaviour/README.md +170 -0
- data/lib/langrove/behaviour/assessable.rb +63 -0
- data/lib/langrove/behaviour/base.rb +16 -0
- data/lib/langrove/behaviour/behaviour_base.rb +341 -0
- data/lib/langrove/behaviour/enqueueable.rb +104 -0
- data/lib/langrove/behaviour/notifiable.rb +48 -0
- data/lib/langrove/behaviour/persistable.rb +89 -0
- data/lib/langrove/behaviour/preloadable.rb +63 -0
- data/lib/langrove/daemon/README.md +7 -0
- data/lib/langrove/daemon/base.rb +9 -2
- data/lib/langrove/daemon/daemon_base.rb +330 -0
- data/lib/langrove/daemon/default.rb +3 -0
- data/lib/langrove/ext/README.md +48 -0
- data/lib/langrove/ext/class_loader.rb +9 -66
- data/lib/langrove/ext/config_item.rb +31 -23
- data/lib/langrove/ext/config_loader.rb +42 -8
- data/lib/langrove/ext/fake_config.rb +121 -0
- data/lib/langrove/ext/fake_logger.rb +50 -7
- data/lib/langrove/ext/fake_root.rb +38 -0
- data/lib/langrove/ext/hash.rb +56 -0
- data/lib/langrove/ext/i.rb +43 -0
- data/lib/langrove/ext/log_monitor.rb +272 -0
- data/lib/langrove/ext/module_loader.rb +52 -0
- data/lib/langrove/ext/recursive_string.rb +94 -0
- data/lib/langrove/ext/spec_helper.rb +84 -0
- data/lib/langrove/ext.rb +8 -2
- data/lib/langrove/handler/README.md +161 -0
- data/lib/langrove/handler/base.rb +29 -2
- data/lib/langrove/handler/default.rb +4 -0
- data/lib/langrove/handler/deferred.rb +105 -0
- data/lib/langrove/handler/handler_base.rb +242 -0
- data/lib/langrove/handler/http_servlet.rb +58 -0
- data/lib/langrove/handler/socket.rb +21 -0
- data/lib/langrove/handler/socket_base.rb +127 -0
- data/lib/langrove/handler/socket_multiplexer.rb +438 -0
- data/lib/langrove/handler/web_socket.rb +41 -0
- data/lib/langrove/plugin/README.md +76 -0
- data/lib/langrove/plugin/assessor.rb +363 -0
- data/lib/langrove/plugin/base.rb +18 -0
- data/lib/langrove/plugin/buffered_persistor.rb +97 -0
- data/lib/langrove/plugin/enqueuer.rb +186 -0
- data/lib/langrove/plugin/notifier.rb +144 -0
- data/lib/langrove/plugin/persistor.rb +360 -0
- data/lib/langrove/plugin/plugin_base.rb +79 -0
- data/lib/langrove/plugin/yaml_file.md +5 -0
- data/lib/langrove/plugin/yaml_file.rb +261 -0
- data/lib/langrove/protocol/README.md +102 -0
- data/lib/langrove/protocol/base.rb +10 -2
- data/lib/langrove/protocol/default.rb +3 -0
- data/lib/langrove/protocol/protocol_base.rb +60 -0
- data/lib/langrove/protocol/syslog.rb +34 -27
- data/lib/langrove/root/README.md +17 -0
- data/lib/langrove/root/base.rb +11 -0
- data/lib/langrove/root/config.rb +163 -0
- data/lib/langrove/root/root_base.rb +259 -0
- data/lib/langrove/server/README.md +7 -0
- data/lib/langrove/server/base.rb +9 -0
- data/lib/langrove/server/default.rb +3 -0
- data/lib/langrove/server/server_base.rb +301 -0
- data/lib/langrove/version.rb +3 -1
- data/lib/langrove.rb +44 -1
- data/spec/langrove/adaptor/adaptor_base_spec.rb +33 -0
- data/spec/langrove/adaptor/event_machine_adaptor_spec.rb +62 -0
- data/spec/langrove/adaptor/query_adaptor_spec.rb +94 -0
- data/spec/langrove/behaviour/assessable_spec.rb +42 -0
- data/spec/langrove/behaviour/behaviour_base_spec.rb +396 -0
- data/spec/langrove/behaviour/enqueueable_spec.rb +19 -0
- data/spec/langrove/behaviour/notifiable_spec.rb +6 -0
- data/spec/langrove/behaviour/persistable_spec.rb +19 -0
- data/spec/langrove/behaviour/preloadable_spec.rb +19 -0
- data/spec/langrove/daemon/base_spec.rb +6 -0
- data/spec/langrove/daemon/daemon_base_spec.rb +253 -0
- data/spec/langrove/ext/class_loader_spec.rb +9 -12
- data/spec/langrove/ext/fake_config_spec.rb +50 -0
- data/spec/langrove/ext/fake_logger_spec.rb +12 -0
- data/spec/langrove/ext/fake_root_spec.rb +19 -0
- data/spec/langrove/ext/hash_spec.rb +54 -0
- data/spec/langrove/ext/i_spec.rb +11 -0
- data/spec/langrove/ext/log_monitor_spec.rb +254 -0
- data/spec/langrove/ext/module_loader_spec.rb +70 -0
- data/spec/langrove/ext/recursive_string_spec.rb +132 -0
- data/{functional/config/environments/development.rb → spec/langrove/ext/spec_helper_spec.rb} +0 -0
- data/spec/langrove/handler/deferred_spec.rb +9 -0
- data/spec/langrove/handler/handler_base_spec.rb +134 -0
- data/spec/langrove/handler/socket_base_spec.rb +76 -0
- data/spec/langrove/handler/socket_multiplexer_spec.rb +480 -0
- data/spec/langrove/handler/socket_spec.rb +6 -0
- data/spec/langrove/handler/web_socket_spec.rb +19 -0
- data/spec/langrove/plugin/assessor_spec.rb +278 -0
- data/spec/langrove/plugin/buffered_persistor_spec.rb +94 -0
- data/spec/langrove/plugin/enqueuer_spec.rb +136 -0
- data/spec/langrove/plugin/notifier_spec.rb +107 -0
- data/spec/langrove/plugin/persistor_spec.rb +300 -0
- data/spec/langrove/plugin/plugin_base_spec.rb +86 -0
- data/spec/langrove/plugin/yaml_file_spec.rb +348 -0
- data/spec/langrove/protocol/protocol_base_spec.rb +19 -0
- data/spec/langrove/protocol/syslog_spec.rb +5 -2
- data/spec/langrove/root/config_spec.rb +103 -0
- data/spec/langrove/root/root_base_spec.rb +93 -0
- data/spec/langrove/server/server_base_spec.rb +414 -0
- data/spec/spec_helper.rb +38 -0
- metadata +157 -92
- data/.watchr +0 -27
- data/functional/config/boot.rb +0 -64
- data/functional/config/daemons.yml +0 -13
- data/functional/config/environment.rb +0 -28
- data/functional/config/environments/production.rb +0 -0
- data/functional/config/environments/test.rb +0 -0
- data/functional/lib/client/socket_to_file.rb +0 -47
- data/functional/lib/daemon/datagram.rb +0 -21
- data/functional/lib/protocol/socket_to_file.rb +0 -55
- data/functional/libexec/daemon.rb +0 -68
- data/functional/tmp/README +0 -1
- data/lib/langrove/_base.rb +0 -28
- data/lib/langrove/adaptor_base.rb +0 -116
- data/lib/langrove/client/base.rb +0 -2
- data/lib/langrove/client/datagram.rb +0 -25
- data/lib/langrove/client_base.rb +0 -92
- data/lib/langrove/daemon_base.rb +0 -281
- data/lib/langrove/ext/find.rb +0 -90
- data/lib/langrove/ext/persistable.rb +0 -103
- data/lib/langrove/handler_base.rb +0 -148
- data/lib/langrove/job/base.rb +0 -1
- data/lib/langrove/job_base.rb +0 -24
- data/lib/langrove/protocol_base.rb +0 -32
- data/spec/functional/daemon/datagram_spec.rb +0 -121
- data/spec/langrove/adaptor_base_spec.rb +0 -63
- data/spec/langrove/client/datagram_spec.rb +0 -1
- data/spec/langrove/client_base_spec.rb +0 -5
- data/spec/langrove/daemon_base_spec.rb +0 -154
- data/spec/langrove/ext/find_spec.rb +0 -53
- data/spec/langrove/ext/persistable_spec.rb +0 -117
- data/spec/langrove/handler_base_spec.rb +0 -103
- data/spec/langrove/job_base_spec.rb +0 -28
- data/spec/langrove/protocol_base_spec.rb +0 -6
- data/spec/todo_spec.rb +0 -12
- data/tmp/README +0 -2
@@ -0,0 +1,330 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
|
3
|
+
module LanGrove
|
4
|
+
|
5
|
+
class DaemonStopException < Exception
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
module LanGrove
|
12
|
+
|
13
|
+
module Daemon
|
14
|
+
|
15
|
+
class Base < LanGrove::Base
|
16
|
+
|
17
|
+
@@type = :daemon
|
18
|
+
|
19
|
+
def connect
|
20
|
+
|
21
|
+
#
|
22
|
+
# UNIMPLEMENTED (Client Daemon)
|
23
|
+
#
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def listen
|
29
|
+
|
30
|
+
@adaptor.listen(
|
31
|
+
|
32
|
+
#
|
33
|
+
# Handler and Protocol are instanciated at socket connect,
|
34
|
+
# they need the config then...
|
35
|
+
#
|
36
|
+
|
37
|
+
{ :class => @handler, :config => @my_config[ :handler ] },
|
38
|
+
|
39
|
+
{ :class => @protocol, :config => @my_config[ :protocol ] },
|
40
|
+
|
41
|
+
@server
|
42
|
+
|
43
|
+
)
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def stop_daemon
|
49
|
+
|
50
|
+
@logger.info "#{self} received stop_daemon"
|
51
|
+
|
52
|
+
@adaptor.stop_adaptor
|
53
|
+
|
54
|
+
@server.stop_server
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
def reload_daemon
|
59
|
+
|
60
|
+
@logger.info "#{self} received reload_daemon"
|
61
|
+
|
62
|
+
@adaptor.reload_adaptor
|
63
|
+
|
64
|
+
@server.reload_server
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
def schedule_behaviours
|
70
|
+
|
71
|
+
@server.schedule do |behaviour, at|
|
72
|
+
|
73
|
+
at.each do |event, event_config|
|
74
|
+
|
75
|
+
@root.schedule(
|
76
|
+
|
77
|
+
event, event_config, behaviour
|
78
|
+
|
79
|
+
) unless event == :interval
|
80
|
+
|
81
|
+
|
82
|
+
if not defined?( EventMachine )
|
83
|
+
|
84
|
+
@logger.warn( "Adaptor does not support :interval: scheduling" )
|
85
|
+
|
86
|
+
return
|
87
|
+
|
88
|
+
end if event == :interval
|
89
|
+
|
90
|
+
EM::add_periodic_timer( event_config ) do
|
91
|
+
|
92
|
+
#
|
93
|
+
# at_interval behaviours only act
|
94
|
+
# on handlers - for now
|
95
|
+
#
|
96
|
+
|
97
|
+
begin
|
98
|
+
|
99
|
+
unless behaviour.running then
|
100
|
+
|
101
|
+
#
|
102
|
+
# Behaviour mey be scheduled at a shorter
|
103
|
+
# interval than it takes to run.
|
104
|
+
#
|
105
|
+
# This protects from multiple runnings
|
106
|
+
#
|
107
|
+
|
108
|
+
behaviour.running = true
|
109
|
+
behaviour.call( @server, :handler )
|
110
|
+
behaviour.running = false
|
111
|
+
|
112
|
+
else
|
113
|
+
|
114
|
+
@logger.warn("#{behaviour} already running at interval:#{event_config}")
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
rescue Exception => err
|
119
|
+
|
120
|
+
puts err
|
121
|
+
behaviour.running = false
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end if event == :interval
|
126
|
+
|
127
|
+
end unless at.nil?
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
def run
|
135
|
+
|
136
|
+
begin
|
137
|
+
|
138
|
+
case @adaptor.type
|
139
|
+
|
140
|
+
when :not_eventmachine
|
141
|
+
|
142
|
+
start
|
143
|
+
|
144
|
+
else
|
145
|
+
|
146
|
+
EventMachine::run do
|
147
|
+
|
148
|
+
start
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
rescue LanGrove::DaemonStopException => e
|
155
|
+
|
156
|
+
stop_daemon
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
def start
|
163
|
+
|
164
|
+
schedule_behaviours unless @server.nil?
|
165
|
+
|
166
|
+
#
|
167
|
+
# TODO: The client
|
168
|
+
#
|
169
|
+
connect unless @client.nil?
|
170
|
+
|
171
|
+
listen unless @handler.nil?
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
def initialize( root, config_hash, daemon_name )
|
176
|
+
|
177
|
+
super( root )
|
178
|
+
|
179
|
+
@config = config_hash
|
180
|
+
@daemon_name = daemon_name
|
181
|
+
|
182
|
+
|
183
|
+
#
|
184
|
+
# TODO: The client
|
185
|
+
#
|
186
|
+
|
187
|
+
client = nil
|
188
|
+
@client = nil
|
189
|
+
|
190
|
+
|
191
|
+
begin
|
192
|
+
|
193
|
+
@logger.info "Starting daemon: #{@daemon_name}"
|
194
|
+
|
195
|
+
rescue
|
196
|
+
|
197
|
+
config_exception(
|
198
|
+
|
199
|
+
"Requires a logger"
|
200
|
+
|
201
|
+
)
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
begin
|
207
|
+
|
208
|
+
@my_config = @config[ :daemons ][ @daemon_name ]
|
209
|
+
|
210
|
+
root.config.system = @my_config[:system] unless @my_config[:system].nil?
|
211
|
+
|
212
|
+
root.config.application = @my_config[:application] unless @my_config[:application].nil?
|
213
|
+
|
214
|
+
raise LanGrove::DaemonConfigException.new(
|
215
|
+
|
216
|
+
'Daemon requires :system: and :application: defined.'
|
217
|
+
|
218
|
+
) if root.config.system.nil? or root.config.application.nil?
|
219
|
+
|
220
|
+
rescue
|
221
|
+
|
222
|
+
error = "Missing config for daemon: #{@daemon_name}"
|
223
|
+
|
224
|
+
@logger.error( error )
|
225
|
+
|
226
|
+
config_exception(
|
227
|
+
|
228
|
+
error
|
229
|
+
|
230
|
+
)
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
|
235
|
+
#
|
236
|
+
# Instanciate the Server module
|
237
|
+
#
|
238
|
+
# - Contains the Handler collection (of attached clients)
|
239
|
+
#
|
240
|
+
|
241
|
+
server = LanGrove::ModuleLoader.create( {
|
242
|
+
|
243
|
+
:key => :server,
|
244
|
+
:config => @my_config,
|
245
|
+
:mandatory => false,
|
246
|
+
:logger => @logger
|
247
|
+
|
248
|
+
} )
|
249
|
+
|
250
|
+
@server = server.new(
|
251
|
+
|
252
|
+
root, @config, @daemon_name
|
253
|
+
|
254
|
+
) unless server.nil?
|
255
|
+
|
256
|
+
|
257
|
+
#
|
258
|
+
# Instanciate the Adaptor module
|
259
|
+
#
|
260
|
+
# - Interface to listen()
|
261
|
+
#
|
262
|
+
adaptor = LanGrove::ModuleLoader.create( {
|
263
|
+
|
264
|
+
:key => :adaptor,
|
265
|
+
:config => @my_config,
|
266
|
+
:mandatory => true,
|
267
|
+
:logger => @logger
|
268
|
+
|
269
|
+
} )
|
270
|
+
|
271
|
+
@adaptor = adaptor.new(
|
272
|
+
|
273
|
+
root, @my_config[ :adaptor ], @daemon_name
|
274
|
+
|
275
|
+
) unless adaptor.nil?
|
276
|
+
|
277
|
+
|
278
|
+
#
|
279
|
+
# Load the Handler if present in config
|
280
|
+
#
|
281
|
+
# - Dont create instance.
|
282
|
+
#
|
283
|
+
# - These are started up on socket connect
|
284
|
+
#
|
285
|
+
# - These will each have an attached client
|
286
|
+
#
|
287
|
+
# - These will reside in the Server.@handlers
|
288
|
+
# collection.
|
289
|
+
#
|
290
|
+
@handler = LanGrove::ModuleLoader.create( {
|
291
|
+
|
292
|
+
:key => :handler,
|
293
|
+
:config => @my_config,
|
294
|
+
|
295
|
+
#
|
296
|
+
# Mandatory if @server is loaded
|
297
|
+
#
|
298
|
+
:mandatory => ( not @server.nil? ),
|
299
|
+
:logger => @logger
|
300
|
+
|
301
|
+
} )
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
#
|
306
|
+
# Laod the Protocol module
|
307
|
+
#
|
308
|
+
# - Dont create instance.
|
309
|
+
#
|
310
|
+
# - These are started up, one each, in
|
311
|
+
# the Handler, as the socket connects.
|
312
|
+
#
|
313
|
+
@protocol = LanGrove::ModuleLoader.create( {
|
314
|
+
|
315
|
+
:key => :protocol,
|
316
|
+
:config => @my_config,
|
317
|
+
:mandatory => ( not @server.nil? ),
|
318
|
+
:logger => @logger
|
319
|
+
|
320
|
+
} )
|
321
|
+
|
322
|
+
@server.start_server
|
323
|
+
|
324
|
+
end
|
325
|
+
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|
329
|
+
|
330
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
Tools and Utilities
|
2
|
+
===================
|
3
|
+
|
4
|
+
|
5
|
+
LanGrove::ClassLoader
|
6
|
+
---------------------
|
7
|
+
|
8
|
+
Used to load the contantized definition of a `class` from its `String` name in the config tree.
|
9
|
+
|
10
|
+
<pre>
|
11
|
+
|
12
|
+
mercury_definition = ClassLoader.create(
|
13
|
+
|
14
|
+
:module => 'InnerPlanet',
|
15
|
+
:class => 'Mercury'
|
16
|
+
|
17
|
+
)
|
18
|
+
|
19
|
+
mercury = mercury_definition.new
|
20
|
+
|
21
|
+
</pre>
|
22
|
+
|
23
|
+
Assuming that `lib/inner_planet/mercury.rb` exists.
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
LanGrove::ConfigLoader
|
28
|
+
----------------------
|
29
|
+
|
30
|
+
Used by the environment loader to collect and merge all `./config/*.yml` files ahead of spawing the daemon.
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
LanGrove::ModuleLoader
|
35
|
+
----------------------
|
36
|
+
|
37
|
+
Used specifically to convert branches of `config` into the `class` definitions they define.
|
38
|
+
|
39
|
+
<pre>
|
40
|
+
|
41
|
+
:handler:
|
42
|
+
:class: MyClientHandler
|
43
|
+
|
44
|
+
</pre>
|
45
|
+
|
46
|
+
Would use the ModuleLoader to load the `class` definition at `lib/handler/my_client_handler.rb` into `Handler::MyClientHandler` for later instanciation.
|
47
|
+
|
48
|
+
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'langrove/ext/string'
|
2
|
+
|
2
3
|
module LanGrove
|
3
4
|
|
4
5
|
class ClassLoaderException < Exception; end
|
@@ -7,34 +8,7 @@ module LanGrove
|
|
7
8
|
|
8
9
|
def self.create( class_config, logger = nil )
|
9
10
|
|
10
|
-
logger.info( "
|
11
|
-
|
12
|
-
#
|
13
|
-
# When <config> = {
|
14
|
-
#
|
15
|
-
# :module => 'ModuleName'
|
16
|
-
# :class => 'ClassName'
|
17
|
-
#
|
18
|
-
# }
|
19
|
-
#
|
20
|
-
# Then this will return the constantized
|
21
|
-
# definition instance of ClassName as
|
22
|
-
# loaded from the F1RST found .rb file
|
23
|
-
# according to:
|
24
|
-
#
|
25
|
-
# - lib/module_name/class_name.rb
|
26
|
-
# - langrove/module_name/class_name.rb
|
27
|
-
#
|
28
|
-
# Which then facilitates the following
|
29
|
-
# construct:
|
30
|
-
#
|
31
|
-
# planet = ClassLoader.create(
|
32
|
-
#
|
33
|
-
# :module => 'Planet',
|
34
|
-
# :class => 'Mercury'
|
35
|
-
#
|
36
|
-
# ).new( *initializer_parameters )
|
37
|
-
#
|
11
|
+
logger.info( "LOAD: #{class_config.inspect}" ) unless logger.nil?
|
38
12
|
|
39
13
|
raise ClassLoaderException.new(
|
40
14
|
|
@@ -53,33 +27,6 @@ module LanGrove
|
|
53
27
|
class_name = class_config[:class]
|
54
28
|
|
55
29
|
|
56
|
-
#
|
57
|
-
# SIGNIFICANT DECISION
|
58
|
-
#
|
59
|
-
# - Late binding to the extent of also calling
|
60
|
-
# to require the actual class.rb file could
|
61
|
-
# potentially be avoided by
|
62
|
-
#
|
63
|
-
# << using this layer in the abstraction >>
|
64
|
-
#
|
65
|
-
# to do the necessary requiring for the specific
|
66
|
-
# daemon being spawned.
|
67
|
-
#
|
68
|
-
# - Obviously there are downsides to eval...
|
69
|
-
#
|
70
|
-
# - But there are upsides to having this layer
|
71
|
-
# totally aliteral - it leaves the window open
|
72
|
-
# to the later posibility of collecting the class
|
73
|
-
# definition itself from across the network.
|
74
|
-
#
|
75
|
-
#
|
76
|
-
# Which was the cental purpose behind daemons
|
77
|
-
# by configuration in the first place.
|
78
|
-
#
|
79
|
-
# Taking latebinding to a whole new level...
|
80
|
-
#
|
81
|
-
|
82
|
-
|
83
30
|
#
|
84
31
|
# First try local implementation root
|
85
32
|
#
|
@@ -100,16 +47,6 @@ module LanGrove
|
|
100
47
|
|
101
48
|
exception = e
|
102
49
|
|
103
|
-
logger.error "Missing class definition in lib/#{location}.rb" unless logger.nil?
|
104
|
-
|
105
|
-
#rescue Exception => e
|
106
|
-
#
|
107
|
-
# #
|
108
|
-
# # Incase of more... (discovery phase)
|
109
|
-
# #
|
110
|
-
#
|
111
|
-
|
112
|
-
|
113
50
|
end
|
114
51
|
|
115
52
|
#
|
@@ -122,7 +59,11 @@ module LanGrove
|
|
122
59
|
|
123
60
|
location = "#{path}/#{module_name.underscore}/#{class_name.underscore}"
|
124
61
|
|
125
|
-
|
62
|
+
begin
|
63
|
+
|
64
|
+
eval "require '#{location}'"
|
65
|
+
|
66
|
+
rescue; end
|
126
67
|
|
127
68
|
return LanGrove.const_get( module_name ).const_get( class_name )
|
128
69
|
|
@@ -137,6 +78,8 @@ module LanGrove
|
|
137
78
|
# And not confuse the issue by raising
|
138
79
|
# "no such file 'langrove/module/class"
|
139
80
|
#
|
81
|
+
logger.error "FAIL: #{exception.message}.rb" unless logger.nil?
|
82
|
+
|
140
83
|
raise ClassLoaderException.new "#{exception.message}.rb"
|
141
84
|
|
142
85
|
end
|
@@ -1,34 +1,42 @@
|
|
1
1
|
|
2
|
-
module LanGrove
|
2
|
+
module LanGrove
|
3
3
|
|
4
|
-
|
4
|
+
class ConfigException < Exception; end
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
if mandatory != false then
|
15
|
-
# raises a config exception if the item isnt present
|
16
|
-
raise ConfigException.new("Missing config item '#{key}'") unless hash.has_key?(key)
|
17
|
-
|
18
|
-
# raises a config exception if the nested item isnt present NEITHER NOT
|
19
|
-
# raise ConfigException.new("Missing config item '#{key}'") if hash[key].empty?
|
6
|
+
end
|
7
|
+
|
8
|
+
module LanGrove
|
9
|
+
|
10
|
+
class ConfigItem
|
11
|
+
|
12
|
+
def self.get(config_hash, key_array, mandatory = true)
|
20
13
|
|
21
|
-
|
14
|
+
# raise ConfigException.new("match")
|
22
15
|
|
23
|
-
|
24
|
-
raise ConfigException.new("Missing config item '#{key}'") if hash == ""
|
16
|
+
hash = config_hash
|
25
17
|
|
18
|
+
key_array.each do |key|
|
19
|
+
|
20
|
+
if mandatory != false then
|
21
|
+
# raises a config exception if the item isnt present
|
22
|
+
raise ConfigException.new("Missing config item '#{key}'") unless hash.has_key?(key)
|
23
|
+
|
24
|
+
# raises a config exception if the nested item isnt present NEITHER NOT
|
25
|
+
# raise ConfigException.new("Missing config item '#{key}'") if hash[key].empty?
|
26
|
+
|
27
|
+
hash = hash[key]
|
28
|
+
|
29
|
+
# raises a config exception if the key isnt present BLANK NEITHER
|
30
|
+
raise ConfigException.new("Missing config item '#{key}'") if hash == ""
|
31
|
+
|
32
|
+
end
|
33
|
+
|
26
34
|
end
|
27
35
|
|
36
|
+
return hash
|
37
|
+
|
28
38
|
end
|
29
|
-
|
30
|
-
return hash
|
31
|
-
|
39
|
+
|
32
40
|
end
|
33
41
|
|
34
|
-
end
|
42
|
+
end
|
@@ -2,15 +2,49 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
module LanGrove
|
5
|
+
module LanGrove
|
6
|
+
|
7
|
+
class ConfigLoader
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
def self.load_dir( directory )
|
10
|
+
|
11
|
+
@config = {
|
12
|
+
|
13
|
+
:daemons => {}
|
14
|
+
|
15
|
+
}
|
16
|
+
|
17
|
+
Dir.glob( "#{directory}/*.yml" ) do |config_part|
|
18
|
+
|
19
|
+
self.load_yaml( config_part )
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
return @config
|
24
|
+
|
25
|
+
end
|
11
26
|
|
12
|
-
|
27
|
+
def self.load_yaml( file )
|
13
28
|
|
29
|
+
# no rescue block
|
30
|
+
# daemon fails on missing config file
|
31
|
+
|
32
|
+
yaml = YAML.load_file( file )
|
33
|
+
@config.merge!( yaml ) do |key, oldval, newval|
|
34
|
+
|
35
|
+
#
|
36
|
+
# so the :daemons: subconfigs dont overwrite
|
37
|
+
# each other
|
38
|
+
#
|
39
|
+
oldval.merge!( newval )
|
40
|
+
@config[ key ] = oldval
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
return yaml
|
45
|
+
|
46
|
+
end
|
47
|
+
|
14
48
|
end
|
15
|
-
|
16
|
-
end
|
49
|
+
|
50
|
+
end
|