module Daredevil::Responder::Actions

Constants

ACTIONS

Public Instance Methods

jbuilder_resource_render_options() click to toggle source
# File lib/daredevil/responder/actions.rb, line 46
def jbuilder_resource_render_options
  render_options
end
relation?() click to toggle source
# File lib/daredevil/responder/actions.rb, line 73
def relation?
  resource.is_a?(ActiveRecord::Relation)
end
render_resource() click to toggle source
# File lib/daredevil/responder/actions.rb, line 38
def render_resource
  controller.render(resource_render_options)
end
resource_class() click to toggle source
# File lib/daredevil/responder/actions.rb, line 68
def resource_class
  return resource.model if relation?
  resource.class
end
resource_render_options() click to toggle source
# File lib/daredevil/responder/actions.rb, line 42
def resource_render_options
  self.send(:"#{Daredevil.config.responder_type.to_s}_resource_render_options")
end
respond_to_create_action() click to toggle source
# File lib/daredevil/responder/actions.rb, line 13
def respond_to_create_action
  if resource.persisted? && resource.valid?
    self.status ||= :created
    render_resource
  else
    self.status ||= :conflict
    render_error
  end
end
respond_to_destroy_action() click to toggle source
# File lib/daredevil/responder/actions.rb, line 33
def respond_to_destroy_action
  self.status ||= :no_content
  controller.head(status, render_options)
end
respond_to_update_action() click to toggle source
# File lib/daredevil/responder/actions.rb, line 23
def respond_to_update_action
  if resource.valid?
    self.status ||= :ok
    render_resource
  else
    self.status ||= :conflict
    render_error
  end
end
responder_type() click to toggle source
# File lib/daredevil/responder/actions.rb, line 77
def responder_type
  supported_responders.each do |type, klass|
    return type.to_sym if defined?(klass.safe_constantize).eql?('constant')
  end
end
serializer_class() click to toggle source
# File lib/daredevil/responder/actions.rb, line 59
def serializer_class
  options[:serializer] ||=
    [
      namespace,
      "#{resource_class}Serializer"
    ].compact.join('::').safe_constantize
  options[:serializer] ||= "#{resource_class}Serializer".safe_constantize
end
serializers_resource_render_options() click to toggle source
# File lib/daredevil/responder/actions.rb, line 50
def serializers_resource_render_options
  serializer_key = relation? ? :each_serializer : :serializer

  render_options.merge(
    json: resource,
    serializer_key => serializer_class
  )
end
supported_responders() click to toggle source
# File lib/daredevil/responder/actions.rb, line 83
def supported_responders
  {
    jbuilder: 'Jbuilder',
    serializers: 'ActiveModel::Serializers',
    rabl: 'RABL'
  }
end