tiny-redis 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +27 -0
- data/lib/tasks/tiny/redis_tasks.rake +4 -0
- data/lib/tiny/redis.rb +53 -0
- data/lib/tiny/redis/railtie.rb +6 -0
- data/lib/tiny/redis/version.rb +5 -0
- metadata +30 -18
- data/lib/tiny-redis.rb +0 -50
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c10fdb8684fc3377ed6c516b0c07d4ecfe77d3ecd07893b04aff36e6ebe7ee7f
|
4
|
+
data.tar.gz: 8669162c0bfd1c8edd0e2779b9daac9dbc1600fa785751d3059de716449674c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fca70d1889a3f7b7da86eaf8e245fea77af710f5d3a4865d1320b47b9ae62dec776209386d5823b5ce31c01104c62e52861d13e5114f368f8678ba26f419c3b
|
7
|
+
data.tar.gz: 45e7cb8bb66c998201f605dba108768a059dc15bc066adf1b9a0eda96fcae975ad76080ce70b4524f0ddd6e742df73e17dc3a3e3ed9d332cadb03f5a1ffa00ca
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2020 Pavel Zaitsev
|
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
|
+
# Tiny::Redis
|
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 'tiny-redis'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install tiny-redis
|
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,27 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Tiny::Redis'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'test'
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
24
|
+
t.verbose = false
|
25
|
+
end
|
26
|
+
|
27
|
+
task default: :test
|
data/lib/tiny/redis.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "tiny/redis/railtie"
|
2
|
+
require 'redis'
|
3
|
+
require 'connection_pool'
|
4
|
+
|
5
|
+
module Tiny
|
6
|
+
module Redis
|
7
|
+
|
8
|
+
def self.included(klass)
|
9
|
+
klass.extend(ClassMethods)
|
10
|
+
end
|
11
|
+
|
12
|
+
def save(filter)
|
13
|
+
key, crypt = self.class.setup(index)
|
14
|
+
|
15
|
+
$redis.with do |r|
|
16
|
+
r.set(key, crypt.encrypt_and_sign(self.to_json(except: filter)))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def load(index)
|
22
|
+
key, crypt = setup(index)
|
23
|
+
|
24
|
+
$redis.with do |r|
|
25
|
+
encrypted = r.get(key)
|
26
|
+
return nil if encrypted.nil?
|
27
|
+
JSON.parse(crypt.decrypt_and_verify(encrypted), object_class: self)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def setup(index)
|
32
|
+
key = Digest::SHA1.hexdigest(index)
|
33
|
+
encrypt_key = Rails.application.credentials.user[:encryptkey]
|
34
|
+
crypt = ActiveSupport::MessageEncryptor.new(encrypt_key)
|
35
|
+
return [key, crypt]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_accessor :errors
|
40
|
+
def initialize(params = {})
|
41
|
+
@errors = ActiveModel::Errors.new(self)
|
42
|
+
|
43
|
+
params.present? && params.each do |k,v|
|
44
|
+
self[k] = v
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def []=(key, value)
|
49
|
+
return if key == 'errors' # PATCH if error sneaks in, ruins whole validation process
|
50
|
+
send("#{key}=", value)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,69 +1,81 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny-redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Zaitsev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.0.3
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 6.0.3.2
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 6.0.3
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 6.0.3.2
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
34
|
+
name: redis
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
39
|
+
version: '4.2'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
46
|
+
version: '4.2'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
48
|
+
name: connection_pool
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
53
|
+
version: 2.2.3
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
description:
|
56
|
-
email:
|
60
|
+
version: 2.2.3
|
61
|
+
description: Encrypted Redis ORM for rails, active record style
|
62
|
+
email:
|
63
|
+
- pavel@arslogi.ca
|
57
64
|
executables: []
|
58
65
|
extensions: []
|
59
66
|
extra_rdoc_files: []
|
60
67
|
files:
|
61
|
-
-
|
62
|
-
|
68
|
+
- MIT-LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- lib/tasks/tiny/redis_tasks.rake
|
72
|
+
- lib/tiny/redis.rb
|
73
|
+
- lib/tiny/redis/railtie.rb
|
74
|
+
- lib/tiny/redis/version.rb
|
75
|
+
homepage: https://blog.arslogi.ca/
|
63
76
|
licenses:
|
64
77
|
- MIT
|
65
|
-
metadata:
|
66
|
-
source_code_uri: https://github.com/pavelz/tiny-redis
|
78
|
+
metadata: {}
|
67
79
|
post_install_message:
|
68
80
|
rdoc_options: []
|
69
81
|
require_paths:
|
@@ -82,5 +94,5 @@ requirements: []
|
|
82
94
|
rubygems_version: 3.0.6
|
83
95
|
signing_key:
|
84
96
|
specification_version: 4
|
85
|
-
summary:
|
97
|
+
summary: encrypted redis orm
|
86
98
|
test_files: []
|
data/lib/tiny-redis.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'connection_pool'
|
2
|
-
require 'redis'
|
3
|
-
|
4
|
-
module TinyRedis
|
5
|
-
def self.included(klass)
|
6
|
-
klass.extend(ClassMethods)
|
7
|
-
end
|
8
|
-
|
9
|
-
def save(filter)
|
10
|
-
key, crypt = self.class.setup(index)
|
11
|
-
|
12
|
-
$redis.with do |r|
|
13
|
-
r.set(key, crypt.encrypt_and_sign(self.to_json(except: filter)))
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
module ClassMethods
|
18
|
-
def load(index)
|
19
|
-
key, crypt = setup(index)
|
20
|
-
|
21
|
-
$redis.with do |r|
|
22
|
-
encrypted = r.get(key)
|
23
|
-
return nil if encrypted.nil?
|
24
|
-
JSON.parse(crypt.decrypt_and_verify(encrypted), object_class: self)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def setup(index)
|
29
|
-
key = Digest::SHA1.hexdigest(index)
|
30
|
-
encrypt_key = Rails.application.credentials.user[:encryptkey]
|
31
|
-
crypt = ActiveSupport::MessageEncryptor.new(encrypt_key)
|
32
|
-
return [key, crypt]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
attr_accessor :errors
|
37
|
-
def initialize(params = {})
|
38
|
-
@errors = ActiveModel::Errors.new(self)
|
39
|
-
|
40
|
-
params.present? && params.each do |k,v|
|
41
|
-
self[k] = v
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def []=(key, value)
|
46
|
-
return if key == 'errors' # PATCH if error sneaks in, ruins whole validation process
|
47
|
-
send("#{key}=", value)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|