Class: ModSpox::Models::Signature

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/mod_spox/models/Signature.rb

Overview

Attributes provided by model:

signature

regex signature

params

Array of parameters to match in signature

method

method to call when matched

plugin

plugin to call when matched

description

description of trigger

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_or_create(args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mod_spox/models/Signature.rb', line 34

def Signature.find_or_create(args)
    t = nil
    if(args.has_key?(:signature) && args.has_key?(:params) && args.has_key?(:method) && args.has_key?(:plugin))
        args[:params] = [] if args[:params].nil?
        Signature.filter(:method => args[:method], :plugin => args[:plugin], :params => args[:params].join('|')).each do |s|
            t = s if s.signature == args[:signature]
        end
        args[:params] = nil if args[:params].empty?
    end
    unless(t)
        t = create(args)
    end
    t.update(:enabled => true)
    return t
end

Instance Method Details

#paramsObject



21
22
23
# File 'lib/mod_spox/models/Signature.rb', line 21

def params
    return values[:params].nil? ? [] : values[:params].split('|')
end

#params=(prms) ⇒ Object



15
16
17
18
19
# File 'lib/mod_spox/models/Signature.rb', line 15

def params=(prms)
    raise Exceptions::InvalidType.new('Parameter names must be provided in an array') unless prms.nil? || prms.kind_of?(Array)
    prms = prms.join('|') unless prms.nil?
    super(prms)
end

#signatureObject



30
31
32
# File 'lib/mod_spox/models/Signature.rb', line 30

def signature
    values[:signature] ? Marshal.load(values[:signature].unpack('m')[0]) : nil
end

#signature=(v) ⇒ Object



25
26
27
28
# File 'lib/mod_spox/models/Signature.rb', line 25

def signature=(v)
    v = [Marshal.dump(v)].pack('m')
    super(v)
end