Class: Volt::Task

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

Direct Known Subclasses

QueryTasks, StoreTasks, UserTasks

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LoginAsHelper

#login_as

Methods included from CollectionHelpers

#channel, #flash, #local_store, #page, #params, #store, #tasks, #url, #url_for, #url_with

Constructor Details

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

Returns a new instance of Task.



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

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

Class Method Details

.inherited(subclass) ⇒ Object



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

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

.known_handlersObject



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

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.



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

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 = Volt.current_app.cookies._user_id
  ['user_id'] = user_id unless user_id.nil?

  Volt.current_app.tasks.call(self.name, name, , *args, &block)
end

.timeout(value) ⇒ Object

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



43
44
45
# File 'lib/volt/tasks/task.rb', line 43

def self.timeout(value)
  self.__timeout = value
end

Instance Method Details

#cookiesObject



47
48
49
# File 'lib/volt/tasks/task.rb', line 47

def cookies
  @cookies ||= Model.new
end

#fetch_cookiesObject

Get the cookies that got set



52
53
54
55
56
# File 'lib/volt/tasks/task.rb', line 52

def fetch_cookies
  if @cookies
    @cookies.to_h.reject {|k,v| k == :id }
  end
end