Sha256: 229d5cb739a5fcaf17e886b27d0f8ea8c8a048fe292ed5b976641d191530bb32

Contents?: true

Size: 466 Bytes

Versions: 26

Compression:

Stored size: 466 Bytes

Contents

module DataMapper
  class Property

    class ParsePointer < Object

      def dump(value)
        value && {"__type" => "Pointer", "className" => target_storage_name, "objectId" => value.to_s}
      end

      def load(value)
        value.is_a?(Hash) ? value["objectId"] : super
      end

      private
      def target_storage_name
        model.relationships.select { |r| r.child_key.include? self }.first.parent_model.storage_name
      end
    end

  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
dm-parse-0.3.0 lib/property/parse_pointer.rb
dm-parse-0.2.3 lib/property/parse_pointer.rb
dm-parse-0.2.2 lib/property/parse_pointer.rb
dm-parse-0.2.1 lib/property/parse_pointer.rb
dm-parse-0.2.0 lib/property/parse_pointer.rb
dm-parse-0.1.0 lib/property/parse_pointer.rb