Sha256: 665110234956494fc70002e2d19476e3454c4fedcd02c9eee6c8d0da3348e4a1

Contents?: true

Size: 836 Bytes

Versions: 1

Compression:

Stored size: 836 Bytes

Contents

require 'time'
module Mayu
  module Stores
    class Base
      def initialize(**options)
        @options = options
      end

      def put(obj)
        raise NotImplementedError
      end

      def get
        raise NotImplementedError
      end

      def for_json(obj)
        case obj
        when Array
          obj.map{ |_| for_json(_) }
        when Hash
          obj.transform_values { |v| v.is_a?(Time) ? v.xmlschema : for_json(v) }
        else
          obj
        end
      end

      def from_json(obj)
        case obj
        when Array
          obj.map do |v|
            from_json(v)
          end
        when Hash
          obj.map do |k,v|
            [k, k.to_s.end_with?('_at') ? (v && Time.xmlschema(v)) : from_json(v)]
          end.to_h
        else
          obj
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mayu-0.1.0.beta1 lib/mayu/stores/base.rb