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

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

Instance Method Summary collapse

Instance Method Details

#default_async_jobObject



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/telegram/bot/async.rb', line 59

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.



73
74
75
76
# File 'lib/telegram/bot/async.rb', line 73

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.



84
85
86
# File 'lib/telegram/bot/async.rb', line 84

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.



90
91
92
93
94
95
96
# File 'lib/telegram/bot/async.rb', line 90

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