Class: KO::Signals::Signal
- Inherits:
-
Object
- Object
- KO::Signals::Signal
- Defined in:
- lib/ko/signals/signal.rb
Instance Attribute Summary collapse
-
#arg_types ⇒ Object
readonly
Returns the value of attribute arg_types.
-
#connections ⇒ Object
readonly
Returns the value of attribute connections.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #call ⇒ Object
- #connect(receiver = nil, mode: :direct, one_shot: false, &block) ⇒ Object
- #disconnect(receiver) ⇒ Object
- #dup ⇒ Object
- #emit(*args) ⇒ Object
-
#initialize(name, arg_types) ⇒ Signal
constructor
A new instance of Signal.
- #inspect ⇒ Object
- #receiver_name ⇒ Object
Constructor Details
Instance Attribute Details
#arg_types ⇒ Object (readonly)
Returns the value of attribute arg_types.
6 7 8 |
# File 'lib/ko/signals/signal.rb', line 6 def arg_types @arg_types end |
#connections ⇒ Object (readonly)
Returns the value of attribute connections.
6 7 8 |
# File 'lib/ko/signals/signal.rb', line 6 def connections @connections end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/ko/signals/signal.rb', line 6 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
6 7 8 |
# File 'lib/ko/signals/signal.rb', line 6 def parent @parent end |
Instance Method Details
#call ⇒ Object
49 |
# File 'lib/ko/signals/signal.rb', line 49 def call(...) = emit(...) |
#connect(receiver = nil, mode: :direct, one_shot: false, &block) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/ko/signals/signal.rb', line 27 def connect(receiver = nil, mode: :direct, one_shot: false, &block) receiver = normalize_receiver(receiver) || block @validator.validate_receiver!(receiver) raise "ALREADY CONNECTED" if @connections.include?(receiver) Connection.new(receiver, self, mode:, one_shot:).tap { @connections[receiver] = _1 } end |
#disconnect(receiver) ⇒ Object
36 37 38 39 |
# File 'lib/ko/signals/signal.rb', line 36 def disconnect(receiver) receiver = normalize_receiver(receiver) raise ArgumentError, "given receiver is not connected to this signal" if @connections.delete(receiver).nil? end |
#dup ⇒ Object
23 |
# File 'lib/ko/signals/signal.rb', line 23 def dup = self.class.new(name, arg_types) |
#emit(*args) ⇒ Object
41 42 43 44 45 |
# File 'lib/ko/signals/signal.rb', line 41 def emit(*args) @validator.validate_args!(args) notify_subscribers(args) end |
#inspect ⇒ Object
47 |
# File 'lib/ko/signals/signal.rb', line 47 def inspect = "#<#{self.class}@#{object_id}[#{name.inspect}] connections=#{@connections.count}>" |
#receiver_name ⇒ Object
25 |
# File 'lib/ko/signals/signal.rb', line 25 def receiver_name = :"on_#{name}" |