Class: EventBus::CallSlot

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) ⇒ CallSlot

Returns a new instance of CallSlot.



38
39
40
41
42
# File 'lib/ls4/lib/ebus.rb', line 38

def initialize(bus, name)
	@bus = bus
	@name = name
	@method = nil
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



44
45
46
# File 'lib/ls4/lib/ebus.rb', line 44

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



45
46
47
# File 'lib/ls4/lib/ebus.rb', line 45

def name
  @name
end

Instance Method Details

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



61
62
63
64
65
66
67
# File 'lib/ls4/lib/ebus.rb', line 61

def call(*args, &block)
	unless @method
		raise ::EventBus::SlotError.new("slot not connected", @name)
	end
	@bus.ebus_call_log(@method, args, &block)
	@method.call(*args, &block)
end

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



47
48
49
50
51
52
53
54
# File 'lib/ls4/lib/ebus.rb', line 47

def connect(method=nil, &block)
	if @method
		raise ::EventBus::SlotError.new("slot already connected", @name)
	end
	method ||= block
	@method = method
	@bus
end

#disconnect!Object



56
57
58
59
# File 'lib/ls4/lib/ebus.rb', line 56

def disconnect!
	@method = nil
	@bus
end

#to_sObject



71
72
73
74
75
76
77
# File 'lib/ls4/lib/ebus.rb', line 71

def to_s
	m = @method.inspect[/\#\<[^\:]*\:\s?(.+)\>/, 1]
	unless m
		m = m.to_s
	end
	"#<slot :#{@name} => #{m}>"
end