bullet_train-obfuscates_id 1.0.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: 2d5941b63ab2c4dd139fd34d6512419db25af0e5076bdcdd5eda10d88dbeff5a
4
+ data.tar.gz: 21c8d8eeb96366a9f6cade51ae7355358e5e72a283b55413cac52f33e50bb772
5
+ SHA512:
6
+ metadata.gz: 5276bc3dd254c4886d60c8cde4f62163315575d519723fa2261c5d7b3a34488e714f1faaa91228a2d0654323a4edf5a1b3d7d3793ee709ed095bfad8a2843e7d
7
+ data.tar.gz: 8909c55a6d2857ad537b7dd53c20709a94085a194a37e41889c8a380a03a2e4062329afeb00db48d7d4e013d32991607d5d33281b5ddab1c42d6b7a87ef16262
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 Andrew Culver
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # BulletTrain::ObfuscatesId
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "bullet_train-obfuscates_id"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install bullet_train-obfuscates_id
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ load "rails/tasks/statistics.rake"
7
+
8
+ require "bundler/gem_tasks"
@@ -0,0 +1,51 @@
1
+ module ObfuscatesId
2
+ extend ActiveSupport::Concern
3
+
4
+ class_methods do
5
+ def hashids
6
+ # ⚠️ Changing anything in this method will invalidate any URLs with obfuscated IDs that are in the wild.
7
+ # You should not change any of these settings after going live unless you're OK breaking links in sent emails,
8
+ # breaking bookmarks to pages within your application, etc. For this reason, we don't want the Hashids salt
9
+ # configurable via an ENV value.
10
+
11
+ # We don't include digits in our alphabet because it sometimes results in fully numeric strings being generated,
12
+ # and we can't differentiate those from normal IDs that we still need to be able to deal with.
13
+ @hashids ||= Hashids.new "Default ID Obfuscation Salt for #{name}", 6, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
14
+ end
15
+
16
+ def encode_id(id)
17
+ hashids.encode(id)
18
+ end
19
+
20
+ def decode_id(id)
21
+ return id if id.to_i > 0
22
+ hashids.decode(id).first
23
+ end
24
+
25
+ def find(*ids)
26
+ super(*ids.map { |id| decode_id(id) })
27
+ end
28
+
29
+ def relation
30
+ super.tap { |r| r.extend ClassMethods }
31
+ end
32
+
33
+ def has_many(*args, &block)
34
+ options = args.extract_options!
35
+ options[:extend] = Array(options[:extend]).push(ClassMethods)
36
+ super(*args, **options, &block)
37
+ end
38
+
39
+ def find_by_obfuscated_id(id)
40
+ find_by(id: decode_id(id))
41
+ end
42
+ end
43
+
44
+ def obfuscated_id
45
+ @obfuscated_id ||= self.class.encode_id(id)
46
+ end
47
+
48
+ def to_param
49
+ obfuscated_id
50
+ end
51
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,6 @@
1
+ module BulletTrain
2
+ module ObfuscatesId
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module BulletTrain
2
+ module ObfuscatesId
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require "bullet_train/obfuscates_id/version"
2
+ require "bullet_train/obfuscates_id/engine"
3
+
4
+ module BulletTrain
5
+ module ObfuscatesId
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :bullet_train_obfuscates_id do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bullet_train-obfuscates_id
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Culver
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.0
27
+ description: Bullet Train Obfuscates ID
28
+ email:
29
+ - andrew.culver@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/assets/config/bullet_train_obfuscates_id_manifest.js
38
+ - app/models/concerns/obfuscates_id.rb
39
+ - config/routes.rb
40
+ - lib/bullet_train/obfuscates_id.rb
41
+ - lib/bullet_train/obfuscates_id/engine.rb
42
+ - lib/bullet_train/obfuscates_id/version.rb
43
+ - lib/tasks/bullet_train/obfuscates_id_tasks.rake
44
+ homepage: https://github.com/bullet-train-co/bullet_train-obfuscates_id
45
+ licenses:
46
+ - MIT
47
+ metadata:
48
+ homepage_uri: https://github.com/bullet-train-co/bullet_train-obfuscates_id
49
+ source_code_uri: https://github.com/bullet-train-co/bullet_train-obfuscates_id
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.2.22
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Bullet Train Obfuscates ID
69
+ test_files: []