Class: MrMurano::EventHandler
Overview
Instance Method Summary
collapse
Methods inherited from ServiceBase
#cacheFileName, #cacheUpdateTimeFor, #cachedUpdateTimeFor, #docmp, #remove, #upload
#endPoint
Methods included from SyncUpDown
#docmp, #dodiff, #download, #localitems, #locallist, #remove, #removelocal, #status, #syncdown, #syncup, #tolocalpath, #upload
Methods included from Verbose
#debug, #error, #outf, #tabularize, #verbose, #warning
Methods included from Http
#curldebug, #delete, #get, #http, #http_reset, #isJSON, #json_opts, #post, #postf, #put, #set_def_headers, #showHttpError, #token, #workit
Constructor Details
Returns a new instance of EventHandler.
206
207
208
209
210
211
212
|
# File 'lib/MrMurano/Solution-Services.rb', line 206
def initialize
super
@uriparts << 'eventhandler'
@itemkey = :alias
@location = $cfg['location.eventhandlers']
= /--#EVENT (?<service>\S+) (?<event>\S+)/
end
|
Instance Method Details
#fetch(name) ⇒ Object
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
# File 'lib/MrMurano/Solution-Services.rb', line 251
def fetch(name)
ret = get('/'+CGI.escape(name))
if ret.nil? then
error "Fetch for #{name} returned nil; skipping"
return ''
end
= (ret[:script].lines.first or "").chomp
= "--#EVENT #{ret[:service]} #{ret[:event]}"
if block_given? then
yield + "\n" if !=
yield ret[:script]
else
res = ''
res << + "\n" if !=
res << ret[:script]
res
end
end
|
#ignoring ⇒ Object
234
235
236
|
# File 'lib/MrMurano/Solution-Services.rb', line 234
def ignoring
($cfg['eventhandler.ignoring'] or '').split
end
|
#list ⇒ Object
238
239
240
241
242
243
244
245
246
247
248
249
|
# File 'lib/MrMurano/Solution-Services.rb', line 238
def list
ret = get()
skiplist = ($cfg['eventhandler.skiplist'] or '').split
ret[:items].reject { |i|
i.has_key?(:service) and i.has_key?(:event) and
( skiplist.include? i[:service] or
skiplist.include? "#{i[:service]}.#{i[:event]}"
)
}
end
|
#mkalias(remote) ⇒ Object
214
215
216
217
218
219
220
|
# File 'lib/MrMurano/Solution-Services.rb', line 214
def mkalias(remote)
if remote.has_key? :service and remote.has_key? :event then
[$cfg['solution.id'], remote[:service], remote[:event]].join('_')
else
raise "Missing parts! #{remote.to_json}"
end
end
|
#mkname(remote) ⇒ Object
222
223
224
225
226
227
228
|
# File 'lib/MrMurano/Solution-Services.rb', line 222
def mkname(remote)
if remote.has_key? :service and remote.has_key? :event then
[remote[:service], remote[:event]].join('_')
else
raise "Missing parts! #{remote.to_json}"
end
end
|
#searchFor ⇒ Object
230
231
232
|
# File 'lib/MrMurano/Solution-Services.rb', line 230
def searchFor
($cfg['eventhandler.searchFor'] or '').split
end
|
#synckey(item) ⇒ Object
296
297
298
|
# File 'lib/MrMurano/Solution-Services.rb', line 296
def synckey(item)
"#{item[:service]}_#{item[:event]}"
end
|
#tolocalname(item, key) ⇒ Object
270
271
272
|
# File 'lib/MrMurano/Solution-Services.rb', line 270
def tolocalname(item, key)
"#{item[:name]}.lua"
end
|
#toRemoteItem(from, path) ⇒ Object
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
# File 'lib/MrMurano/Solution-Services.rb', line 274
def toRemoteItem(from, path)
path = Pathname.new(path) unless path.kind_of? Pathname
cur = nil
lineno=0
path.readlines().each do |line|
md = .match(line)
if not md.nil? then
cur = {:service=>md[:service],
:event=>md[:event],
:local_path=>path,
:line=>lineno,
:script=>line}
elsif not cur.nil? and not cur[:script].nil? then
cur[:script] << line
end
lineno += 1
end
cur[:line_end] = lineno unless cur.nil?
cur
end
|