Class: SignedGlobalID
- Defined in:
- lib/global_id/signed_global_id.rb
Defined Under Namespace
Classes: ExpiredMessage
Constant Summary collapse
- DEFAULT_PURPOSE =
"default"
Class Attribute Summary collapse
-
.expires_in ⇒ Object
Returns the value of attribute expires_in.
-
.verifier ⇒ Object
Returns the value of attribute verifier.
Instance Attribute Summary collapse
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#purpose ⇒ Object
readonly
Returns the value of attribute purpose.
-
#verifier ⇒ Object
readonly
Returns the value of attribute verifier.
Attributes inherited from GlobalID
Class Method Summary collapse
- .parse(sgid, options = {}) ⇒ Object
- .pick_purpose(options) ⇒ Object
-
.pick_verifier(options) ⇒ Object
Grab the verifier from options and fall back to SignedGlobalID.verifier.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(gid, options = {}) ⇒ SignedGlobalID
constructor
A new instance of SignedGlobalID.
-
#inspect ⇒ Object
:nodoc:.
- #to_s ⇒ Object (also: #to_param)
Methods inherited from GlobalID
#as_json, create, deprecator, eager_load!, find, #find, #hash, #model_class
Constructor Details
#initialize(gid, options = {}) ⇒ SignedGlobalID
Returns a new instance of SignedGlobalID.
59 60 61 62 63 64 |
# File 'lib/global_id/signed_global_id.rb', line 59 def initialize(gid, = {}) super @verifier = self.class.pick_verifier() @purpose = self.class.pick_purpose() @expires_at = pick_expiration() end |
Class Attribute Details
.expires_in ⇒ Object
Returns the value of attribute expires_in.
8 9 10 |
# File 'lib/global_id/signed_global_id.rb', line 8 def expires_in @expires_in end |
.verifier ⇒ Object
Returns the value of attribute verifier.
8 9 10 |
# File 'lib/global_id/signed_global_id.rb', line 8 def verifier @verifier end |
Instance Attribute Details
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
57 58 59 |
# File 'lib/global_id/signed_global_id.rb', line 57 def expires_at @expires_at end |
#purpose ⇒ Object (readonly)
Returns the value of attribute purpose.
57 58 59 |
# File 'lib/global_id/signed_global_id.rb', line 57 def purpose @purpose end |
#verifier ⇒ Object (readonly)
Returns the value of attribute verifier.
57 58 59 |
# File 'lib/global_id/signed_global_id.rb', line 57 def verifier @verifier end |
Class Method Details
.parse(sgid, options = {}) ⇒ Object
10 11 12 |
# File 'lib/global_id/signed_global_id.rb', line 10 def parse(sgid, = {}) super verify(sgid.to_s, ), end |
.pick_purpose(options) ⇒ Object
24 25 26 |
# File 'lib/global_id/signed_global_id.rb', line 24 def pick_purpose() .fetch :for, DEFAULT_PURPOSE end |
.pick_verifier(options) ⇒ Object
Grab the verifier from options and fall back to SignedGlobalID.verifier. Raise ArgumentError if neither is available.
16 17 18 19 20 |
# File 'lib/global_id/signed_global_id.rb', line 16 def pick_verifier() .fetch :verifier do verifier || raise(ArgumentError, 'Pass a `verifier:` option with an `ActiveSupport::MessageVerifier` instance, or set a default SignedGlobalID.verifier.') end end |
Instance Method Details
#==(other) ⇒ Object
71 72 73 |
# File 'lib/global_id/signed_global_id.rb', line 71 def ==(other) super && @purpose == other.purpose end |
#inspect ⇒ Object
:nodoc:
75 76 77 |
# File 'lib/global_id/signed_global_id.rb', line 75 def inspect # :nodoc: "#<#{self.class.name}:#{'%#016x' % (object_id << 1)}>" end |
#to_s ⇒ Object Also known as: to_param
66 67 68 |
# File 'lib/global_id/signed_global_id.rb', line 66 def to_s @sgid ||= @verifier.generate(@uri.to_s, purpose: purpose, expires_at: expires_at) end |