redissify_model 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +7 -0
- data/lib/redissify_model/config.rb +11 -0
- data/lib/redissify_model/redis.rb +5 -0
- data/lib/redissify_model/sequel.rb +18 -0
- data/lib/redissify_model/version.rb +3 -0
- data/lib/redissify_model.rb +39 -0
- data/redissify_model.gemspec +26 -0
- data/spec/lib/redissify_model_spec.rb +46 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/prepare_test_table.rb +7 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af010f8e94adc15df6ed538f14f03c993d30b829
|
4
|
+
data.tar.gz: d3bdd204c7af6e9f9d0e6be54e8a7e69d062c962
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ceefd337f91eedb787109322208f90aaae2542cb5a20a23f430165692c0fcce883983014e186541db693dd57ec2a5cc555c48e765b94e8e2e5a9a2400491fee7
|
7
|
+
data.tar.gz: cb0bef9fd85d983ccda170eb7d7f6a2d3a32ddfb3cd34d5bdede40c365d80fe63e32221e921025cc2e1344809dfdcf7bf7e94ce0df7dfdd41ecb97b78c9801fb
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Charles Darwin Pobre
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# RedissifyModel
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'redissify_model'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install redissify_model
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/redissify_model/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "sequel"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module RedissifyModel
|
5
|
+
module Sequel
|
6
|
+
::Sequel::Model.class_eval do
|
7
|
+
def after_save
|
8
|
+
super
|
9
|
+
::RedissifyModel::REDIS.set self.redis_model_key_val, self.values.to_json
|
10
|
+
end
|
11
|
+
|
12
|
+
def around_destroy
|
13
|
+
super
|
14
|
+
::RedissifyModel::REDIS.del self.redis_model_key_val
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "redissify_model/version"
|
2
|
+
require "redissify_model/config"
|
3
|
+
require "redissify_model/redis"
|
4
|
+
require "redissify_model/sequel"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module RedissifyModel
|
8
|
+
def self.included(base)
|
9
|
+
base.extend ClassMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def redis_model_key_val
|
14
|
+
"#{self.class.redis_model}:#{self.id}"
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
def get_redis_ins(id)
|
19
|
+
redis_key = "#{self.redis_model}:#{id}"
|
20
|
+
redis_query = JSON.parse(RedissifyModel::REDIS.get redis_key)
|
21
|
+
|
22
|
+
if redis_query
|
23
|
+
p_id = redis_query["id"]
|
24
|
+
redis_query.delete "id" # Need to delete key id to prevent throwing a restricted primary key assignment on Sequel Model
|
25
|
+
wallet_ins = self.new(redis_query)
|
26
|
+
wallet_ins.id = p_id
|
27
|
+
wallet_ins
|
28
|
+
else
|
29
|
+
self[id]
|
30
|
+
end
|
31
|
+
rescue
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def redis_model
|
36
|
+
"#{RedissifyModel::Config.project_name}:#{self.to_s.downcase}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'redissify_model/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "redissify_model"
|
8
|
+
spec.version = RedissifyModel::VERSION
|
9
|
+
spec.authors = ["Charles Darwin Pobre"]
|
10
|
+
spec.email = ["cdpobre@yahoo.com"]
|
11
|
+
spec.summary = "Helps you cache DB objects on a Redis server"
|
12
|
+
spec.description = "Cache Model objects as key value store on Redis. It maps through namespaced models"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "redis", "~> 3.1"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "sequel"
|
26
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RedissifyModel do
|
4
|
+
RedissifyModel::Config.project_name = "test_project"
|
5
|
+
class Test < Sequel::Model
|
6
|
+
include RedissifyModel
|
7
|
+
end
|
8
|
+
|
9
|
+
let!(:test){Test.create name: "test_name", price: 23}
|
10
|
+
|
11
|
+
context "#redis_model_key_val" do
|
12
|
+
it "should return model key val" do
|
13
|
+
expect(test.redis_model_key_val).to match(/test_project:test/)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context ".get_redis_ins" do
|
18
|
+
it "should return a model object based on redis instance" do
|
19
|
+
test = Test.get_redis_ins(Test.last.id)
|
20
|
+
expect(test).to be_an_instance_of(Test)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return exact values" do
|
24
|
+
test = Test.get_redis_ins(Test.last.id)
|
25
|
+
expect(test).to eq(Test.last)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context ".redis_model" do
|
30
|
+
it "should return the exact redis model" do
|
31
|
+
expect(Test.redis_model).to eq("test_project:test")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "Hooks" do
|
36
|
+
it "should delete key if record deleted" do
|
37
|
+
test.destroy
|
38
|
+
expect(Test.get_redis_ins(test)).to be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should add key if record created" do
|
42
|
+
test2 = Test.create name: "test_name2", price: 45
|
43
|
+
expect(Test.get_redis_ins(test2.id)).not_to be_nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redissify_model
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charles Darwin Pobre
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sequel
|
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: Cache Model objects as key value store on Redis. It maps through namespaced
|
84
|
+
models
|
85
|
+
email:
|
86
|
+
- cdpobre@yahoo.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- lib/redissify_model.rb
|
98
|
+
- lib/redissify_model/config.rb
|
99
|
+
- lib/redissify_model/redis.rb
|
100
|
+
- lib/redissify_model/sequel.rb
|
101
|
+
- lib/redissify_model/version.rb
|
102
|
+
- redissify_model.gemspec
|
103
|
+
- spec/lib/redissify_model_spec.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- spec/support/prepare_test_table.rb
|
106
|
+
homepage: ''
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.2.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Helps you cache DB objects on a Redis server
|
130
|
+
test_files:
|
131
|
+
- spec/lib/redissify_model_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- spec/support/prepare_test_table.rb
|