Sha256: 8bfcb8a0bfcbb2ca6d7b68a98200f6167c30a41a892a0a6c21d10ba9c42a1f55

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

# Represents a href type.
require 'uri'

module Attributor
  class URI
    include Attributor::Type

    def self.family
      String.family
    end

    def self.valid_type?(value)
      case value
      when ::String, ::URI::Generic
        true
      else
        false
      end
    end

    def self.native_type
      return ::URI::Generic
    end

    def self.example(context=nil, options={})
      URI(/[:uri:]/.gen)
    end

    def self.load(value, context=Attributor::DEFAULT_ROOT_CONTEXT, **options)
      return nil if value.nil?
      case value
      when self.native_type
        value
      when ::String
        URI(value)
      else
        raise CoercionError, context: context, from: value.class, to: self, value: value
      end
    end

    def self.validate(value,context=Attributor::DEFAULT_ROOT_CONTEXT,attribute)
      []
    end

    def check_option!(name, definition)
      # No options are supported
      :unknown
    end

  end
end

class Randgen
  def self.uri
    "http://example.com/#{word}/#{rand(10 ** 9)}"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
attributor-4.0.0 lib/attributor/types/uri.rb
attributor-3.0.1 lib/attributor/types/uri.rb
attributor-3.0 lib/attributor/types/uri.rb