Class: Volt::Task

Inherits:
Object show all
Includes:
CollectionHelpers
Defined in:
lib/volt/tasks/task.rb

Direct Known Subclasses

QueryTasks, StoreTasks, UserTasks

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CollectionHelpers

#store, #url_for, #url_with

Constructor Details

#initialize(volt_app, channel = nil, dispatcher = nil) ⇒ Task

Returns a new instance of Task.



23
24
25
26
27
28
# File 'lib/volt/tasks/task.rb', line 23

def initialize(volt_app, channel = nil, dispatcher = nil)
  @volt_app   = volt_app
  @page       = volt_app.page
  @channel    = channel
  @dispatcher = dispatcher
end

Class Method Details

.inherited(subclass) ⇒ Object



30
31
32
33
# File 'lib/volt/tasks/task.rb', line 30

def self.inherited(subclass)
  @subclasses ||= []
  @subclasses << subclass
end

.known_handlersObject



35
36
37
# File 'lib/volt/tasks/task.rb', line 35

def self.known_handlers
  @subclasses ||= []
end

.method_missing(name, *args, &block) ⇒ Object

On the backend, we proxy all class methods like we would on the front-end. This returns a promise, even if the original code did not.



8
9
10
11
12
13
14
15
16
17
# File 'lib/volt/tasks/task.rb', line 8

def self.method_missing(name, *args, &block)
  # Meta data is passed from the browser to the server so the server can know
  # things like who's logged in.
   = {}

  user_id = $page.cookies._user_id
  ['user_id'] = user_id unless user_id.nil?

  $page.tasks.call(self.name, name, , *args, &block)
end

Instance Method Details

#timeout(value) ⇒ Object

Set the timeout for method calls on this task. (The default is Volt.config.worker_timeout)



41
42
43
# File 'lib/volt/tasks/task.rb', line 41

def timeout(value)
  self.__timeout = value
end