typeid_rails 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.
@@ -0,0 +1,26 @@
1
+ module TypeidRails
2
+ # See the note on _IdentifiableClass: this is the surface of the including class
3
+ # that the `class_methods` block body uses.
4
+ interface _ModelOptionsClass
5
+ def typeid_rails_options: () -> Hash[Symbol, bool]
6
+ def typeid_rails_options=: (Hash[Symbol, bool] options) -> Hash[Symbol, bool]
7
+ end
8
+
9
+ module ModelOptions : Module, _ModelOptionsClass
10
+ extend ActiveSupport::Concern
11
+
12
+ KEYS: Array[Symbol]
13
+
14
+ # Merges into the inherited options and returns the result.
15
+ def typeid_options: (**bool options) -> Hash[Symbol, bool]
16
+
17
+ private
18
+
19
+ def build_typeid_type: (String prefix, ?strict: bool?, ?fuzzy: bool?) -> Type
20
+
21
+ # Generated by ActiveSupport::Concern; extended into the including class.
22
+ module ClassMethods
23
+ def typeid_options: (**bool options) -> Hash[Symbol, bool]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,12 @@
1
+ module TypeidRails
2
+ class PolymorphicType < Type
3
+ def initialize: (?strict: bool, ?fuzzy: bool?) -> void
4
+
5
+ def deserialize: (untyped value) -> String?
6
+ def cast: (untyped value) -> String?
7
+ def serialize: (untyped value) -> String?
8
+
9
+ private
10
+ def parse_or_null: (String string) -> Value?
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module TypeidRails
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ module TypeidRails
2
+ module Registry
3
+ type model = Module
4
+
5
+ self.@prefixes: Hash[String, model]
6
+ self.@models: Hash[model, String]
7
+
8
+ def self.register: (String prefix, model model) -> model
9
+ def self.all_prefixes: () -> Hash[String, model]
10
+ def self.model_for: (String prefix) -> model?
11
+ def self.prefix_for: (model model) -> String?
12
+ def self.reset!: () -> void
13
+
14
+ private
15
+ def self.name_of: (model model) -> String
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ module TypeidRails
2
+ class Type < ActiveRecord::Type::Value
3
+ attr_reader prefix: String
4
+
5
+ @strict: bool
6
+ @fuzzy: bool?
7
+
8
+ def initialize: (prefix: String, ?strict: bool, ?fuzzy: bool?) -> void
9
+
10
+ def strict?: () -> bool
11
+ def fuzzy?: () -> bool
12
+ def type: () -> Symbol
13
+ def deserialize: (untyped value) -> String?
14
+ def cast: (untyped value) -> String?
15
+ def serialize: (untyped value) -> untyped
16
+ def changed_in_place?: (untyped raw_old_value, untyped new_value) -> bool
17
+
18
+ private
19
+ def cast_string: (String string) -> String
20
+ def string_to_uuid: (String string) -> String
21
+ def parse_or_null: (String string) -> Value?
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module TypeidRails
2
+ class Value
3
+ PREFIX_FORMAT: Regexp
4
+
5
+ attr_reader uuid: String
6
+ attr_reader prefix: String
7
+ attr_reader encoded: String
8
+
9
+ def initialize: (uuid: String, prefix: String, encoded: String) -> void
10
+
11
+ def self.valid_prefix?: (untyped prefix) -> bool
12
+ def self.validate_prefix!: (untyped prefix) -> void
13
+ def self.from_uuid: (String uuid, prefix: String) -> Value
14
+ def self.generate: (prefix: String, ?version: Integer) -> Value
15
+ def self.parse: (String? string, ?expected_prefix: String?, ?fuzzy: bool) -> Value?
16
+
17
+ def to_s: () -> String
18
+ def to_uuid: () -> String
19
+ def ==: (untyped other) -> bool
20
+ def eql?: (untyped other) -> bool
21
+ def hash: () -> Integer
22
+ def inspect: () -> String
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ module TypeidRails
2
+ VERSION: String
3
+
4
+ def self.encode: (String uuid, prefix: String) -> String
5
+ def self.generate: (prefix: String, ?version: Integer) -> String
6
+ def self.parse: (String? string, ?expected_prefix: String?, ?fuzzy: bool) -> Value?
7
+ def self.to_uuid: (String? prefixed_id, ?expected_prefix: String?, ?fuzzy: bool) -> String?
8
+ def self.derive_uuid: (*String parts) -> String
9
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typeid_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sorah Fukumori
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Renders a 128-bit UUID as a TypeID, a short type-tagged string such as
13
+ "user_2n1t201rmv87aae5j4csam8000", and parses it back. Includes an ActiveRecord
14
+ attribute type and an optional deterministic SHAKE128 derivation.
15
+ email:
16
+ - sorah@ivry.jp
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/typeid_rails.rb
26
+ - lib/typeid_rails/active_record.rb
27
+ - lib/typeid_rails/association_support.rb
28
+ - lib/typeid_rails/base32.rb
29
+ - lib/typeid_rails/configuration.rb
30
+ - lib/typeid_rails/derivation.rb
31
+ - lib/typeid_rails/encoder.rb
32
+ - lib/typeid_rails/errors.rb
33
+ - lib/typeid_rails/identifiable.rb
34
+ - lib/typeid_rails/model_options.rb
35
+ - lib/typeid_rails/polymorphic_type.rb
36
+ - lib/typeid_rails/railtie.rb
37
+ - lib/typeid_rails/registry.rb
38
+ - lib/typeid_rails/type.rb
39
+ - lib/typeid_rails/value.rb
40
+ - lib/typeid_rails/version.rb
41
+ - sig/typeid_rails.rbs
42
+ - sig/typeid_rails/association_support.rbs
43
+ - sig/typeid_rails/base32.rbs
44
+ - sig/typeid_rails/configuration.rbs
45
+ - sig/typeid_rails/derivation.rbs
46
+ - sig/typeid_rails/encoder.rbs
47
+ - sig/typeid_rails/errors.rbs
48
+ - sig/typeid_rails/identifiable.rbs
49
+ - sig/typeid_rails/model_options.rbs
50
+ - sig/typeid_rails/polymorphic_type.rbs
51
+ - sig/typeid_rails/railtie.rbs
52
+ - sig/typeid_rails/registry.rbs
53
+ - sig/typeid_rails/type.rbs
54
+ - sig/typeid_rails/value.rbs
55
+ homepage: https://github.com/sorah/typeid_rails
56
+ licenses:
57
+ - MIT
58
+ metadata:
59
+ allowed_push_host: https://rubygems.org
60
+ homepage_uri: https://github.com/sorah/typeid_rails
61
+ rubygems_mfa_required: 'true'
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 3.3.0
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubygems_version: 4.0.20
77
+ specification_version: 4
78
+ summary: TypeID identifiers for UUID primary keys in Rails
79
+ test_files: []