Sha256: 5e210a21368712cbfb8ef668a127c99ae3f8a448b124e42114af51e874aeb9d3

Contents?: true

Size: 686 Bytes

Versions: 5

Compression:

Stored size: 686 Bytes

Contents

module Qwirk
  module MarshalStrategy
    module JSON
      extend self

      def marshal_type
        :text
      end

      def to_sym
        :json
      end

      begin
        require 'json'
        def marshal(object)
          object.to_json
        end

        def unmarshal(msg)
          ::JSON.parse(msg)
        end

      rescue LoadError => e
        def marshal(object)
          raise 'Error: JSON marshaling specified but json gem has not been installed'
        end

        def unmarshal(msg)
          raise 'Error: JSON marshaling specified but json gem has not been installed'
        end
      end
      
      MarshalStrategy.register(self)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
qwirk-0.2.4 lib/qwirk/marshal_strategy/json.rb
qwirk-0.2.3 lib/qwirk/marshal_strategy/json.rb
qwirk-0.2.2 lib/qwirk/marshal_strategy/json.rb
qwirk-0.2.1 lib/qwirk/marshal_strategy/json.rb
qwirk-0.2.0 lib/qwirk/marshal_strategy/json.rb