Module: SuckerPunch::Backgroundable::BackgroundableClassMethods

Defined in:
lib/sucker_punch/backgroundable/backgroundable.rb

Instance Method Summary collapse

Instance Method Details

#always_background(*methods) ⇒ Object

Marks methods to always be backgrounded. Takes one or more method symbols, and an optional options hash as the final argument.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sucker_punch/backgroundable/backgroundable.rb', line 33

def always_background(*methods)
  options = methods.last.is_a?(Hash) ? methods.pop : {}
  @__backgroundable_methods ||= {}

  methods.each do |method|
    method = method.to_s
    if !@__backgroundable_methods[method]
      @__backgroundable_methods[method] ||= { }
      @__backgroundable_methods[method][:options] = options
      if Util.singleton_methods_include?(self, method) ||
          Util.instance_methods_include?(self, method)
        __enable_backgrounding(method)
      end
    end
  end
end

#background(options = { }) ⇒ Object

Allows you to background any method that has not been marked as a backgrounded method via #always_background.



52
53
54
# File 'lib/sucker_punch/backgroundable/backgroundable.rb', line 52

def background(options = { })
  BackgroundProxy.new(self, options)
end

#later(seconds, options = { }) ⇒ Object

Allows you to background any method that has not been marked as a backgrounded method via #always_background. The method will not be executed immediately, but only after ‘seconds’ seconds.



59
60
61
# File 'lib/sucker_punch/backgroundable/backgroundable.rb', line 59

def later(seconds, options = { })
  BackgroundProxy.new(self, options, seconds)
end

#method_added(method) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



64
65
66
67
# File 'lib/sucker_punch/backgroundable/backgroundable.rb', line 64

def method_added(method)
  super
  __method_added(method)
end

#singleton_method_added(method) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



70
71
72
73
# File 'lib/sucker_punch/backgroundable/backgroundable.rb', line 70

def singleton_method_added(method)
  super
  __method_added(method)
end