globalid 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of globalid might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18b15edf85a6adec6677a63e25b88f7e0a603317
4
- data.tar.gz: 070999cf1c6910f232e0139d398d635184d285ef
3
+ metadata.gz: 3de819ff2f02d59893c4a4fd90539488ff7179e9
4
+ data.tar.gz: e2e16efbcff7df37e004aa3102fb4f0fafa52dfa
5
5
  SHA512:
6
- metadata.gz: 70412b970cb49cf9b7435616a1e5a7924a7c4dc11c70e5e1fb676e71441721f89d7fe39141c3817d375ccc264ef5d4c8413ea194cf5d5d1db02d0577b6595ba3
7
- data.tar.gz: 75b5e5854eb5d330201bf55c49245a2d3d735ab29a74181458a321d6d625813744246ad0c01d6c7e230eb36d91cebc4cb6291e6e297b75c27b5922370d764285
6
+ metadata.gz: 6c822d9f0ba64363ed40ecea47d85e36bd16a84c4fb171cc547dc510c886143217c58c403a5d8f8c37c259f60c34f631761c50ed005f9d7e9cfc57c3b0098ff8
7
+ data.tar.gz: 00d2640d7e991dcee6fa4f69ea2d56a1aeae047aa0505864dea88b7f2de9aa4ef0892357c53902a433846750db5899209f1d5cfa7bea6881780da909fed90384
@@ -11,24 +11,24 @@ class GlobalID
11
11
  def create(model, options = {})
12
12
  app = options.fetch :app, GlobalID.app
13
13
  raise ArgumentError, "An app is required to create a GlobalID. Pass the :app option or set the default GlobalID.app." unless app
14
- new URI("gid://#{app}/#{model.class.name}/#{model.id}")
14
+ new URI("gid://#{app}/#{model.class.name}/#{model.id}"), options
15
15
  end
16
16
 
17
17
  def find(gid, options = {})
18
18
  parse(gid).try(:find, options)
19
19
  end
20
20
 
21
- def parse(gid)
22
- gid.is_a?(self) ? gid : new(gid)
21
+ def parse(gid, options = {})
22
+ gid.is_a?(self) ? gid : new(gid, options)
23
23
  rescue URI::Error
24
- parse_encoded_gid(gid)
24
+ parse_encoded_gid(gid, options)
25
25
  end
26
26
 
27
- def parse_encoded_gid(gid)
28
- new Base64.urlsafe_decode64(repad_gid(gid)) rescue nil
29
- end
30
-
31
27
  private
28
+ def parse_encoded_gid(gid, options)
29
+ new(Base64.urlsafe_decode64(repad_gid(gid)), options) rescue nil
30
+ end
31
+
32
32
  # We removed the base64 padding character = during #to_param, now we're adding it back so decoding will work
33
33
  def repad_gid(gid)
34
34
  padding_chars = gid.length.modulo(4).zero? ? 0 : (4 - gid.length.modulo(4))
@@ -38,7 +38,7 @@ class GlobalID
38
38
 
39
39
  attr_reader :uri, :app, :model_name, :model_id
40
40
 
41
- def initialize(gid)
41
+ def initialize(gid, options = {})
42
42
  extract_uri_components gid
43
43
  end
44
44
 
@@ -16,7 +16,11 @@ class GlobalID
16
16
  GlobalID.app = app.config.global_id.app
17
17
 
18
18
  config.after_initialize do
19
- app.config.global_id.verifier ||= app.message_verifier(:signed_global_ids)
19
+ app.config.global_id.verifier ||= begin
20
+ app.message_verifier(:signed_global_ids)
21
+ rescue ArgumentError
22
+ nil
23
+ end
20
24
  SignedGlobalID.verifier = app.config.global_id.verifier
21
25
  end
22
26
 
@@ -4,16 +4,40 @@ require 'active_support/message_verifier'
4
4
  class SignedGlobalID < GlobalID
5
5
  class << self
6
6
  attr_accessor :verifier
7
+
8
+ def parse(sgid, options = {})
9
+ if sgid.is_a? self
10
+ sgid
11
+ else
12
+ super verify(sgid, pick_verifier(options))
13
+ end
14
+ end
15
+
16
+ # Grab the verifier from options and fall back to SignedGlobalID.verifier.
17
+ # Raise ArgumentError if neither is available.
18
+ def pick_verifier(options)
19
+ options.fetch :verifier do
20
+ verifier || raise(ArgumentError, 'Pass a `verifier:` option with an `ActiveSupport::MessageVerifier` instance, or set a default SignedGlobalID.verifier.')
21
+ end
22
+ end
23
+
24
+ private
25
+ def verify(sgid, verifier)
26
+ verifier.verify(sgid)
27
+ rescue ActiveSupport::MessageVerifier::InvalidSignature
28
+ nil
29
+ end
7
30
  end
8
31
 
9
- def self.parse(sgid)
10
- sgid.is_a?(self) ? sgid : super(verifier.verify(sgid))
11
- rescue ActiveSupport::MessageVerifier::InvalidSignature
12
- nil
32
+ attr_reader :verifier
33
+
34
+ def initialize(gid, options = {})
35
+ super
36
+ @verifier = self.class.pick_verifier(options)
13
37
  end
14
38
 
15
39
  def to_s
16
- @sgid ||= self.class.verifier.generate(super)
40
+ @sgid ||= @verifier.generate(super)
17
41
  end
18
42
  alias to_param to_s
19
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: globalid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-18 00:00:00.000000000 Z
11
+ date: 2014-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport