Class: SweetActions::JSON::BaseAction

Inherits:
Action
  • Object
show all
Includes:
Serialize
Defined in:
lib/sweet_actions/json/base_action.rb

Instance Attribute Summary collapse

Attributes inherited from Action

#controller

Instance Method Summary collapse

Methods inherited from Action

#initialize

Constructor Details

This class inherits a constructor from SweetActions::Action

Instance Attribute Details

#response_codeObject (readonly)

Returns the value of attribute response_code.



6
7
8
# File 'lib/sweet_actions/json/base_action.rb', line 6

def response_code
  @response_code
end

#response_dataObject (readonly)

Returns the value of attribute response_data.



6
7
8
# File 'lib/sweet_actions/json/base_action.rb', line 6

def response_data
  @response_data
end

Instance Method Details

#perform_actionObject



8
9
10
11
12
13
14
15
16
# File 'lib/sweet_actions/json/base_action.rb', line 8

def perform_action
  run_action = Proc.new do
    before_action
    @response_data = action
  end

  debug_mode? ? run_action.call : fail_gracefully(run_action)
  controller.render status: response_code, json: response_data
end