Class: EventBus::SignalSlot

Inherits:
Slot
  • Object
show all
Defined in:
lib/ls4/lib/ebus.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bus, name) ⇒ SignalSlot

Returns a new instance of SignalSlot.



81
82
83
84
85
# File 'lib/ls4/lib/ebus.rb', line 81

def initialize(bus, name)
  @bus = bus
  @name = name
  @methods = []
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



87
88
89
# File 'lib/ls4/lib/ebus.rb', line 87

def methods
  @methods
end

#nameObject (readonly)

Returns the value of attribute name.



88
89
90
# File 'lib/ls4/lib/ebus.rb', line 88

def name
  @name
end

Instance Method Details

#call(*args, &block) ⇒ Object Also known as: signal



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/ls4/lib/ebus.rb', line 103

def call(*args, &block)
  @bus.ebus_signal_log(methods, args, &block)
  methods.each {|block|
    begin
      block.call(*args, &block)
    rescue => err
      @bus.ebus_signal_error(err)
    end
  }
  nil
end

#connect(method = nil, &block) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/ls4/lib/ebus.rb', line 90

def connect(method=nil, &block)
  method ||= block
  unless @methods.include?(method)
    @methods << method
  end
  @bus
end

#disconnect!Object



98
99
100
101
# File 'lib/ls4/lib/ebus.rb', line 98

def disconnect!
  @methods.clear
  @bus
end

#to_sObject



117
118
119
120
121
122
123
124
125
126
# File 'lib/ls4/lib/ebus.rb', line 117

def to_s
  methods = @methods.map {|m|
    if s = m.inspect[/\#\<[^\:]*\:\s?(.+)\>/, 1]
      s
    else
      m.to_s
    end
  }
  "#<slot :#{@name} => [#{methods.join(',')}]>"
end