Sha256: d7ee4b34059c9d4e28e7315439e1e92533c9eac85598e27b0c0ae430eab0e61a

Contents?: true

Size: 772 Bytes

Versions: 5

Compression:

Stored size: 772 Bytes

Contents

# Hack to load msgpack gem first so we can overwrite its to_msgpack.

begin
  require "msgpack"
rescue LoadError
end

# The msgpack gem adds a few modules to Ruby core classes containing :to_msgpack definition, overwriting
# their default behavior. That said, we need to define the basic to_msgpack method in all of them,
# otherwise they will always use to_msgpack gem implementation.
[Object, NilClass, TrueClass, FalseClass, Fixnum, Bignum, Float, String, Array, Hash, Symbol].each do |klass|
  klass.class_eval do
    alias_method :msgpack_to_msgpack, :to_msgpack if respond_to?(:to_msgpack)
    # Dumps object in msgpack. See http://msgpack.org for more infoa
    def to_msgpack(options = nil)
      ActiveSupport::MessagePack.encode(self, options)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
msgpack_rails-0.4.2 lib/msgpack_rails/activesupport/core_ext/object/to_msgpack.rb
msgpack_rails-0.4.1 lib/msgpack_rails/activesupport/core_ext/object/to_msgpack.rb
msgpack_rails-0.4.0 lib/msgpack_rails/activesupport/core_ext/object/to_msgpack.rb
msgpack_rails-0.3.0 lib/msgpack_rails/activesupport/core_ext/object/to_msgpack.rb
msgpack_rails-0.1.0 lib/msgpack_rails/activesupport/core_ext/object/to_msgpack.rb