digest_generator 0.1.1

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: 6953bd9dffe4cc95debbe7efc16e875b5aa76b4bd7989b1904e3d9ea86bf3e6e
4
+ data.tar.gz: '092b4850ed4ab5d846950a18dad4238c9ff9a0e5fc86fd591710e0e3f8ce5941'
5
+ SHA512:
6
+ metadata.gz: c92d4345c254beda529bdee281a05320fcb8a4a1c535f40e5f8c4c8790402d1997d7c6867a5403457f807ff69539bde7928e3fa5111fc64a33d9b6752a559c5a
7
+ data.tar.gz: 63c5cb853aed6ab9cb8ff4d31f40169e213727adac8e80c015b59b55d51be1923356ba053a5739fb8f9782a69c832001730f460829b82641ad24aefbba0b7b9f
data/.DS_Store ADDED
Binary file
@@ -0,0 +1,54 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ working_directory: ~/YourMechanic/digest_generator
5
+ parallelism: 1
6
+ shell: /bin/bash --login
7
+
8
+ environment:
9
+ CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
10
+ CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
11
+ docker:
12
+ - image: circleci/ruby:2.6.2
13
+ steps:
14
+ - checkout
15
+ - run: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
16
+ - restore_cache:
17
+ keys:
18
+ # This branch if available
19
+ - v2-dep-{{ .Branch }}-
20
+ # Default branch if not
21
+ - v2-dep-master-
22
+ # Any branch if there are none on the default branch - this should be unnecessary if you have your default branch configured correctly
23
+ - v2-dep-
24
+ - run:
25
+ name: Install bundler for digest_generator
26
+ working_directory: ~/YourMechanic/digest_generator
27
+ command: gem install bundler:2.2.11
28
+ - run:
29
+ name: Install Gems for digest_generator
30
+ working_directory: ~/YourMechanic/digest_generator
31
+ command: bundle install
32
+ # Save dependency cache
33
+ - save_cache:
34
+ key: v2-dep-{{ .Branch }}-{{ epoch }}
35
+ paths:
36
+ - vendor/bundle
37
+ - ~/virtualenvs
38
+ - ~/.m2
39
+ - ~/.ivy2
40
+ - ~/.bundle
41
+ - run:
42
+ working_directory: ~/YourMechanic/digest_generator
43
+ command: bundle exec rubocop
44
+ - run:
45
+ working_directory: ~/YourMechanic/digest_generator
46
+ command: bundle exec rspec --colour --drb --profile -fd --format progress $(circleci tests glob "spec/*_spec.rb" | circleci tests split)
47
+ - store_test_results:
48
+ path: /tmp/circleci-test-results
49
+ - store_artifacts:
50
+ path: /tmp/circleci-artifacts
51
+ - store_artifacts:
52
+ path: /tmp/circleci-test-results
53
+ - store_artifacts:
54
+ path: digest_generator/coverage
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ Style/NumericLiterals:
4
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,15 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2021-02-19 12:51:57 UTC using RuboCop version 1.10.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnforcedStyle, Autocorrect.
12
+ # SupportedStyles: module_function, extend_self, forbidden
13
+ Style/ModuleFunction:
14
+ Exclude:
15
+ - 'lib/digest_generator.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-02-19
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at sachin@yourmechanic.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in digest_generator.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ digest_generator (0.1.1)
5
+ xxhash (~> 0.4.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ byebug (11.1.3)
12
+ diff-lcs (1.4.4)
13
+ parallel (1.20.1)
14
+ parser (3.0.0.0)
15
+ ast (~> 2.4.1)
16
+ rainbow (3.0.0)
17
+ rake (13.0.3)
18
+ regexp_parser (2.0.3)
19
+ rexml (3.2.4)
20
+ rspec (3.10.0)
21
+ rspec-core (~> 3.10.0)
22
+ rspec-expectations (~> 3.10.0)
23
+ rspec-mocks (~> 3.10.0)
24
+ rspec-core (3.10.1)
25
+ rspec-support (~> 3.10.0)
26
+ rspec-expectations (3.10.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-mocks (3.10.2)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-support (3.10.2)
33
+ rubocop (1.10.0)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.0.0.0)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml
39
+ rubocop-ast (>= 1.2.0, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 3.0)
42
+ rubocop-ast (1.4.1)
43
+ parser (>= 2.7.1.5)
44
+ ruby-progressbar (1.11.0)
45
+ unicode-display_width (2.0.0)
46
+ xxhash (0.4.0)
47
+
48
+ PLATFORMS
49
+ x86_64-darwin-19
50
+ x86_64-linux
51
+
52
+ DEPENDENCIES
53
+ byebug
54
+ digest_generator!
55
+ rake (~> 13.0)
56
+ rspec (~> 3.0)
57
+ rubocop (~> 1.7)
58
+
59
+ BUNDLED WITH
60
+ 2.2.11
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 YourMechanic
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 sachinsaxena1996
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,71 @@
1
+ # DigestGenerator
2
+
3
+ A simple digest generator which uses xxhash for digest generation.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'digest_generator', :branch => 'master'
11
+ ```
12
+
13
+ And then run `bundle install` in application root directory.
14
+
15
+
16
+ ## Usage
17
+
18
+ Supported Algorithm at present is xxHash.
19
+
20
+ This gem can be used in two ways:
21
+
22
+ ### To generate Hash 64 and mask bit 63 (0-63) (to remove signedness to be compatible with postgress bigints) call: <br/>
23
+
24
+ ```ruby
25
+ DigestGenerator.digest_63bit(payload)
26
+ ```
27
+
28
+ ### To generate Hash 64 bit digest
29
+ ```ruby
30
+ DigestGenerator.digest_64bit(payload)
31
+ ```
32
+
33
+ ### To generate Hash 32 bit digest
34
+ ```ruby
35
+ DigestGenerator.digest_32bit(payload)
36
+ ```
37
+
38
+ ### To use digest as a primary key for a model you need to include DigestGenerator module and define DIGEST_VALID_KEYS as:
39
+
40
+ ```ruby
41
+ include DigestGenerator
42
+ self.primary_key = 'digest'
43
+ DIGEST_VALID_KEYS = %w[
44
+ name
45
+ ].freeze
46
+
47
+ ```
48
+
49
+ Call refresh_digest on an instance of your model to set its digest value. <br/>
50
+ ```ruby
51
+ person = Person.new(name: 'something')
52
+ # (Set the supported algorithm. As xxHash is the default algorithm you can skip this step if you want to use xxHash algorithm.)
53
+ person.algorithm = 'xxHash'
54
+ # (now your digest key is set to 64 bit and mask bit 63 (0-63) value)
55
+ person.refresh_digest
56
+
57
+ ```
58
+
59
+ You can also set algorithm by creating a file digest_generator.rb in config/initializers folder
60
+ with: <br/>
61
+ ```ruby
62
+ DigestGenerator.algorithm = 'xxHash'
63
+ ```
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
68
+
69
+ ## Code of Conduct
70
+
71
+ Everyone interacting in the DigestGenerator project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/digest_generator/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'digest_generator'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/digest_generator/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'digest_generator'
7
+ spec.version = DigestGenerator::VERSION
8
+ spec.authors = ['Sachin Saxena']
9
+ spec.email = ['dev@yourmechanic.com']
10
+
11
+ spec.summary = 'Digest generator to generate digest'
12
+ spec.description = 'Generates Hash 64 and mask bit 63 (0-63) to remove signedness
13
+ to be compatible with postgres bigints, supports xxHash32 and xxHash64 also'
14
+ spec.homepage = 'https://github.com/YourMechanic/digest_generator'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.2')
17
+
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = 'https://github.com/YourMechanic/digest_generator'
22
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+
36
+ # For more information and examples about making a new gem, checkout our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+
39
+ spec.add_development_dependency 'rake', '~> 13.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
+ spec.add_development_dependency 'rubocop', '~> 1.7'
42
+ spec.add_dependency 'xxhash', '~> 0.4.0'
43
+ spec.add_development_dependency 'byebug'
44
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'digest_generator/version'
4
+ require 'xxhash'
5
+ require 'byebug'
6
+
7
+ # DigestGenerator
8
+ module DigestGenerator
9
+ extend self
10
+
11
+ MASK_64BIT = 0x7FFFFFFFFFFFFFFF
12
+ XXHASH_ALGO = 'xxHash'
13
+ SUPPORTED_ALGORITHMS = [XXHASH_ALGO].freeze
14
+
15
+ def algorithm
16
+ @algorithm
17
+ end
18
+
19
+ def algorithm=(value)
20
+ @algorithm = value
21
+ end
22
+
23
+ def configure_default_algo
24
+ self.algorithm = XXHASH_ALGO if algorithm.nil?
25
+ end
26
+
27
+ # Hash 64 and mask bit 63 (0-63) to remove signedness to be compatible with postgress bigints
28
+ def digest_63bit(payload)
29
+ configure_default_algo
30
+ send("#{algorithm.downcase}63_digest", payload)
31
+ end
32
+
33
+ def digest_32bit(payload)
34
+ configure_default_algo
35
+ send("#{algorithm.downcase}32_digest", payload)
36
+ end
37
+
38
+ def digest_64bit(payload)
39
+ configure_default_algo
40
+ send("#{algorithm.downcase}64_digest", payload)
41
+ end
42
+
43
+ def self.included(base)
44
+ base.include(InstanceMethods)
45
+ end
46
+
47
+ # InstanceMethods
48
+ module InstanceMethods
49
+ def refresh_digest
50
+ self.digest = generate_digest
51
+ end
52
+
53
+ private
54
+
55
+ def generate_digest
56
+ properties = attributes # Cache the hash version of the object
57
+ digest_keys = self.class::DIGEST_VALID_KEYS
58
+ values = digest_keys.map { |key| properties[key] }
59
+ configure_default_algo
60
+ unless SUPPORTED_ALGORITHMS.include?(XXHASH_ALGO)
61
+ raise "Please ask the gem author to add support
62
+ for #{algorithm}"
63
+ end
64
+
65
+ digest_63bit(values)
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def xxhash63_digest(payload)
72
+ XXhash.xxh64(payload) & MASK_64BIT
73
+ end
74
+
75
+ def xxhash64_digest(payload)
76
+ XXhash.xxh64(payload)
77
+ end
78
+
79
+ def xxhash32_digest(payload)
80
+ XXhash.xxh32(payload)
81
+ end
82
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DigestGenerator
4
+ VERSION = '0.1.1'
5
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digest_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Sachin Saxena
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '13.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '13.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: xxhash
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |-
84
+ Generates Hash 64 and mask bit 63 (0-63) to remove signedness
85
+ to be compatible with postgres bigints, supports xxHash32 and xxHash64 also
86
+ email:
87
+ - dev@yourmechanic.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".DS_Store"
93
+ - ".circleci/config.yml"
94
+ - ".gitignore"
95
+ - ".rubocop.yml"
96
+ - ".rubocop_todo.yml"
97
+ - ".ruby-version"
98
+ - CHANGELOG.md
99
+ - CODE_OF_CONDUCT.md
100
+ - Gemfile
101
+ - Gemfile.lock
102
+ - LICENSE
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - bin/console
107
+ - bin/setup
108
+ - digest_generator.gemspec
109
+ - lib/digest_generator.rb
110
+ - lib/digest_generator/version.rb
111
+ homepage: https://github.com/YourMechanic/digest_generator
112
+ licenses:
113
+ - MIT
114
+ metadata:
115
+ allowed_push_host: https://rubygems.org
116
+ homepage_uri: https://github.com/YourMechanic/digest_generator
117
+ source_code_uri: https://github.com/YourMechanic/digest_generator
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: 2.6.2
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubygems_version: 3.2.8
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Digest generator to generate digest
137
+ test_files: []