class Attributor::URI
Public Class Methods
check_option!(name, definition)
click to toggle source
# File lib/attributor/types/uri.rb, line 64 def self.check_option!(name, definition) case name when :path unless definition.is_a? ::Regexp raise AttributorException, "Value for option :path is not a Regexp object. Got (#{definition.inspect})" end :ok else :unknown end end
dump(value, **_opts)
click to toggle source
# File lib/attributor/types/uri.rb, line 49 def self.dump(value, **_opts) value.to_s end
example(_context = nil, options: {})
click to toggle source
# File lib/attributor/types/uri.rb, line 33 def self.example(_context = nil, options: {}) URI("https://example.com/#{Attributor::String.example}") end
family()
click to toggle source
# File lib/attributor/types/uri.rb, line 8 def self.family String.family end
json_schema_string_format()
click to toggle source
# File lib/attributor/types/uri.rb, line 29 def self.json_schema_string_format :uri end
json_schema_type()
click to toggle source
# File lib/attributor/types/uri.rb, line 25 def self.json_schema_type :string end
load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **_options)
click to toggle source
# File lib/attributor/types/uri.rb, line 37 def self.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **_options) return nil if value.nil? case value when native_type value when ::String URI(value) else raise CoercionError.new(context: context, from: value.class, to: self, value: value) end end
native_type()
click to toggle source
# File lib/attributor/types/uri.rb, line 21 def self.native_type ::URI::Generic end
valid_type?(value)
click to toggle source
# File lib/attributor/types/uri.rb, line 12 def self.valid_type?(value) case value when ::String, ::URI::Generic true else false end end
validate(value, context = Attributor::DEFAULT_ROOT_CONTEXT, attribute)
click to toggle source
# File lib/attributor/types/uri.rb, line 53 def self.validate(value, context = Attributor::DEFAULT_ROOT_CONTEXT, attribute) errors = [] if attribute && (definition = attribute.options[:path]) unless value.path =~ attribute.options[:path] errors << "#{Attributor.humanize_context(context)} value (#{value}) does not match path (#{definition.inspect})" end end errors end