Sha256: be6118c3629418c6a0b5659e3ce1ec27abcce1ae384bf7509a66af55269d7611

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

require "shamu/rack"
require "shamu/json_api"

module Shamu
  module Rails

    # Integrate Shamu with rails.
    class Railtie < ::Rails::Railtie

      rake_tasks do
        rake_path = File.expand_path( "../../tasks/*.rake" )
        Dir[ rake_path ].each { |f| load f }
      end

      initializer "shamu.configure" do
        config.shamu = ActiveSupport::OrderedOptions.new
        config.shamu.json_api = ActiveSupport::OrderedOptions.new
        config.shamu.json_api.default_url_options = {}

        if defined? ::ActionController
          ::ActionController::Base.send :include, Shamu::Rails::Controller
          ::ActionController::Base.send :include, Shamu::Rails::Entity
          ::ActionController::Base.send :include, Shamu::Rails::Features

          Mime::Type.register Shamu::JsonApi::MIME_TYPE, :json_api

          ActionController::Renderers.add :json_api do |obj, _options|
            self.content_type ||= Mime[:json_api]
            obj
          end
        end
      end

      initializer "shamu.insert_middleware" do |app|
        app.config.middleware.use "Scorpion::Rack::Middleware"
        app.config.middleware.use "Shamu::Rack::CookiesMiddleware"
        app.config.middleware.use "Shamu::Rack::QueryParamsMiddleware"
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shamu-0.0.9 lib/shamu/rails/railtie.rb
shamu-0.0.8 lib/shamu/rails/railtie.rb
shamu-0.0.7 lib/shamu/rails/railtie.rb