Sha256: 7c68ab0f165989680526d69ca29b717d23b5b0ed175c9cc2bb27a89bf6fefa22

Contents?: true

Size: 646 Bytes

Versions: 1

Compression:

Stored size: 646 Bytes

Contents

require 'pg_hstore'

module ActiveRecord
  module Coders
    class Hstore
      def self.load(hstore)
        new.load(hstore)
      end

      def self.dump(hstore)
        new.dump(hstore)
      end

      def initialize(default=nil)
        @default=default
      end

      def dump(obj)
        obj.nil? ? (@default.nil? ? nil : to_hstore(@default)) : to_hstore(obj)
      end

      def load(hstore)
        hstore.nil? ? @default : from_hstore(hstore)
      end

      private

      def to_hstore obj
        PgHstore.dump obj, true
      end

      def from_hstore hstore
        PgHstore.load hstore, false
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-postgres-hstore-0.7.2 lib/activerecord-postgres-hstore/coder.rb