Class: Flirt::Callback

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Callback

Returns a new instance of Callback.



12
13
14
15
16
17
18
# File 'lib/flirt/callback.rb', line 12

def initialize(opts = {})
    self.callback_name      = opts.fetch(:callback_name)
    callback_object         = opts.fetch(:object)
    self.weakref            = !!opts[:weakref]
    self.object             = weakref ? WeakRef.new(callback_object) : callback_object
    self.callback_object_id = callback_object.object_id
end

Instance Attribute Details

#callback_nameObject

Returns the value of attribute callback_name.



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

def callback_name
  @callback_name
end

#callback_object_idObject

Returns the value of attribute callback_object_id.



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

def callback_object_id
  @callback_object_id
end

#objectObject

Returns the value of attribute object.



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

def object
  @object
end

#weakrefObject

Returns the value of attribute weakref.



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

def weakref
  @weakref
end

Instance Method Details

#==(other_callback) ⇒ Object



33
34
35
36
# File 'lib/flirt/callback.rb', line 33

def ==(other_callback)
    callback_object_id == other_callback.callback_object_id &&
        callback_name == other_callback.callback_name
end

#alive?Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/flirt/callback.rb', line 27

def alive?
    return true unless weakref
    object.weakref_alive?
end

#call(event_data) ⇒ Object



21
22
23
24
# File 'lib/flirt/callback.rb', line 21

def call(event_data)
    return unless alive?
    object.send callback_name, event_data
end