universalid 0.0.1 → 0.1.0

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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +929 -188
  3. data/Rakefile +1 -5
  4. data/config/default.yml +12 -0
  5. data/config/example.yml +45 -0
  6. data/contrib/active_record/base_message_pack_type.rb +11 -0
  7. data/contrib/active_record/base_packer.rb +130 -0
  8. data/contrib/active_record/base_unpacker.rb +52 -0
  9. data/contrib/active_record/relation_message_pack_type.rb +16 -0
  10. data/contrib/active_record.rb +8 -0
  11. data/contrib/active_support/time_with_zone_message_pack_type.rb +14 -0
  12. data/contrib/active_support.rb +7 -0
  13. data/contrib/global_id/global_id_model.rb +24 -0
  14. data/contrib/global_id/global_id_uid_extension.rb +36 -0
  15. data/contrib/global_id/message_pack_type.rb +15 -0
  16. data/contrib/global_id.rb +7 -0
  17. data/contrib/signed_global_id/message_pack_type.rb +8 -0
  18. data/contrib/signed_global_id.rb +7 -0
  19. data/contrib/tags +75 -0
  20. data/lib/universal_id/contrib.rb +14 -0
  21. data/lib/universal_id/encoder.rb +27 -0
  22. data/lib/universal_id/message_pack_factory.rb +37 -0
  23. data/lib/universal_id/message_pack_types/ruby/composites/open_struct.rb +8 -0
  24. data/lib/universal_id/message_pack_types/ruby/composites/set.rb +9 -0
  25. data/lib/universal_id/message_pack_types/ruby/composites/struct.rb +23 -0
  26. data/lib/universal_id/message_pack_types/ruby/scalars/complex.rb +8 -0
  27. data/lib/universal_id/message_pack_types/ruby/scalars/date.rb +8 -0
  28. data/lib/universal_id/message_pack_types/ruby/scalars/date_time.rb +8 -0
  29. data/lib/universal_id/message_pack_types/ruby/scalars/range.rb +20 -0
  30. data/lib/universal_id/message_pack_types/ruby/scalars/rational.rb +8 -0
  31. data/lib/universal_id/message_pack_types/ruby/scalars/regexp.rb +15 -0
  32. data/lib/universal_id/message_pack_types/uri/uid/type.rb +8 -0
  33. data/lib/universal_id/message_pack_types.rb +26 -0
  34. data/lib/universal_id/prepack_database_options.rb +63 -0
  35. data/lib/universal_id/prepack_options.rb +74 -0
  36. data/lib/universal_id/prepacker.rb +28 -0
  37. data/lib/universal_id/refinements/array_refinement.rb +17 -0
  38. data/lib/universal_id/refinements/hash_refinement.rb +19 -0
  39. data/lib/universal_id/refinements/kernel_refinement.rb +19 -0
  40. data/lib/universal_id/refinements/open_struct_refinement.rb +12 -0
  41. data/lib/universal_id/refinements/set_refinement.rb +12 -0
  42. data/lib/universal_id/refinements.rb +9 -0
  43. data/lib/universal_id/settings.rb +82 -0
  44. data/lib/universal_id/version.rb +1 -1
  45. data/lib/universal_id.rb +23 -10
  46. data/lib/uri/uid.rb +95 -0
  47. metadata +106 -28
  48. data/lib/universal_id/active_model_serializer.rb +0 -53
  49. data/lib/universal_id/config.rb +0 -18
  50. data/lib/universal_id/errors.rb +0 -11
  51. data/lib/universal_id/portable.rb +0 -24
  52. data/lib/universal_id/portable_hash.rb +0 -85
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: universalid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Hopkins (hopsoft)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-06 00:00:00.000000000 Z
11
+ date: 2023-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activemodel
14
+ name: brotli
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.0'
19
+ version: '0.4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '6.0'
26
+ version: '0.4'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activesupport
28
+ name: msgpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '6.0'
33
+ version: '1.7'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '6.0'
40
+ version: '1.7'
41
41
  - !ruby/object:Gem::Dependency
