rails_surrogate_key_logging 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/surrogate_key_logging/application_record.rb +17 -0
- data/app/models/surrogate_key_logging/surrogate.rb +28 -0
- data/config/database.yml +15 -0
- data/db/migrate/20230119211745_create_surrogates.rb +13 -0
- data/lib/surrogate_key_logging/version.rb +1 -1
- data/rails_surrogate_key_logging.gemspec +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea4b88c12da4f0ec6f5a7820dcfc828c86441c02ea4556a99b6d6ce9d6d2f36b
|
4
|
+
data.tar.gz: 86ab606742802c48b10f8a15f4cfee779871b2ef6fd76aab6b778f38a951368c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c1141c8d9b2df0fdd92db47211ed229e3f34afdbebfd9772a17ac6fcdbb6ef2df89c10e2f1a7065d2cef69c5ec7a606656c4fb4cc2782f951113097d7bc48eb
|
7
|
+
data.tar.gz: 3fac576dad21b8299f122eabea8c82cf3c35eec4fd299f9d0bfcab456ec6c56fc0719062b60a1466f1be7b1366ce4cf8590e2892c147055725de73cd2c61549c
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SurrogateKeyLogging
|
4
|
+
class ApplicationRecord < ::ActiveRecord::Base
|
5
|
+
self.abstract_class = true
|
6
|
+
|
7
|
+
def self.table_name
|
8
|
+
"#{Rails.application.config.database_configuration["surrogate_key_logging_#{Rails.env}"]['database']}.#{compute_table_name}"
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def table_name_prefix; end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SurrogateKeyLogging
|
4
|
+
class Surrogate < ApplicationRecord
|
5
|
+
class << self
|
6
|
+
def hash_value(value)
|
7
|
+
Digest::SHA512.hexdigest value.to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def value_for_surrogate(surrogate)
|
11
|
+
where(key: surrogate).select(:value).first&.value
|
12
|
+
end
|
13
|
+
|
14
|
+
def surrogate_for_value(value)
|
15
|
+
where(hashed_value: hash_value(value)).select(:key).first&.key
|
16
|
+
end
|
17
|
+
|
18
|
+
def add(surrogate, value)
|
19
|
+
s = new(key: surrogate, value: value, hashed_value: hash_value(value))
|
20
|
+
s.save
|
21
|
+
end
|
22
|
+
|
23
|
+
def use(surrogate)
|
24
|
+
where(key: surrogate).touch_all
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/config/database.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
<%=
|
2
|
+
YAML.load(
|
3
|
+
ERB.new(
|
4
|
+
File.read(
|
5
|
+
Rails.root.join('config', 'database.yml')
|
6
|
+
),
|
7
|
+
nil, nil, '__dummy_config_database_yml_erbout__'
|
8
|
+
).result(binding)
|
9
|
+
).inject({}) do |memo, conf|
|
10
|
+
k, v = conf
|
11
|
+
memo[k.sub(Regexp.new("^surrogate_key_logging_"),'')] = v if k.starts_with?("surrogate_key_logging_")
|
12
|
+
|
13
|
+
memo
|
14
|
+
end.to_yaml
|
15
|
+
%>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateSurrogates < ActiveRecord::Migration[6.0]
|
2
|
+
def change
|
3
|
+
create_table :surrogates, id: false, options: 'ENGINE=InnoDB, CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' do |t|
|
4
|
+
t.string :key, primary_key: true, null: false
|
5
|
+
t.text :value, limit: 4294967295, null: false
|
6
|
+
t.string :hashed_value, null: false
|
7
|
+
|
8
|
+
t.datetime :updated_at, null: false
|
9
|
+
end
|
10
|
+
add_index :surrogates, :key, unique: true
|
11
|
+
add_index :surrogates, :hashed_value, unique: true
|
12
|
+
end
|
13
|
+
end
|
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
'rubygems_mfa_required' => 'true',
|
22
22
|
}
|
23
23
|
|
24
|
-
s.files = Dir['lib/**/*', 'README.md', 'MIT-LICENSE', 'rails_surrogate_key_logging.gemspec']
|
24
|
+
s.files = Dir['app/**/*', 'lib/**/*', 'config/**/*', 'db/**/*', 'README.md', 'MIT-LICENSE', 'rails_surrogate_key_logging.gemspec']
|
25
25
|
|
26
26
|
s.require_paths = %w[ lib ]
|
27
27
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_surrogate_key_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Yelverton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -97,6 +97,10 @@ extensions: []
|
|
97
97
|
extra_rdoc_files: []
|
98
98
|
files:
|
99
99
|
- README.md
|
100
|
+
- app/models/surrogate_key_logging/application_record.rb
|
101
|
+
- app/models/surrogate_key_logging/surrogate.rb
|
102
|
+
- config/database.yml
|
103
|
+
- db/migrate/20230119211745_create_surrogates.rb
|
100
104
|
- lib/rails_surrogate_key_logging.rb
|
101
105
|
- lib/surrogate_key_logging.rb
|
102
106
|
- lib/surrogate_key_logging/action_controller.rb
|