Sha256: bf184c11f62df8eac77a3a4a42df67355772c3cd90420c9a405c3d6edb2aea66

Contents?: true

Size: 673 Bytes

Versions: 9

Compression:

Stored size: 673 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 typecast(value)
        if value.nil?
          nil
        elsif 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

9 entries across 9 versions & 2 rubygems

Version Path
ardm-types-1.2.3 lib/dm-types/slug.rb
ardm-types-1.2.2 lib/dm-types/slug.rb
dm-types-1.2.2 lib/dm-types/slug.rb
dm-types-1.2.1 lib/dm-types/slug.rb
dm-types-1.2.0 lib/dm-types/slug.rb
dm-types-1.2.0.rc2 lib/dm-types/slug.rb
dm-types-1.2.0.rc1 lib/dm-types/slug.rb
dm-types-1.1.0 lib/dm-types/slug.rb
dm-types-1.1.0.rc3 lib/dm-types/slug.rb