42
- name: globalid
42
+ name: config
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.1'
47
+ version: '5.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.1'
54
+ version: '5.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: activerecord
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: globalid
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '1.1'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '1.1'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: magic_frozen_string_literal
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,20 @@ dependencies:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: model_probe
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: pry-byebug
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -151,7 +179,7 @@ dependencies:
151
179
  - !ruby/object:Gem::Version
152
180
  version: '0'
153
181
  - !ruby/object:Gem::Dependency
154
- name: rake
182
+ name: rainbow
155
183
  requirement: !ruby/object:Gem::Requirement
156
184
  requirements:
157
185
  - - ">="
@@ -165,7 +193,7 @@ dependencies:
165
193
  - !ruby/object:Gem::Version
166
194
  version: '0'
167
195
  - !ruby/object:Gem::Dependency
168
- name: sqlite3
196
+ name: rake
169
197
  requirement: !ruby/object:Gem::Requirement
170
198
  requirements:
171
199
  - - ">="
@@ -179,7 +207,7 @@ dependencies:
179
207
  - !ruby/object:Gem::Version
180
208
  version: '0'
181
209
  - !ruby/object:Gem::Dependency
182
- name: standard
210
+ name: simplecov
183
211
  requirement: !ruby/object:Gem::Requirement
184
212
  requirements:
185
213
  - - ">="
@@ -193,7 +221,7 @@ dependencies:
193
221
  - !ruby/object:Gem::Version
194
222
  version: '0'
195
223
  - !ruby/object:Gem::Dependency
196
- name: tocer
224
+ name: sqlite3
197
225
  requirement: !ruby/object:Gem::Requirement
198
226
  requirements:
199
227
  - - ">="
@@ -206,10 +234,25 @@ dependencies:
206
234
  - - ">="
207
235
  - !ruby/object:Gem::Version
208
236
  version: '0'
209
- description: 'UniversalID expands GlobalID support to objects like Array, Hash, ActiveRecord::Relation,
210
- and more.
211
-
212
- '
237
+ - !ruby/object:Gem::Dependency
238
+ name: standard
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '1.32'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '1.32'
251
+ description: |
252
+ Universal ID is a Ruby library that specializes in the serialization of Ruby objects to URL-safe strings,
253
+ employing MessagePack and Brotli for optimized encoding. It facilitates efficient data transfer and state
254
+ management across various computing processes. Designed to seamlessly integrate with Ruby applications,
255
+ it does not rely on Rails-specific dependencies, making it adaptable for diverse Ruby projects.
213
256
  email:
214
257
  - natehop@gmail.com
215
258
  executables: []
@@ -218,14 +261,50 @@ extra_rdoc_files: []
218
261
  files:
219
262
  - README.md
220
263
  - Rakefile
264
+ - config/default.yml
265
+ - config/example.yml
266
+ - contrib/active_record.rb
267
+ - contrib/active_record/base_message_pack_type.rb
268
+ - contrib/active_record/base_packer.rb
269
+ - contrib/active_record/base_unpacker.rb
270
+ - contrib/active_record/relation_message_pack_type.rb
271
+ - contrib/active_support.rb
272
+ - contrib/active_support/time_with_zone_message_pack_type.rb
273
+ - contrib/global_id.rb
274
+ - contrib/global_id/global_id_model.rb
275
+ - contrib/global_id/global_id_uid_extension.rb
276
+ - contrib/global_id/message_pack_type.rb
277
+ - contrib/signed_global_id.rb
278
+ - contrib/signed_global_id/message_pack_type.rb
279
+ - contrib/tags
221
280
  - lib/universal_id.rb
