activesupport-db-cache 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ db/*.sqlite3
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format documentation
3
+ --backtrace
4
+ --default_path spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activesupport-db-cache.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sergei O. Udalov
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,29 @@
1
+ # Activesupport::Db::Cache
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'activesupport-db-cache'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install activesupport-db-cache
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ Dir["tasks/**/*.task"].each { |task| load task }
4
+
5
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require File.expand_path('../lib/activesupport-db-cache', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Sergei O. Udalov"]
7
+ gem.email = ["sergei.udalov@gmail.com"]
8
+ gem.description = %q{ActiveRecord DB Store engine for ActiveSupport::Cache}
9
+ gem.summary = %q{ActiveRecord DB Store engine for ActiveSupport::Cache}
10
+ gem.homepage = ""
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "activesupport-db-cache"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = ActiveSupport::Cache::ActiveRecordStore::VERSION
18
+
19
+ gem.add_dependency "activesupport", ">=3.0.0"
20
+ gem.add_dependency "activerecord", ">=3.0.0"
21
+ gem.add_development_dependency "rspec"
22
+ gem.add_development_dependency "sqlite3"
23
+ end
@@ -0,0 +1,42 @@
1
+
2
+ module ActiveSupport
3
+ module Cache
4
+ class ActiveRecordStore < Store
5
+ VERSION = "0.0.1"
6
+
7
+ # set database url:
8
+ # ENV['ACTIVE_RECORD_CACHE_STORE_DATABASE_URL'] = "sqlite3://./db/test2.sqlite3"
9
+ class CacheItem < ActiveRecord::Base
10
+ self.table_name = ENV['ACTIVE_RECORD_CACHE_STORE_TABLE'] || 'cache_items'
11
+ establish_connection ENV['ACTIVE_RECORD_CACHE_STORE_DATABASE_URL'] if ENV['ACTIVE_RECORD_CACHE_STORE_DATABASE_URL'].present?
12
+
13
+ def value
14
+ Marshal.load(self[:value])
15
+ end
16
+
17
+ def expired?
18
+ false
19
+ end
20
+ end
21
+
22
+ def clear
23
+ CacheItem.delete_all
24
+ end
25
+
26
+ def delete_entry(key, options)
27
+ CacheItem.delete_all(:key => key)
28
+ end
29
+
30
+ def read_entry(key, options)
31
+ CacheItem.find_by_key(key)
32
+ end
33
+
34
+ def write_entry(key, entry, options)
35
+ item = CacheItem.find_or_initialize_by_key(key)
36
+ item.value = Marshal.dump(entry.value)
37
+ item.save
38
+ end
39
+ end
40
+ end
41
+ end
42
+
@@ -0,0 +1,4 @@
1
+ require "active_record"
2
+ require "active_support"
3
+ require "active_support/cache"
4
+ require "active_support/cache/active_record_store"
data/log/test.log ADDED
File without changes
@@ -0,0 +1,63 @@
1
+ require 'spec_helper.rb'
2
+
3
+ module ActiveSupport
4
+ module Cache
5
+ describe ActiveRecordStore do
6
+ before do
7
+ @store = ActiveRecordStore.new
8
+ end
9
+
10
+ it "should store numbers" do
11
+ @store.write("foo", 123)
12
+ @store.read("foo").should eq(123)
13
+ end
14
+
15
+ it "should store strings" do
16
+ @store.write("foo", "bar string")
17
+ @store.read("foo").should eq("bar string")
18
+ end
19
+
20
+ it "should store hash" do
21
+ @store.write("foo", { :a => 123 })
22
+ @store.read("foo").keys.should include(:a)
23
+ @store.read("foo")[:a].should eq(123)
24
+ end
25
+
26
+ it "should expire entries"
27
+ it "should use LIMIT"
28
+
29
+ describe "#read" do
30
+ before do
31
+ @store.write("foo", 123)
32
+ end
33
+
34
+ it "should return nil if missed" do
35
+ @store.read("bar").should be_nil
36
+ end
37
+
38
+ it "should read data if hit" do
39
+ @store.read("foo").should eq(123)
40
+ end
41
+ end
42
+
43
+ describe "#clear" do
44
+ it "should clear cache" do
45
+ @store.write("foo", 123)
46
+ @store.write("bar", "blah data")
47
+ @store.clear
48
+ @store.read("foo").should be_blank
49
+ @store.read("bar").should be_blank
50
+ end
51
+ end
52
+
53
+ describe "#delete" do
54
+ it "should delete entry" do
55
+ @store.write("foo", 123)
56
+ @store.delete("foo")
57
+ @store.read("foo").should be_blank
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'activesupport-db-cache'
4
+
5
+ require "sqlite3"
6
+ ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => 'db/test.sqlite3')
7
+ ActiveRecord::Base.connection.create_table(:cache_items, :force => true) do |t|
8
+ t.column :key, :string
9
+ t.column :value, :text
10
+ end
11
+ ActiveRecord::Base.connection.add_index(:cache_items, :key, :unique => true)
12
+
13
+ #logfile = File.open(File.expand_path("../../log/test.log", __FILE__), 'a')
14
+ #ActiveSupport::Cache::ActiveRecordStore.logger = Logger.new(logfile)
15
+
16
+ Dir['./spec/support/*.rb'].map {|f| require f }
17
+
18
+ RSpec.configure do |config|
19
+ config.filter_run :focus => true
20
+ config.run_all_when_everything_filtered = true
21
+ end
data/tasks/rspec.task ADDED
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new
4
+
5
+ RSpec::Core::RakeTask.new(:rcov) do |task|
6
+ task.rcov = true
7
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activesupport-db-cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sergei O. Udalov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: activerecord
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sqlite3
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: ActiveRecord DB Store engine for ActiveSupport::Cache
79
+ email:
80
+ - sergei.udalov@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - Gemfile
88
+ - LICENSE
89
+ - README.md
90
+ - Rakefile
91
+ - activesupport-db-cache.gemspec
92
+ - lib/active_support/cache/active_record_store.rb
93
+ - lib/activesupport-db-cache.rb
94
+ - log/test.log
95
+ - spec/active_support/cache/active_record_store_spec.rb
96
+ - spec/spec_helper.rb
97
+ - tasks/rspec.task
98
+ homepage: ''
99
+ licenses: []
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.24
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: ActiveRecord DB Store engine for ActiveSupport::Cache
122
+ test_files:
123
+ - spec/active_support/cache/active_record_store_spec.rb
124
+ - spec/spec_helper.rb