Class: IRC::Server::Dispatcher::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/failirc/server/dispatcher/event.rb

Defined Under Namespace

Classes: Callback

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dispatcher, chain, thing, string) ⇒ Event

Returns a new instance of Event.



44
45
46
47
48
49
50
51
52
# File 'lib/failirc/server/dispatcher/event.rb', line 44

def initialize (dispatcher, chain, thing, string)
    @dispatcher = dispatcher
    @chain      = chain
    @thing      = thing
    @string     = string
    @types      = Event.types(dispatcher, chain, string)
    @aliases    = Event.aliases(dispatcher, chain, types)
    @callbacks  = Event.callbacks(dispatcher, chain, types)
end

Instance Attribute Details

#aliasesObject (readonly)

Returns the value of attribute aliases.



41
42
43
# File 'lib/failirc/server/dispatcher/event.rb', line 41

def aliases
  @aliases
end

#chainObject (readonly)

Returns the value of attribute chain.



41
42
43
# File 'lib/failirc/server/dispatcher/event.rb', line 41

def chain
  @chain
end

#dispatcherObject (readonly)

Returns the value of attribute dispatcher.



41
42
43
# File 'lib/failirc/server/dispatcher/event.rb', line 41

def dispatcher
  @dispatcher
end

#specialObject

Returns the value of attribute special.



42
43
44
# File 'lib/failirc/server/dispatcher/event.rb', line 42

def special
  @special
end

#stringObject (readonly)

Returns the value of attribute string.



41
42
43
# File 'lib/failirc/server/dispatcher/event.rb', line 41

def string
  @string
end

#thingObject (readonly)

Returns the value of attribute thing.



41
42
43
# File 'lib/failirc/server/dispatcher/event.rb', line 41

def thing
  @thing
end

#typesObject (readonly)

Returns the value of attribute types.



41
42
43
# File 'lib/failirc/server/dispatcher/event.rb', line 41

def types
  @types
end

Class Method Details

.aliases(dispatcher, chain, types) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/failirc/server/dispatcher/event.rb', line 80

def self.aliases (dispatcher, chain, types)
    aliases = []

    dispatcher.aliases[chain].each {|key, value|
        if types.include?(value)
            aliases.push key
        end
    }

    return aliases
end

.callbacks(dispatcher, chain, types) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/failirc/server/dispatcher/event.rb', line 92

def self.callbacks (dispatcher, chain, types)
    callbacks = []

    if chain == :pre || chain == :post || chain == :default
        callbacks.insert(-1, *dispatcher.events[chain])
    else
        types.each {|type|
            callbacks.insert(-1, *dispatcher.events[chain][type])
        }
    end

    return callbacks
end

.types(dispatcher, chain, string) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/failirc/server/dispatcher/event.rb', line 68

def self.types (dispatcher, chain, string)
    types = []

    dispatcher.events[chain].each_key {|key|
        if key.class == Regexp && key.match(string)
            types.push key
        end
    }

    return types
end

Instance Method Details

#callbacksObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/failirc/server/dispatcher/event.rb', line 54

def callbacks
    if @callbacks
        return @callbacks
    else
        tmp = Event.callbacks(@dispatcher, @chain, @type)

        if tmp
            return @callbacks = tmp
        else
            return []
        end
    end
end