Sha256: 450d5a1aaa8eec80e47aceab2b446432dc1bffd9245ef2f9f91f843fbe4902e0

Contents?: true

Size: 674 Bytes

Versions: 15

Compression:

Stored size: 674 Bytes

Contents

require 'ardm/property/string'
require 'stringex'

module Ardm
  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 Ardm

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ardm-0.4.0.ar427 lib/ardm/property/slug.rb
ardm-0.4.0 lib/ardm/property/slug.rb
ardm-0.3.2 lib/ardm/property/slug.rb
ardm-0.3.1 lib/ardm/property/slug.rb
ardm-0.3.0 lib/ardm/property/slug.rb
ardm-0.2.7 lib/ardm/property/slug.rb
ardm-0.2.6 lib/ardm/property/slug.rb
ardm-0.2.5 lib/ardm/property/slug.rb
ardm-0.2.4 lib/ardm/property/slug.rb
ardm-0.2.3 lib/ardm/property/slug.rb
ardm-0.2.2 lib/ardm/property/slug.rb
ardm-0.2.1 lib/ardm/property/slug.rb
ardm-0.2.0 lib/ardm/property/slug.rb
ardm-0.1.0 lib/ardm/property/slug.rb
ardm-0.0.1 lib/ardm/property/slug.rb