Module: Syndi::DSL::Base

Included in:
IRC::Server
Defined in:
lib/syndi/dsl/base.rb

Overview

A domain-specific language (DSL) wrapper mixin for simple usage of the events system, API::Events, and the timers system, API::Timers.

See Also:

  • API::Events
  • API::Timers

Author:

  • noxgirl

Since:

  • 4.0.0

Instance Method Summary collapse

Instance Method Details

#clock_do(*args) ⇒ Object

See Also:

  • API::Timers#spawn

Since:

  • 4.0.0



22
# File 'lib/syndi/dsl/base.rb', line 22

def clock_do(*args);   $m.clock.spawn(*args); end

#clock_stop(*args) ⇒ Object

See Also:

  • API::Timers#del

Since:

  • 4.0.0



24
# File 'lib/syndi/dsl/base.rb', line 24

def clock_stop(*args); $m.clock.del(*args);   end

#emit(sys, event, *args) ⇒ Object

Emit an event.

Parameters:

  • system (Symbol)

    The events system to access.

  • event (Symbol)

    The event onto which to hook.

See Also:

  • API::Events#call

Since:

  • 4.0.0



46
47
48
49
50
51
52
# File 'lib/syndi/dsl/base.rb', line 46

def emit(sys, event, *args)
  if sys == :syndi # central system
    $m.events.call(event, *args)
  else
    $m.send(sys).events.call(event, *args) if $m.respond_to? sys
  end
end

#on(sys, event, &prc) ⇒ Object

Hook onto an event.

Parameters:

  • system (Symbol)

    The events system to access.

  • event (Symbol)

    The event onto which to hook.

See Also:

  • API::Events#on

Since:

  • 4.0.0



32
33
34
35
36
37
38
# File 'lib/syndi/dsl/base.rb', line 32

def on(sys, event, &prc)
  if sys == :syndi # central system
    $m.events.on(event, prc)
  else
    $m.send(sys).events.on(event, prc) if $m.respond_to? sys
  end
end

#undo_on(sys, hook) ⇒ Object

Delete a hook.

Parameters:

  • system (Symbol)

    The events system to access.

  • hook (Array(Symbol, Integer, String))

    The identification data of the hook.

See Also:

  • API::Events#del

Since:

  • 4.0.0



60
61
62
63
64
65
66
# File 'lib/syndi/dsl/base.rb', line 60

def undo_on(sys, hook)
  if sys == :syndi # central system
    $m.events.del(hook)
  else
    $m.send(sys).events.del(hook) if $m.respond_to? sys
  end
end