222
- - lib/universal_id/active_model_serializer.rb
223
- - lib/universal_id/config.rb
224
- - lib/universal_id/errors.rb
225
- - lib/universal_id/portable.rb
226
- - lib/universal_id/portable_hash.rb
281
+ - lib/universal_id/contrib.rb
282
+ - lib/universal_id/encoder.rb
283
+ - lib/universal_id/message_pack_factory.rb
284
+ - lib/universal_id/message_pack_types.rb
285
+ - lib/universal_id/message_pack_types/ruby/composites/open_struct.rb
286
+ - lib/universal_id/message_pack_types/ruby/composites/set.rb
287
+ - lib/universal_id/message_pack_types/ruby/composites/struct.rb
288
+ - lib/universal_id/message_pack_types/ruby/scalars/complex.rb
289
+ - lib/universal_id/message_pack_types/ruby/scalars/date.rb
290
+ - lib/universal_id/message_pack_types/ruby/scalars/date_time.rb
291
+ - lib/universal_id/message_pack_types/ruby/scalars/range.rb
292
+ - lib/universal_id/message_pack_types/ruby/scalars/rational.rb
293
+ - lib/universal_id/message_pack_types/ruby/scalars/regexp.rb
294
+ - lib/universal_id/message_pack_types/uri/uid/type.rb
295
+ - lib/universal_id/prepack_database_options.rb
296
+ - lib/universal_id/prepack_options.rb
297
+ - lib/universal_id/prepacker.rb
298
+ - lib/universal_id/refinements.rb
299
+ - lib/universal_id/refinements/array_refinement.rb
300
+ - lib/universal_id/refinements/hash_refinement.rb
301
+ - lib/universal_id/refinements/kernel_refinement.rb
302
+ - lib/universal_id/refinements/open_struct_refinement.rb
303
+ - lib/universal_id/refinements/set_refinement.rb
304
+ - lib/universal_id/settings.rb
227
305
  - lib/universal_id/version.rb
228
306
  - lib/universalid.rb
307
+ - lib/uri/uid.rb
229
308
  homepage: https://github.com/hopsoft/universalid
230
309
  licenses:
231
310
  - MIT
@@ -241,16 +320,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
241
320
  requirements:
242
321
  - - ">="
243
322
  - !ruby/object:Gem::Version
244
- version: 2.7.5
323
+ version: '3.0'
245
324
  required_rubygems_version: !ruby/object:Gem::Requirement
246
325
  requirements:
247
326
  - - ">="
248
327
  - !ruby/object:Gem::Version
249
328
  version: '0'
250
329
  requirements: []
251
- rubygems_version: 3.3.21
330
+ rubygems_version: 3.2.32
252
331
  signing_key:
253
332
  specification_version: 4
