Sha256: f04e43c6341e3110fec26cc30a59c99a0a6067bd6f4be900f82f458c1d9a249e

Contents?: true

Size: 610 Bytes

Versions: 3

Compression:

Stored size: 610 Bytes

Contents

require 'pathname'

module DataMapper
  module Types
    class FilePath < DataMapper::Type
      primitive String
      length    255

      def self.load(value, property)
        if value.blank?
          nil
        else
          Pathname.new(value)
        end
      end

      def self.dump(value, property)
        return nil if value.blank?
        value.to_s
      end

      def self.typecast(value, property)
        # Leave alone if a Pathname is given.
        value.kind_of?(Pathname) ? value : load(value, property)
      end
    end # class FilePath
  end # module Types
end # module DataMapper

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dm-types-0.10.2 lib/dm-types/file_path.rb
dm-types-0.10.1 lib/dm-types/file_path.rb
dm-types-0.10.0 lib/dm-types/file_path.rb