Class: TD::UpdateHandler

Inherits:
Object
  • Object
show all
Includes:
Concurrent::Async
Defined in:
lib/tdlib/update_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(update_type, extra = nil, disposable: false, &action) ⇒ UpdateHandler

Returns a new instance of UpdateHandler.



6
7
8
9
10
11
12
13
# File 'lib/tdlib/update_handler.rb', line 6

def initialize(update_type, extra = nil, disposable: false, &action)
  super()

  @action = action
  @update_type = update_type
  @extra = extra
  @disposable = disposable
end

Instance Attribute Details

#extraObject (readonly)

Returns the value of attribute extra.



4
5
6
# File 'lib/tdlib/update_handler.rb', line 4

def extra
  @extra
end

#update_typeObject (readonly)

Returns the value of attribute update_type.



4
5
6
# File 'lib/tdlib/update_handler.rb', line 4

def update_type
  @update_type
end

Instance Method Details

#disposable?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/tdlib/update_handler.rb', line 26

def disposable?
  disposable
end

#match?(update, extra = nil) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/tdlib/update_handler.rb', line 22

def match?(update, extra = nil)
  update.is_a?(update_type) && (self.extra.nil? || self.extra == extra)
end

#run(update) ⇒ Object



15
16
17
18
19
20
# File 'lib/tdlib/update_handler.rb', line 15

def run(update)
  action.call(update)
rescue StandardError => e
  warn("Uncaught exception in handler #{self}: #{e.message}")
  raise
end

#to_sObject Also known as: inspect



30
31
32
# File 'lib/tdlib/update_handler.rb', line 30

def to_s
  "TD::UpdateHandler (#{update_type}#{": #{extra}" if extra})#{' disposable' if disposable?}"
end