Sha256: 2d6ee1885da2806d84a098f5188c145a6302e76c48eeaa30bc67e988035fb95f

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

require 'active_support/concern'
require 'responders'
require 'roar-rails'

module HalApi::Controller
  extend ActiveSupport::Concern

  require 'hal_api/controller/actions'
  require 'hal_api/controller/cache'
  require 'hal_api/controller/resources'
  require 'hal_api/controller/exceptions'
  require 'hal_api/controller/sorting'
  require 'hal_api/controller/filtering'
  require 'hal_api/responders/api_responder'

  include HalApi::Controller::Actions
  include HalApi::Controller::Cache
  include HalApi::Controller::Resources
  include HalApi::Controller::Exceptions
  include HalApi::Controller::Sorting
  include HalApi::Controller::Filtering

  included do
    include Roar::Rails::ControllerAdditions

    before_action :set_accepts
    respond_to :hal, :json

    hal_rescue_standard_errors

    def self.responder
      HalApi::Responders::ApiResponder
    end
  end

  private

  def set_accepts
    mime_comparator = case HalApi::rails_major_version
                      when 5
                        Mime[:html]
                      else
                        Mime::HTML
                      end
    request.format = :json if request.format == mime_comparator
  end

  def env
    case HalApi.rails_major_version
    when 5
      request.env
    else
      super
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hal_api-rails-1.1.4 lib/hal_api/controller.rb
hal_api-rails-1.1.3 lib/hal_api/controller.rb
hal_api-rails-1.1.2 lib/hal_api/controller.rb
hal_api-rails-1.1.1 lib/hal_api/controller.rb
hal_api-rails-1.1.0 lib/hal_api/controller.rb
hal_api-rails-1.0.0 lib/hal_api/controller.rb
hal_api-rails-0.7.0 lib/hal_api/controller.rb
hal_api-rails-0.6.0 lib/hal_api/controller.rb