Sha256: 30896d7ecf70797ee5a2d6960ac43cb4817587785a467ca6cc51ef156ca5db1c

Contents?: true

Size: 658 Bytes

Versions: 2

Compression:

Stored size: 658 Bytes

Contents

require 'dm-core'
require 'stringex'

module DataMapper
  class Property
    class Slug < String
      # Maximum length chosen because URI type is limited to 2000
      # characters, and a slug is a component of a URI, so it should
      # not exceed the maximum URI length either.
      length 2000

      def dump(value)
        return if value.nil?

        if value.respond_to?(:to_str)
          escape(value.to_str)
        else
          raise ArgumentError, '+value+ must be nil or respond to #to_str'
        end
      end

      def escape(string)
        string.to_url
      end
    end # class Slug
  end # class Property
end # module DataMapper

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dm-types-1.0.0.rc2 lib/dm-types/slug.rb
dm-types-1.0.0.rc1 lib/dm-types/slug.rb