Module: Wires::Convenience

Defined in:
lib/wires/convenience.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prefix_methods(prefix) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/wires/convenience.rb', line 35

def prefix_methods(prefix)
  
  return unless prefix
  prefix = prefix.to_s
  
  instance_methods.each do |thing|
    thing = thing.to_s
    f2 = (prefix+'_'+thing)
    f2 = (thing[0]=~/[[:lower:]]/) ? f2.underscore : f2.camelcase
    f2 = f2.to_sym; thing = thing.to_sym
    alias_method f2, thing
    remove_method thing
  end
  
  # remove_method :prefix_methods
  
end

Instance Method Details

#Channel(*args) ⇒ Object



6
# File 'lib/wires/convenience.rb', line 6

def Channel(*args) Channel.new(*args) end

#fire(event, channel = '*', **kwargs) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/wires/convenience.rb', line 16

def fire(event, channel='*', **kwargs)
  channel = Channel.new(channel) unless channel.is_a? Channel
  unless kwargs[:time] or (kwargs[:count] and kwargs[:count]!=1)
    channel.fire(event, **kwargs)
  else
    time = kwargs[:time] or Time.now
    kwargs.reject!{|k,v| k==:time}
    TimeScheduler.add(time, event, channel, **kwargs)
  end
nil end

#fire_and_wait(*args, **kwargs) ⇒ Object



27
28
29
30
# File 'lib/wires/convenience.rb', line 27

def fire_and_wait(*args, **kwargs)
  kwargs[:blocking]=true
  fire(*args, **kwargs)
end

#on(events, channels = '*', &codeblock) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/wires/convenience.rb', line 8

def on(events, channels='*', &codeblock)
  channels = [channels] unless channels.is_a? Array
  for channel in channels
    channel=Channel.new(channel) unless channel.is_a? Channel
    channel.register(events, codeblock)
  end
nil end