Class CloudKit::URI

  1. lib/cloudkit/uri.rb
Parent: Object

A CloudKit::URI wraps a URI string, adding methods useful for routing in CloudKit as well as caching URI components for future comparisons.

Attributes

string [R] The string form of a URI.

Public class methods

new (string)

Create a new URI with the given string.

[show source]
    # File lib/cloudkit/uri.rb, line 11
11:     def initialize(string)
12:       @string = string
13:     end

Public instance methods

cannonical_uri_string ()

Returns a cannonical URI for a given URI/URI fragment, generating it if required.

Example: URI.new('/items/123').cannoncal_uri_string => /items/123

Example: URI.new('/items').cannonical_uri_string => /items/some-new-uuid
[show source]
    # File lib/cloudkit/uri.rb, line 78
78:     def cannonical_uri_string
79:       @cannonical_uri_string ||= if resource_collection_uri?
80:         "#{@string}/#{UUID.generate}"
81:       elsif resource_uri?
82:         @string
83:       else
84:         raise CloudKit::InvalidURIFormat
85:       end
86:     end
collection_type ()

Return the resource collection referenced by a URI.

Example: URI.new('/foos/123').collection_type => :foos
[show source]
    # File lib/cloudkit/uri.rb, line 28
28:     def collection_type
29:       components[0].to_sym rescue nil
30:     end
collection_uri_fragment ()

Return the resource collection URI fragment.

Example: URI.new('/foos/123').collection_uri_fragment => '/foos
[show source]
    # File lib/cloudkit/uri.rb, line 17
17:     def collection_uri_fragment
18:       "/#{components[0]}" rescue nil
19:     end
components ()

Splits a URI into its components

[show source]
    # File lib/cloudkit/uri.rb, line 22
22:     def components
23:       @components ||= @string.split('/').reject{|x| x == '' || x == nil} rescue []
24:     end
current_resource_uri ()

Return the URI for the current version of a resource.

Example: URI.new('/foos/123/versions/abc').current_resource_uri => '/foos/123'
[show source]
    # File lib/cloudkit/uri.rb, line 34
34:     def current_resource_uri
35:       "/#{components[0..1].join('/')}" rescue nil
36:     end
meta_uri? ()

Returns true if URI matches /cloudkit-meta

[show source]
    # File lib/cloudkit/uri.rb, line 39
39:     def meta_uri?
40:       return components.size == 1 && components[0] == 'cloudkit-meta'
41:     end
resolved_resource_collection_uri? ()

Returns true if URI matches /{collection}/_resolved

[show source]
    # File lib/cloudkit/uri.rb, line 49
49:     def resolved_resource_collection_uri?
50:       return components.size == 2 && components[1] == '_resolved'
51:     end
resolved_version_collection_uri? ()

Returns true if URI matches /{collection}/{uuid}/versions/_resolved

[show source]
    # File lib/cloudkit/uri.rb, line 64
64:     def resolved_version_collection_uri?
65:       return components.size == 4 && components[2] == 'versions' && components[3] == '_resolved'
66:     end
resource_collection_uri? ()

Returns true if URI matches /{collection}

[show source]
    # File lib/cloudkit/uri.rb, line 44
44:     def resource_collection_uri?
45:       return components.size == 1 && components[0] != 'cloudkit-meta'
46:     end
resource_uri? ()

Returns true if URI matches /{collection}/{uuid}

[show source]
    # File lib/cloudkit/uri.rb, line 54
54:     def resource_uri?
55:       return components.size == 2 && components[1] != '_resolved'
56:     end
resource_version_uri? ()

Returns true if URI matches /{collection}/{uuid}/versions/{etag}

[show source]
    # File lib/cloudkit/uri.rb, line 69
69:     def resource_version_uri?
70:       return components.size == 4 && components[2] == 'versions' && components[3] != '_resolved'
71:     end
version_collection_uri? ()

Returns true if URI matches /{collection}/{uuid}/versions

[show source]
    # File lib/cloudkit/uri.rb, line 59
59:     def version_collection_uri?
60:       return components.size == 3 && components[2] == 'versions'
61:     end