activerecord-obscuredid 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +11 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +115 -0
- data/Rakefile +12 -0
- data/lib/activerecord-obscuredid/base32.rb +41 -0
- data/lib/activerecord-obscuredid/configuration.rb +27 -0
- data/lib/activerecord-obscuredid/extensions/email_address.rb +44 -0
- data/lib/activerecord-obscuredid/version.rb +7 -0
- data/lib/activerecord-obscuredid.rb +63 -0
- data/sig/activerecord-obscuredid.rbs +42 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 58cb4a44828f83c6cd63d839571e3ffaa3156c374134ce603549249cec831fa9
|
4
|
+
data.tar.gz: 0b6e070feb74a02a18ba57824135da6731661c69deaaef31d08a9013ada24fe7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8a6f7862c0bad759bd8eaaad59abb7ab49d9b5fce9fedd7bde820043f2f1cfd4003641ee0ee96d640fb9ea220060885fedd14c3711ca78cfc6ac91f648099651
|
7
|
+
data.tar.gz: bcc53d8e8183357611b235df67c9819146e10ed0623ae1def5532ab7ef3f30b28cfbc8b5d6a242c744d16f8d8eeb4d3a92c02062d38d2e6459e7e6b1448923b2
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 darthrighteous
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# ActiveRecord::ObscuredId
|
2
|
+
|
3
|
+
`activerecord-obscuredid` is a gem that provides a way to encode and decode model IDs into Base32-obscured strings, making it easy to obscure the model IDs when exposing them in URLs or emails, for example.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
Install the gem and add to the application's Gemfile by executing:
|
7
|
+
|
8
|
+
```bash
|
9
|
+
$ bundle add PLACEHOLDER_GEM_NAME
|
10
|
+
```
|
11
|
+
|
12
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
13
|
+
|
14
|
+
```bash
|
15
|
+
$ gem install PLACEHOLDER_GEM_NAME
|
16
|
+
```
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
By default, the gem uses example.com as the domain for generating obscured email addresses. You can configure this to use a custom domain:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
# config/initializers/obscured_id.rb
|
24
|
+
ActiveRecord::ObscuredId.configure do |config|
|
25
|
+
config.domain = 'yourdomain.com'
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
For Rails users, the ActiveRecord::ObscuredId module is already included in ActiveRecord::Base by default, so there’s no need to include it again manually. The gem automatically extends ActiveRecord models with the obscured ID functionality.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class User < ApplicationRecord
|
35
|
+
# The module is already included, so you can use obscured_id related methods directly.
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
### Using with Non-Rails Models
|
40
|
+
|
41
|
+
If you’re not using Rails, or if your models don’t extend from ActiveRecord::Base, you can still use the ActiveRecord::ObscuredId module. To do so, include the module in your model and ensure your model has the following methods:
|
42
|
+
- An id attribute or method.
|
43
|
+
- A find method that accepts an id as an argument.
|
44
|
+
- A find_by method that accepts an id: keyword argument.
|
45
|
+
|
46
|
+
Here’s an example of a model that satisfies these requirements:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
class User
|
50
|
+
include ActiveRecord::ObscuredId
|
51
|
+
|
52
|
+
attr_accessor :id
|
53
|
+
|
54
|
+
# Method to find a record by its ID
|
55
|
+
def self.find(id)
|
56
|
+
# Implementation to find a record by its ID
|
57
|
+
end
|
58
|
+
|
59
|
+
# Method to find a record using an ID keyword argument
|
60
|
+
def self.find_by(id:)
|
61
|
+
# Implementation to find a record using a keyword argument
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
The gem provides a way to encode the ID of a record into a Base32-obscured string, as well as decode it back:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
# Generating an Obscured ID
|
70
|
+
user = User.find(7371)
|
71
|
+
user.obscured_id # => "g4ztomi" (an example Base32-encoded version of the ID)
|
72
|
+
|
73
|
+
# Find by Obscured ID
|
74
|
+
User.find_obscured('g4ztomi') # => <User id: 7371, ...>
|
75
|
+
User.find_obscured!('g4ztomi') # Raises ActiveRecord::RecordNotFound if no user is found.
|
76
|
+
|
77
|
+
# Generate an Obscured Email Address
|
78
|
+
user.obscured_email_address # => "g4ztomi@users.yourdomain.com"
|
79
|
+
|
80
|
+
# Find by Obscured Email Address
|
81
|
+
User.from_obscured_email_address("g4ztomi@users.yourdomain.com") # => <User id: 7371, ...>
|
82
|
+
```
|
83
|
+
|
84
|
+
## Development
|
85
|
+
|
86
|
+
1. Fork the repository.
|
87
|
+
2. Create a new branch for your feature or bugfix.
|
88
|
+
3. Make your changes, add tests for them.
|
89
|
+
4. Ensure the tests and linter pass
|
90
|
+
5. Open a pull request with a detailed description of your changes.
|
91
|
+
|
92
|
+
### Setting up
|
93
|
+
|
94
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
95
|
+
|
96
|
+
### Running the tests and linter
|
97
|
+
|
98
|
+
Minitest is used for unit tests. Rubocop is used to enforce the ruby style.
|
99
|
+
|
100
|
+
To run the complete set of tests and linter run the following:
|
101
|
+
|
102
|
+
```bash
|
103
|
+
$ bundle install
|
104
|
+
$ bundle exec rake test
|
105
|
+
$ bundle exec rubocop
|
106
|
+
```
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/darthrighteous/activerecord-obscuredid. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/darthrighteous/activerecord-obscuredid/blob/master/CODE_OF_CONDUCT.md).
|
111
|
+
|
112
|
+
## License
|
113
|
+
|
114
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
115
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ObscuredId
|
5
|
+
# Implementation of Base32 encoding and decoding
|
6
|
+
module Base32
|
7
|
+
module_function
|
8
|
+
|
9
|
+
BASE32_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'
|
10
|
+
|
11
|
+
def encode(input)
|
12
|
+
# Convert input to a binary string
|
13
|
+
binary = input.unpack1('B*')
|
14
|
+
|
15
|
+
# Break the binary string into 5-bit chunks and map them to Base32 characters
|
16
|
+
binary.scan(/.{1,5}/).map do |chunk|
|
17
|
+
# Pad the chunk with zeroes to make it 5 bits long if needed
|
18
|
+
chunk = chunk.ljust(5, '0')
|
19
|
+
BASE32_ALPHABET[chunk.to_i(2)]
|
20
|
+
end.join
|
21
|
+
end
|
22
|
+
|
23
|
+
def decode(base32_str)
|
24
|
+
# Convert Base32 string to binary representation
|
25
|
+
binary_str = base32_str.chars.map do |char|
|
26
|
+
# Convert each character to its 5-bit binary equivalent
|
27
|
+
index = BASE32_ALPHABET.index(char.upcase)
|
28
|
+
raise ArgumentError, "Invalid Base32 character: #{char}" if index.nil?
|
29
|
+
|
30
|
+
index.to_s(2).rjust(5, '0')
|
31
|
+
end.join
|
32
|
+
|
33
|
+
# Convert binary string back to its original form, ignoring extra zeroes
|
34
|
+
decoded_str = [binary_str].pack('B*')
|
35
|
+
|
36
|
+
# Strip out any null characters (trailing zero bits that resulted from padding)
|
37
|
+
decoded_str.delete("\x00")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
# = Active Record Obscured Id
|
5
|
+
module ObscuredId
|
6
|
+
# Holds configuration options for obscured id
|
7
|
+
class Configuration
|
8
|
+
attr_accessor :domain
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@domain = 'example.com'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_writer :config
|
17
|
+
|
18
|
+
def config
|
19
|
+
@config ||= Configuration.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def configure
|
23
|
+
yield(config)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
require 'active_support/core_ext/string/inflections' # for #pluralize, #underscore, #dasherize
|
5
|
+
require 'active_support/core_ext/string/filters' # for #remove
|
6
|
+
|
7
|
+
module ActiveRecord
|
8
|
+
module ObscuredId
|
9
|
+
module Extensions
|
10
|
+
# Extension using obscured ID to generate email addresses that can be used
|
11
|
+
# to find the record.
|
12
|
+
module EmailAddress
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
|
15
|
+
class_methods do
|
16
|
+
def from_obscured_email_address(obscured_email_address)
|
17
|
+
domain = obscured_id_email_domain
|
18
|
+
subdomain = obscured_id_email_subdomain
|
19
|
+
|
20
|
+
return nil unless obscured_email_address.match?(/@#{subdomain}.#{domain}\z/)
|
21
|
+
|
22
|
+
find_obscured(obscured_email_address.remove(/@.*\z/))
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def obscured_id_email_domain = ActiveRecord::ObscuredId.config.domain
|
28
|
+
def obscured_id_email_subdomain = name.pluralize.underscore.dasherize.downcase
|
29
|
+
end
|
30
|
+
|
31
|
+
def obscured_email_address
|
32
|
+
domain = self.class.send(:obscured_id_email_domain)
|
33
|
+
subdomain = self.class.send(:obscured_id_email_subdomain)
|
34
|
+
|
35
|
+
"#{obscured_id}@#{subdomain}.#{domain}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if Object.const_defined?('ActiveRecord::Base')
|
43
|
+
ActiveRecord::Base.include ActiveRecord::ObscuredId::Extensions::EmailAddress
|
44
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'activerecord-obscuredid/base32'
|
4
|
+
require 'activerecord-obscuredid/configuration'
|
5
|
+
require 'activerecord-obscuredid/extensions/email_address'
|
6
|
+
|
7
|
+
require 'active_support/concern'
|
8
|
+
|
9
|
+
module ActiveRecord
|
10
|
+
# = Active Record Obscured Id
|
11
|
+
module ObscuredId
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
# Class methods
|
15
|
+
module ClassMethods
|
16
|
+
# Finds a record by its obscured ID.
|
17
|
+
#
|
18
|
+
# This method decodes the given obscured ID to extract the original record ID,
|
19
|
+
# then searches for the record using the decoded ID.
|
20
|
+
#
|
21
|
+
# @param obscured_id [String] The obscured ID that represents the original record ID.
|
22
|
+
# @return [ActiveRecord::Base, nil] Returns the record if found, otherwise returns `nil`.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# user = User.find_obscured('g4ztomi') # => <User:0x0000000165a73210 id: 7371, ...>
|
26
|
+
# # Returns the user with ID 7371 corresponding to the decoded value of "g4ztomi"
|
27
|
+
def find_obscured(obscured_id)
|
28
|
+
find_by(id: decode_obscured_id(obscured_id))
|
29
|
+
end
|
30
|
+
|
31
|
+
# Same as #find_obscured but will raise +ActiveRecord::RecordNotFound+
|
32
|
+
# exception if the decoded id can't find a record.
|
33
|
+
def find_obscured!(obscured_id)
|
34
|
+
find(decode_obscured_id(obscured_id))
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def decode_obscured_id(obscured_id)
|
40
|
+
Base32.decode(obscured_id.upcase)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Generates an obscured representation of the record's ID.
|
45
|
+
#
|
46
|
+
# This method encodes the ID of the current record using a Base32 encoding
|
47
|
+
# scheme. The resulting obscured ID is a down-cased string that does not
|
48
|
+
# directly reveal the actual ID, making it suitable for public references
|
49
|
+
# (e.g., in URLs or emails). It is case-insensitive making it ideal for use
|
50
|
+
# cases like constructing email addresses or URLs, where case sensitivity
|
51
|
+
# might be an issue.
|
52
|
+
#
|
53
|
+
# @return [String] A down-cased Base32-encoded string representing the record's ID.
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
# user = User.find(7371)
|
57
|
+
# user.obscured_id
|
58
|
+
# # => "g4ztomi" (an example Base32 encoded version of the ID)
|
59
|
+
def obscured_id = Base32.encode(id.to_s).downcase
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
ActiveRecord::Base.include ActiveRecord::ObscuredId if Object.const_defined?('ActiveRecord::Base')
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ObscuredId
|
3
|
+
VERSION: String
|
4
|
+
|
5
|
+
class Configuration
|
6
|
+
attr_accessor domain: String
|
7
|
+
|
8
|
+
def initialize: () -> void
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_writer self.config: Configuration
|
12
|
+
|
13
|
+
def self.config: (Configuration) -> Configuration
|
14
|
+
def self.configure: () { (Configuration) -> void } -> void
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def find_obscured: (obscured_id: String) -> ActiveRecord::Base?
|
18
|
+
def find_obscured!: (obscured_id: String) -> ActiveRecord::Base
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def decode_obscured_id: (obscured_id: String) -> String
|
23
|
+
end
|
24
|
+
|
25
|
+
def obscured_id: () -> String
|
26
|
+
|
27
|
+
module Base32
|
28
|
+
BASE32_ALPHABET: String
|
29
|
+
|
30
|
+
def encode: (input: String) -> String
|
31
|
+
def decode: (base32_str: String) -> String
|
32
|
+
end
|
33
|
+
|
34
|
+
module Extensions
|
35
|
+
module EmailAddress
|
36
|
+
def from_obscured_email_address: (obscured_email_address: String) -> ActiveRecord::Base?
|
37
|
+
|
38
|
+
def obscured_email_address: () -> String
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-obscuredid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- darthrighteous
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.0'
|
27
|
+
description: |-
|
28
|
+
This gem provides functionality to encode and decode model IDs into Base32-obscured strings,
|
29
|
+
making it easy to obscure model IDs when exposing them in URLs or emails.
|
30
|
+
email:
|
31
|
+
- ja.ogunniyi@gmail.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- lib/activerecord-obscuredid.rb
|
43
|
+
- lib/activerecord-obscuredid/base32.rb
|
44
|
+
- lib/activerecord-obscuredid/configuration.rb
|
45
|
+
- lib/activerecord-obscuredid/extensions/email_address.rb
|
46
|
+
- lib/activerecord-obscuredid/version.rb
|
47
|
+
- sig/activerecord-obscuredid.rbs
|
48
|
+
homepage: https://github.com/darthrighteous/activerecord-obscuredid
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata:
|
52
|
+
rubygems_mfa_required: 'true'
|
53
|
+
homepage_uri: https://github.com/darthrighteous/activerecord-obscuredid
|
54
|
+
source_code_uri: https://github.com/darthrighteous/activerecord-obscuredid
|
55
|
+
changelog_uri: https://github.com/darthrighteous/activerecord-obscuredid/blob/master/CHANGELOG.md
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 3.0.0
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.5.16
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: A gem to generate obscured IDs for ActiveRecord models.
|
75
|
+
test_files: []
|