globalid 0.5.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81180450e9e2f9e9af9593952c70288d868e94b896d62e5f221c5e5f47e507aa
4
- data.tar.gz: 18fae57ba4c9a2d8a3815dab68e6383da1f296e23b1dcf4cab106deba1d594aa
3
+ metadata.gz: e5a7361595eea95f395b66f4a79123ad35e61b7008d256646bea775291fa9f41
4
+ data.tar.gz: a9ece75bb440f6b49b8ad623b976bc05f4f3da2151104d045d1b7305c4a8d9b2
5
5
  SHA512:
6
- metadata.gz: a61c23c62ea73d195a3674197474c464ed4af1610f5e06bdc90d28ef47d3d71208e19fbb35939e8bb5620aefad1fa6c0dcbf7640534f8aa5a4f749339f41989b
7
- data.tar.gz: e119c8418d503a19c0aacb51f214e26dbb75b5a66e8932a4d65eeaf79f852158d03759869c33c30a5b13bcde660b145d41fb39d76cf04d6f138646688a3da9e7
6
+ metadata.gz: 8290a4a79953bb92053c2f52ae847c557e7f5d4f0528124c7f1217ee4a34b5c7d42290a2584d729e0c5011c05cd1df4c9c073be49bde7d4fa13597f44a52513f
7
+ data.tar.gz: 2d9e7c573f7223406733b8be7ce1d6d764cca584bcfbb0a3f2ffb8d6f71f82970ceacf827e9c8a251975c0681b5d7d8293c1e158927dbf38f362e1337fd027ce
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GlobalID
4
+ module FixtureSet
5
+ def signed_global_id(fixture_set_name, label, column_type: :integer, **options)
6
+ identifier = identify(label, column_type)
7
+ model_name = default_fixture_model_name(fixture_set_name)
8
+ uri = URI::GID.build([GlobalID.app, model_name, identifier, {}])
9
+
10
+ SignedGlobalID.new(uri, **options)
11
+ end
12
+ end
13
+ end
@@ -37,6 +37,11 @@ class GlobalID
37
37
  require 'global_id/identification'
38
38
  send :include, GlobalID::Identification
39
39
  end
40
+
41
+ ActiveSupport.on_load(:active_record_fixture_set) do
42
+ require 'global_id/fixture_set'
43
+ send :extend, GlobalID::FixtureSet
44
+ end
40
45
  end
41
46
  end
42
47
  end
@@ -123,9 +123,6 @@ module URI
123
123
  private
124
124
  COMPONENT = [ :scheme, :app, :model_name, :model_id, :params ].freeze
125
125
 
126
- # Extracts model_name and model_id from the URI path.
127
- PATH_REGEXP = %r(\A/([^/]+)/?([^/]+)?\z)
128
-
129
126
  def check_host(host)
130
127
  validate_component(host)
131
128
  super
@@ -145,11 +142,11 @@ module URI
145
142
  end
146
143
 
147
144
  def set_model_components(path, validate = false)
148
- _, model_name, model_id = path.match(PATH_REGEXP).to_a
149
- model_id = CGI.unescape(model_id) if model_id
150
-
145
+ _, model_name, model_id = path.split('/', 3)
151
146
  validate_component(model_name) && validate_model_id(model_id, model_name) if validate
152
147
 
148
+ model_id = CGI.unescape(model_id) if model_id
149
+
153
150
  @model_name = model_name
154
151
  @model_id = model_id
155
152
  end
@@ -162,7 +159,7 @@ module URI
162
159
  end
163
160
 
164
161
  def validate_model_id(model_id, model_name)
165
- return model_id unless model_id.blank?
162
+ return model_id unless model_id.blank? || model_id.include?('/')
166
163
 
167
164
  raise MissingModelIdError, "Unable to create a Global ID for " \
168
165
  "#{model_name} without a model id."
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.5.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-02 00:00:00.000000000 Z
11
+ date: 2023-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -47,6 +47,7 @@ files:
47
47
  - MIT-LICENSE
48
48
  - README.md
49
49
  - lib/global_id.rb
50
+ - lib/global_id/fixture_set.rb
50
51
  - lib/global_id/global_id.rb
51
52
  - lib/global_id/identification.rb
52
53
  - lib/global_id/locator.rb
@@ -59,7 +60,7 @@ homepage: http://www.rubyonrails.org
59
60
  licenses:
60
61
  - MIT
61
62
  metadata: {}
62
- post_install_message:
63
+ post_install_message:
63
64
  rdoc_options: []
64
65
  require_paths:
65
66
  - lib
@@ -74,8 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  requirements: []
77
- rubygems_version: 3.2.24
78
- signing_key:
78
+ rubygems_version: 3.5.0.dev
79
+ signing_key:
79
80
  specification_version: 4
80
81
  summary: 'Refer to any model with a URI: gid://app/class/id'
81
82
  test_files: []