Class: Transflow::Publisher

Inherits:
Object
  • Object
show all
Includes:
Wisper::Publisher
Defined in:
lib/transflow/publisher.rb

Direct Known Subclasses

Curried

Defined Under Namespace

Classes: Curried

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/transflow/publisher.rb', line 7

def name
  @name
end

#opObject (readonly)

Returns the value of attribute op.



9
10
11
# File 'lib/transflow/publisher.rb', line 9

def op
  @op
end

Instance Method Details

#arityObject



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

#curryObject



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