Class: Transflow::Publisher

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

Direct Known Subclasses

Curried, Monadic

Defined Under Namespace

Classes: Curried, Monadic

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, op) ⇒ Publisher

Returns a new instance of Publisher.



60
61
62
63
# File 'lib/transflow/publisher.rb', line 60

def initialize(name, op)
  @name = name
  @op = op
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#opObject (readonly)

Returns the value of attribute op.



12
13
14
# File 'lib/transflow/publisher.rb', line 12

def op
  @op
end

Class Method Details

.[](name, op, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/transflow/publisher.rb', line 14

def self.[](name, op, options = {})
  type =
    if options[:monadic]
      Monadic
    else
      self
    end
  type.new(name, op)
end

Instance Method Details

#arityObject



70
71
72
# File 'lib/transflow/publisher.rb', line 70

def arity
  op.is_a?(Proc) ? op.arity : op.method(:call).arity
end

#call(*args) ⇒ Object Also known as: []



74
75
76
77
78
79
80
# File 'lib/transflow/publisher.rb', line 74

def call(*args)
  result = op.call(*args)
  broadcast_success(result)
  result
rescue StepError => err
  broadcast_failure(*args, err) and raise(err)
end

#curryObject



65
66
67
68
# File 'lib/transflow/publisher.rb', line 65

def curry
  raise "can't curry publisher where operation arity is < 0" if arity < 0
  Curried.new(self)
end

#subscribe(listeners, *args) ⇒ Object



83
84
85
# File 'lib/transflow/publisher.rb', line 83

def subscribe(listeners, *args)
  Array(listeners).each { |listener| super(listener, *args) }
end