Class: MrMurano::EventHandler

Inherits:
ServiceBase show all
Defined in:
lib/MrMurano/Solution-Services.rb

Overview

…/eventhandler

Instance Method Summary collapse

Methods inherited from ServiceBase

#cacheFileName, #cacheUpdateTimeFor, #cachedUpdateTimeFor, #docmp, #remove, #upload

Methods inherited from SolutionBase

#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

#initializeEventHandler

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']
  @match_header = /--#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
  aheader = (ret[:script].lines.first or "").chomp
  dheader = "--#EVENT #{ret[:service]} #{ret[:event]}"
  if block_given? then
    yield dheader + "\n" if aheader != dheader
    yield ret[:script]
  else
    res = ''
    res << dheader + "\n" if aheader != dheader
    res << ret[:script]
    res
  end
end

#ignoringObject



234
235
236
# File 'lib/MrMurano/Solution-Services.rb', line 234

def ignoring
  ($cfg['eventhandler.ignoring'] or '').split
end

#listObject



238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/MrMurano/Solution-Services.rb', line 238

def list
  ret = get()
  # eventhandler.skiplist is a list of whitespace seperated dot-paired values.
  # fe: service.event service service service.event
  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

#searchForObject



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_header.match(line)
    if not md.nil? then
      # header line.
      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