Class: GlobalID
- Inherits:
-
Object
show all
- Defined in:
- lib/global_id.rb,
lib/global_id/locator.rb,
lib/global_id/global_id.rb,
lib/global_id/identification.rb
Defined Under Namespace
Modules: Identification, Locator
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(gid, options = {}) ⇒ GlobalID
Returns a new instance of GlobalID.
51
52
53
|
# File 'lib/global_id/global_id.rb', line 51
def initialize(gid, options = {})
@uri = gid.is_a?(URI::GID) ? gid : URI::GID.parse(gid)
end
|
Class Attribute Details
.app ⇒ Object
Returns the value of attribute app.
10
11
12
|
# File 'lib/global_id/global_id.rb', line 10
def app
@app
end
|
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
48
49
50
|
# File 'lib/global_id/global_id.rb', line 48
def uri
@uri
end
|
Class Method Details
.create(model, options = {}) ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/global_id/global_id.rb', line 12
def create(model, options = {})
if app = options.fetch(:app) { GlobalID.app }
params = options.except(:app, :verifier, :for)
new URI::GID.create(app, model, params), options
else
raise ArgumentError, 'An app is required to create a GlobalID. ' \
'Pass the :app option or set the default GlobalID.app.'
end
end
|
.find(gid, options = {}) ⇒ Object
22
23
24
|
# File 'lib/global_id/global_id.rb', line 22
def find(gid, options = {})
parse(gid, options).try(:find, options)
end
|
.parse(gid, options = {}) ⇒ Object
26
27
28
29
30
|
# File 'lib/global_id/global_id.rb', line 26
def parse(gid, options = {})
gid.is_a?(self) ? gid : new(gid, options)
rescue URI::Error
parse_encoded_gid(gid, options)
end
|
Instance Method Details
#==(other) ⇒ Object
63
64
65
|
# File 'lib/global_id/global_id.rb', line 63
def ==(other)
other.is_a?(GlobalID) && @uri == other.uri
end
|
#find(options = {}) ⇒ Object
55
56
57
|
# File 'lib/global_id/global_id.rb', line 55
def find(options = {})
Locator.locate self, options
end
|
#model_class ⇒ Object
59
60
61
|
# File 'lib/global_id/global_id.rb', line 59
def model_class
model_name.constantize
end
|
#to_param ⇒ Object
67
68
69
70
|
# File 'lib/global_id/global_id.rb', line 67
def to_param
Base64.urlsafe_encode64(to_s).sub(/=+$/, '')
end
|