Module: Telegram::Bot::Async::ClassMethods

Defined in:
lib/telegram/bot/async.rb

Instance Method Summary collapse

Instance Method Details

#default_async_jobObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/telegram/bot/async.rb', line 54

def default_async_job
  @default_async_job ||= begin
    begin
      ApplicationJob
    rescue NameError
      raise 'Define ApplicationJob class or setup #async= with custom job class'
    end
    klass = Class.new(ApplicationJob) { include Job }
    klass.client_class = self
    const_set(:AsyncJob, klass)
  end
end

#default_async_job=(val) ⇒ Object

This is used in specs.



68
69
70
71
# File 'lib/telegram/bot/async.rb', line 68

def default_async_job=(val)
  @default_async_job = val
  remove_const(:AsyncJob) if const_defined?(:AsyncJob, false)
end

#prepare_async_args(*args) ⇒ Object

Prepares argments for async job. ActiveJob doesn’t support Symbol in argumens. Also we can encode json bodies only once here, so it would not be unnecessarily serialized-deserialized.

This is stub method, which returns input. Every client class must prepare args itself.



79
80
81
# File 'lib/telegram/bot/async.rb', line 79

def prepare_async_args(*args)
  args
end

#prepare_async_val(val) ⇒ Object

Returns default_async_job if ‘true` is given, treats String as a constant name, or bypasses any other values.



85
86
87
88
89
90
91
# File 'lib/telegram/bot/async.rb', line 85

def prepare_async_val(val)
  case val
  when true then default_async_job
  when String then Object.const_get(val)
  else val
  end
end