Class: DeferrableActions::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/deferrable_actions.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ Action

Returns a new instance of Action.



34
35
36
37
# File 'lib/deferrable_actions.rb', line 34

def initialize(controller)
  @controller = controller
  @action = controller.session.delete :defered_action
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



21
22
23
# File 'lib/deferrable_actions.rb', line 21

def action
  @action
end

#controllerObject (readonly)

Returns the value of attribute controller.



21
22
23
# File 'lib/deferrable_actions.rb', line 21

def controller
  @controller
end

Class Method Details

.exists?(session) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/deferrable_actions.rb', line 30

def self.exists?(session)
  !!session[:defered_action]
end

.store(session, method, args) ⇒ Object



23
24
25
26
27
28
# File 'lib/deferrable_actions.rb', line 23

def self.store(session, method, args)
  session[:defered_action] = {
    method: method,
    args: args
  }
end

Instance Method Details

#execute!Object



39
40
41
# File 'lib/deferrable_actions.rb', line 39

def execute!
  controller.send(action[:method], action[:args])
end

#on_failure_execute!Object



43
44
45
# File 'lib/deferrable_actions.rb', line 43

def on_failure_execute!
  controller.send("on_failure_#{action[:method]}", action[:args])
end