Class: Tobacco::Callback

Inherits:
Object
  • Object
show all
Defined in:
lib/tobacco/callback.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(writer = nil) ⇒ Callback

Returns a new instance of Callback.



10
11
12
# File 'lib/tobacco/callback.rb', line 10

def initialize(writer = nil)
  self.writer = writer
end

Instance Attribute Details

#writerObject

Returns the value of attribute writer.



3
4
5
# File 'lib/tobacco/callback.rb', line 3

def writer
  @writer
end

Class Method Details

.instance(writer = nil) ⇒ Object



5
6
7
# File 'lib/tobacco/callback.rb', line 5

def self.instance(writer = nil)
  @instance ||= new(writer)
end

Instance Method Details

#notify(name, data) ⇒ Object

Public: Notify the writer class based on callback name

passing along data which is either content or
an error object

name - symbol - the callback name

data - text or object

return - data



24
25
26
27
28
29
30
# File 'lib/tobacco/callback.rb', line 24

def notify(name, data)
  if writer.respond_to? name
    writer.send(name, data)
  else
    data
  end
end