cache_driver 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 674922fba3ded31a1640ac8974c798f591f7132d
4
- data.tar.gz: dff31e48f7763fa0e7d68693bf787997c64b8ec0
3
+ metadata.gz: 6900eb0e5257ce9be8cfd27581a55913564db407
4
+ data.tar.gz: 058bd98fd734647c212049c36dab3055cfd38797
5
5
  SHA512:
6
- metadata.gz: 04f2f65372264fe96ce6318ad63c30ce06e2d9f5fc4404e220385064ac81fad5fde57c9837c2d4be0a9b99ed547301ed774654c1853b978299dd57c9fb9e634e
7
- data.tar.gz: 7635ed4b3eab7ddd00bbacf0b54ac2a04ca10d70e823cd148dd4440f92892d7f538e119c9e393cabfbe0998a79e1dcb99121ef06690b076ea4c345ccc4db92f9
6
+ metadata.gz: da4f5b98c439c09b36be99483363dfba17079e10bab35aab08bd4d2cdf8cc0890abeeba7e939e8012f28a7b7d73d86da2b2d7e3e590ed8717e09715cbb26fc71
7
+ data.tar.gz: 1eaa73e455951dd5c630be3da769fc28ac06aa0267d4498effcca7a3dbb37d0520fd09d88f41da06cb98ff35c5a65390a2a5b2d91b7b0e8ebc446cca33f5f381
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cache_driver (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ rake (10.4.2)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ bundler (~> 1.10)
16
+ cache_driver!
17
+ rake (~> 10.0)
18
+
19
+ BUNDLED WITH
20
+ 1.10.3
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # CacheDriver
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cache_driver`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ This gem makes rails model act as ActiveRecord, but not save data into database but cache system, file or redis
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,17 +20,47 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ Your can create a config file to set storage type
24
+
25
+ $ touch config/initializers/cache_driver.rb
26
+
27
+ ```ruby
28
+ # CacheDriver Config
29
+ # to make model save data to file or redis not database
30
+
31
+ CacheDriver.setup do |config|
32
+ # set cache store type, :file or :redis
33
+ # default is :file
34
+ config.store = :file
35
+ end
36
+ ```
37
+
38
+ And then, create a model file in `app/models`
26
39
 
27
- ## Development
40
+ $ touch app/models/cache_model.rb
28
41
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+ Just define model like below
30
43
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+ ```ruby
45
+ class CacheModel < CacheRecord
46
+ end
47
+ ```
48
+
49
+ So you can use this model just like other ActiveRecord instance in controllers like
50
+
51
+ ```ruby
52
+ cache_models = CacheModel.find_all # get all instance in cache
53
+
54
+ cache_model = CacheModel.find_by_id params[:id] # get instance with id
55
+
56
+ cache_model.save! # save this instance to cache
57
+
58
+ cache_model.destroy # delete this instance
59
+ ```
32
60
 
33
61
  ## Contributing
34
62
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cache_driver. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/goshan/cache_driver.
36
64
 
37
65
 
38
66
  ## License
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -24,10 +24,15 @@ class CacheRecord
24
24
  end
25
25
 
26
26
  def to_cache
27
- self.inspect
27
+ self.to_json
28
28
  end
29
29
 
30
30
  def self.from_cache(str)
31
- self.new
31
+ json = JSON.parse str
32
+ ins = self.new
33
+ json.each do |key, value|
34
+ ins.send "#{key}=", value
35
+ end
36
+ ins
32
37
  end
33
38
  end
@@ -1,3 +1,3 @@
1
1
  module CacheDriver
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - goshan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-27 00:00:00.000000000 Z
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -47,8 +47,10 @@ extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
49
  - Gemfile
50
+ - Gemfile.lock
50
51
  - LICENSE.txt
51
52
  - README.md
53
+ - Rakefile
52
54
  - cache_driver.gemspec
53
55
  - lib/cache_driver.rb
54
56
  - lib/cache_driver/cache_record.rb
@@ -56,6 +58,7 @@ files:
56
58
  - lib/cache_driver/config.rb
57
59
  - lib/cache_driver/file_cache_util.rb
58
60
  - lib/cache_driver/version.rb
61
+ - pkg/cache_driver-0.1.0.gem
59
62
  - tmp/cache/empty
60
63
  homepage: https://github.com/goshan/cache_driver
61
64
  licenses: