Class: Transflow::Publisher
- Inherits:
-
Object
- Object
- Transflow::Publisher
- Includes:
- Wisper::Publisher
- Defined in:
- lib/transflow/publisher.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Curried
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#op ⇒ Object
readonly
Returns the value of attribute op.
Instance Method Summary collapse
- #arity ⇒ Object
- #call(*args) ⇒ Object (also: #[])
- #curry ⇒ Object
-
#initialize(name, op) ⇒ Publisher
constructor
A new instance of Publisher.
Constructor Details
#initialize(name, op) ⇒ Publisher
Returns a new instance of Publisher.
39 40 41 42 |
# File 'lib/transflow/publisher.rb', line 39 def initialize(name, op) @name = name @op = op end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/transflow/publisher.rb', line 7 def name @name end |
#op ⇒ Object (readonly)
Returns the value of attribute op.
9 10 11 |
# File 'lib/transflow/publisher.rb', line 9 def op @op end |
Instance Method Details
#arity ⇒ Object
49 50 51 |
# File 'lib/transflow/publisher.rb', line 49 def arity op.is_a?(Proc) ? op.arity : op.method(:call).arity end |
#call(*args) ⇒ Object Also known as: []
53 54 55 56 57 58 59 60 |
# File 'lib/transflow/publisher.rb', line 53 def call(*args) result = op.call(*args) broadcast(:"#{name}_success", result) result rescue => err broadcast(:"#{name}_failure", *args, err) raise err end |
#curry ⇒ Object
44 45 46 47 |
# File 'lib/transflow/publisher.rb', line 44 def curry raise "can't curry publisher where operation arity is < 0" if arity < 0 Curried.new(self) end |