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.
- #to_h ⇒ Object
- #to_s ⇒ Object (also: #to_param)
Methods inherited from GlobalID
create, eager_load!, find, #find, #model_class
Constructor Details
#initialize(gid, options = {}) ⇒ SignedGlobalID
Returns a new instance of SignedGlobalID.
51 52 53 54 55 56 |
# File 'lib/global_id/signed_global_id.rb', line 51 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.
23 24 25 |
# File 'lib/global_id/signed_global_id.rb', line 23 def expires_in @expires_in end |
.verifier ⇒ Object
Returns the value of attribute verifier.
9 10 11 |
# File 'lib/global_id/signed_global_id.rb', line 9 def verifier @verifier end |
Instance Attribute Details
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
49 50 51 |
# File 'lib/global_id/signed_global_id.rb', line 49 def expires_at @expires_at end |
#purpose ⇒ Object (readonly)
Returns the value of attribute purpose.
49 50 51 |
# File 'lib/global_id/signed_global_id.rb', line 49 def purpose @purpose end |
#verifier ⇒ Object (readonly)
Returns the value of attribute verifier.
49 50 51 |
# File 'lib/global_id/signed_global_id.rb', line 49 def verifier @verifier end |
Class Method Details
.parse(sgid, options = {}) ⇒ Object
11 12 13 |
# File 'lib/global_id/signed_global_id.rb', line 11 def parse(sgid, = {}) super verify(sgid.to_s, ), end |
.pick_purpose(options) ⇒ Object
27 28 29 |
# File 'lib/global_id/signed_global_id.rb', line 27 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.
17 18 19 20 21 |
# File 'lib/global_id/signed_global_id.rb', line 17 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
69 70 71 |
# File 'lib/global_id/signed_global_id.rb', line 69 def ==(other) super && @purpose == other.purpose end |
#to_h ⇒ Object
63 64 65 66 67 |
# File 'lib/global_id/signed_global_id.rb', line 63 def to_h # Some serializers decodes symbol keys to symbols, others to strings. # Using string keys remedies that. { 'gid' => @uri.to_s, 'purpose' => purpose, 'expires_at' => encoded_expiration } end |
#to_s ⇒ Object Also known as: to_param
58 59 60 |
# File 'lib/global_id/signed_global_id.rb', line 58 def to_s @sgid ||= @verifier.generate(to_h) end |