Sha256: d3be573a63de54c0c0e298d728ad05d2d15895112810799757ad153ad6881ab1

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require "active_support"
require "msgpack_rails/version"

module ActiveSupport
  eager_autoload do
    autoload :MessagePack, "msgpack_rails/activesupport/message_pack"
  end
end

if defined?(ActiveModel)
  module ActiveModel
    module Serializers
      eager_autoload do
        autoload :MessagePack, "msgpack_rails/activemodel/serializers/message_pack"
      end
    end
  end
end

if defined?(::Rails)
  module MsgpackRails
    class Rails < ::Rails::Engine
      initializer "msgpack_rails" do
        if defined?(::ActiveRecord::Base)
          ::ActiveSupport.on_load(:active_record) do
            ::ActiveRecord::Base.send(:include, ActiveModel::Serializers::MessagePack)
          end
        end

        if defined?(::Mongoid::Document)
          ::ActiveSupport.on_load(:mongoid) do
            ::Mongoid::Document.send(:include, ActiveModel::Serializers::MessagePack)
          end
        end

        ::Mime::Type.register "application/msgpack", :msgpack

        ::ActionController::Renderers.add :msgpack do |data, options|
          self.content_type = Mime::MSGPACK
          self.response_body = data.as_msgpack(options)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
msgpack_rails-0.4.2 lib/msgpack_rails.rb