Class: Identifier::Global::Uri

Inherits:
Identifier::Global show all
Defined in:
app/models/identifier/global/uri.rb

Overview

Universal Resource Identifier

Instance Attribute Summary

Attributes inherited from Identifier::Global

#relation

Attributes inherited from Identifier

#cached, #identifier, #identifier_object_id, #namespace_id, #project_id, #type

Instance Method Summary (collapse)

Methods inherited from Identifier::Global

#permit_only_one_global_without_relation_supplied_per_type, #set_cached

Methods inherited from Identifier

find_for_autocomplete, prototype_identifier, #set_cached, #type_name

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Method Details

- (Object) using_uri_class



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/identifier/global/uri.rb', line 7

def using_uri_class
  unless identifier.nil?
    uris = URI.extract(identifier)
    if uris.count == 0
      errors.add(:identifier, 'No URI detected.')
    else
      unless (identifier.length == uris[0].length) and (uris.count == 1)
        errors.add(:identifier, 'More than a single URI present.')
      else
        begin
          uri = URI(identifier)
          scheme = uri.scheme.upcase
          unless URI_SCHEMES.include?(scheme)
            errors.add(:identifier, "#{scheme} is not in the URI schemes list.")
          end
        rescue
          errors.add(:identifier, "Badly formed URI #{identifier} detected.")
        end
      end
    end
  end
end