activerecord-ulid 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f95a1ca6f4a8d8a906d219f5cfe27be3c0d2d8d939d901b81b0e6f316255c011
4
+ data.tar.gz: c5a04ae60b9d63fb49afda113b87be459d78d68478c4d2d11cd20c2224d00493
5
+ SHA512:
6
+ metadata.gz: 8f72ad7d083e3397ea3afa71ef7d1b8cb441b59092b1b98d9aeec9d88fb4e8c5225634e3882ae6351d83edf266be2638a300bd0b748d6063f9955d620624790e
7
+ data.tar.gz: 240bb28a734d7352d81b4d41174458abca0121d4fd6ea0aad01b7706914eff01b58847515ef2071a0c35161194f9f25247bd40d24e246c0002360a0fac11517b
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ULIDAttribute < ActiveRecord::Type::String
4
+ attr_reader :prefix,
5
+ :nullable,
6
+ :initial
7
+
8
+ def initialize(precision: nil, limit: nil, scale: nil, prefix: nil, nullable: false, initial: true)
9
+ @prefix = prefix
10
+ @initial = initial
11
+ @nullable = nullable
12
+ super()
13
+ end
14
+
15
+ def cast(value)
16
+ return value if value.present?
17
+ return if value.nil? && nullable
18
+
19
+ value = ULID.generate if value.nil? && initial
20
+ return value if value.empty?
21
+
22
+ [prefix, value].compact.join
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecordULID
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ulid/version"
4
+ require "active_record"
5
+ require "ulid"
6
+
7
+ require_relative "ulid/ulid_attribute"
8
+ ActiveRecord::Type.register(:ulid, ULIDAttribute)
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "activerecord/ulid"
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-ulid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Abdelkader Boudih
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-01-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ulid
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ''
42
+ email:
43
+ - terminale@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/activerecord-ulid.rb
49
+ - lib/activerecord/ulid.rb
50
+ - lib/activerecord/ulid/ulid_attribute.rb
51
+ - lib/activerecord/ulid/version.rb
52
+ homepage: https://github.com/seuros/activerecord-ulid
53
+ licenses:
54
+ - MIT
55
+ metadata:
56
+ homepage_uri: https://github.com/seuros/activerecord-ulid
57
+ source_code_uri: https://github.com/seuros/activerecord-ulid
58
+ changelog_uri: https://github.com/seuros/activerecord-ulid/blob/master/CHANGELOG.md
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 2.6.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.2.33
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Add ULID support to ActiveRecord
78
+ test_files: []