254
- summary: GlobalID for for Arrays, Hashes, and objects like ActiveRecord::Relation,
255
- etc.
333
+ summary: URL-Safe String Serialization for any Ruby Object
256
334
  test_files: []
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module UniversalID::ActiveModelSerializer
4
- extend ActiveSupport::Concern
5
- include ActiveModel::Serializers::JSON
6
-
7
- class_methods do
8
- def new_from_portable_hash(value, options = {})
9
- hash = if value.is_a?(UniversalID::PortableHash)
10
- value
11
- else
12
- gid = UniversalID::PortableHash.parse_gid(value.to_s, options)
13
- gid&.find || {portable_hash_error: "Invalid or expired UniversalID::PortableHash! #{value.to_s.inspect}"}
14
- end
15
- new hash
16
- rescue => error
17
- new(portable_hash_error: "Invalid or expired UniversalID::PortableHash! #{error.inspect}")
18
- end
19
- end
20
-
21
- included do
22
- validate { errors.add(:base, portable_hash_error) if portable_hash_error }
23
- end
24
-
25
- attr_accessor :portable_hash_error
26
-
27
- def to_portable_hash(options = {})
28
- portable_hash_options = options.delete(:portable_hash_options)
29
- UniversalID::PortableHash.new as_json(options).merge(portable_hash_options: portable_hash_options)
30
- end
31
-
32
- def to_portable_hash_global_id(options = {})
33
- gid_options = options.delete(:gid_options) || {}
34
- to_portable_hash(options).to_gid(gid_options)
35
- end
36
- alias_method :to_portable_hash_gid, :to_portable_hash_global_id
37
-
38
- def to_portable_hash_global_id_param(options = {})
39
- to_portable_hash_gid(options).to_param
40
- end
41
- alias_method :to_portable_hash_gid_param, :to_portable_hash_global_id_param
42
-
43
- def to_portable_hash_signed_global_id(options = {})
44
- gid_options = options.delete(:gid_options) || {}
45
- to_portable_hash(options).to_sgid(gid_options)
46
- end
47
- alias_method :to_portable_hash_sgid, :to_portable_hash_signed_global_id
48
-
49
- def to_portable_hash_signed_global_id_param(options = {})
50
- to_portable_hash_sgid(options).to_param
51
- end
52
- alias_method :to_portable_hash_sgid_param, :to_portable_hash_signed_global_id_param
53
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module UniversalID
4
- def self.config
5
- @config ||= begin
6
- options = ActiveSupport::OrderedOptions.new
7
-
8
- # Default options for UniversalID::PortableHash ........................................................
9
- options.portable_hash = {
10
- allow_blank: false,
11
- only: [], # keys to include (trumps except)
12
- except: [] # keys to exclude
13
- }
14
-
15
- options
16
- end
17
- end
18
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class UniversalID::LocatorError < StandardError
4
- attr_reader :id, :cause
5
-
6
- def initialize(id = nil, cause = nil)
7
- super "Failed to locate the id #{id.inspect} Cause: #{cause.inspect}"
8
- @id = id
9
- @cause = cause
10
- end
11
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module UniversalID::Portable
4
- extend ActiveSupport::Concern
5
- include GlobalID::Identification
6
-
7
- class_methods do
8
- def config
9
- UniversalID.config
10
- end
11
-
12
- def parse_gid(gid, options = {})
13
- GlobalID.parse(gid, options) || SignedGlobalID.parse(gid, options)
14
- end
15
-
16
- def find(id)
17
- raise NotImplementedError
18
- end
19
- end
20
-
21
- def id
22
- raise NotImplementedError
23
- end
24
- end
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class UniversalID::PortableHash < Hash
4
- include UniversalID::Portable
5
-
6
- class << self
7
- def config
8
- super.portable_hash.with_indifferent_access
9
- end
10
-
11
- def find(id)
12
- compressed_json = Base64.urlsafe_decode64(id)
13
- JSON.parse Zlib::Inflate.inflate(compressed_json)
14
- rescue => error
15
- raise UniversalID::LocatorError.new(id, error)
16
- end
17
-
18
- def deep_transform(hash, options)
19
- include_list = options[:only]
20
- exclude_list = options[:except]
21
- hash.each_with_object({}) do |(key, value), memo|
22
- key = key.to_s
23
- next if include_list.any? && incldue_list.none?(key)
24
- next if exclude_list.any?(key)
25
- transform(value, options: options) { |val| memo[key] = val }
26
- end
27
- end
28
-
29
- private
30
-
31
- def transform(value, options:)
32
- value = case value
33
- when Hash then deep_transform(value, options)
34
- when Array then value.map { |val| transform(val, options: options) }
35
- else value
36
- end
37
-
38
- if block_given?
39
- yield value if value.present? || options[:allow_blank]
40
- end
41
-
42
- value
43
- end
44
- end
45
-
46
- delegate :config, to: :"self.class"
47
- attr_reader :options
48
-
49
- def initialize(hash)
50
- @options = merge_options!(extract_options!(hash))
51
- merge! self.class.deep_transform(hash, options)
52
- end
53
-
54
- def id
55
- compressed_json = Zlib::Deflate.deflate(to_json, Zlib::BEST_COMPRESSION)
56
- Base64.urlsafe_encode64 compressed_json, padding: false
57
- end
58
-
59
- private
60
-
61
- def extract_options!(hash)
62
- options = hash.delete(:portable_hash_options) || hash.delete("portable_hash_options") || {}
63
- options = options.each_with_object({}) do |(key, val), memo|
64
- memo[key.to_sym] = val.is_a?(Array) ? val.map(&:to_s) : val
65
- end
66
- options.with_indifferent_access
67
- end
68
-
69
- def merge_options!(options)
70
- config.each do |key, val|
71
- default = config[key]
72
- custom = options[key]
73
-
74
- if default.is_a?(Array)
75
- custom = [] if custom.nil?
76
- custom = custom.is_a?(Array) ? custom : [custom]
77
- options[key] = (default + custom).uniq
78
- else
79
- options[key] = custom || default
80
- end
81
- end
82
-
83
- options
84
- end
85
- end