json_cache 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +56 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/json_cache.gemspec +79 -0
- data/lib/json_cache/cache_manager.rb +21 -0
- data/lib/json_cache/call_result.rb +8 -0
- data/lib/json_cache/method_cache.rb +74 -0
- data/lib/json_cache.rb +12 -0
- data/spec/json_cache_spec.rb +164 -0
- data/spec/spec_helper.rb +12 -0
- metadata +200 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.3.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
gem 'rr'
|
14
|
+
end
|
15
|
+
|
16
|
+
gem 'bson_ext'
|
17
|
+
gem 'mharris_ext'
|
18
|
+
gem 'mongoid'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.0.3)
|
5
|
+
activesupport (= 3.0.3)
|
6
|
+
builder (~> 2.1.2)
|
7
|
+
i18n (~> 0.4)
|
8
|
+
activesupport (3.0.3)
|
9
|
+
bson (1.2.0)
|
10
|
+
bson_ext (1.2.0)
|
11
|
+
builder (2.1.2)
|
12
|
+
diff-lcs (1.1.2)
|
13
|
+
facets (2.9.0)
|
14
|
+
fattr (2.2.0)
|
15
|
+
git (1.2.5)
|
16
|
+
i18n (0.5.0)
|
17
|
+
jeweler (1.5.2)
|
18
|
+
bundler (~> 1.0.0)
|
19
|
+
git (>= 1.2.5)
|
20
|
+
rake
|
21
|
+
mharris_ext (1.5.0)
|
22
|
+
facets
|
23
|
+
fattr
|
24
|
+
mongo (1.2.0)
|
25
|
+
bson (>= 1.2.0)
|
26
|
+
mongoid (2.0.0.rc.7)
|
27
|
+
activemodel (~> 3.0)
|
28
|
+
mongo (~> 1.2)
|
29
|
+
tzinfo (~> 0.3.22)
|
30
|
+
will_paginate (~> 3.0.pre)
|
31
|
+
rake (0.8.7)
|
32
|
+
rcov (0.9.9)
|
33
|
+
rr (1.0.2)
|
34
|
+
rspec (2.3.0)
|
35
|
+
rspec-core (~> 2.3.0)
|
36
|
+
rspec-expectations (~> 2.3.0)
|
37
|
+
rspec-mocks (~> 2.3.0)
|
38
|
+
rspec-core (2.3.1)
|
39
|
+
rspec-expectations (2.3.0)
|
40
|
+
diff-lcs (~> 1.1.2)
|
41
|
+
rspec-mocks (2.3.0)
|
42
|
+
tzinfo (0.3.24)
|
43
|
+
will_paginate (3.0.pre2)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
x86-mingw32
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
bson_ext
|
50
|
+
bundler (~> 1.0.0)
|
51
|
+
jeweler (~> 1.5.2)
|
52
|
+
mharris_ext
|
53
|
+
mongoid
|
54
|
+
rcov
|
55
|
+
rr
|
56
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 mharris717
|
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.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= json_cache
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to json_cache
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 mharris717. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "json_cache"
|
16
|
+
gem.homepage = "http://github.com/mharris717/json_cache"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{json_cache}
|
19
|
+
gem.description = %Q{json_cache}
|
20
|
+
gem.email = "mharris717@gmail.com"
|
21
|
+
gem.authors = ["mharris717"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "json_cache #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/json_cache.gemspec
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{json_cache}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["mharris717"]
|
12
|
+
s.date = %q{2011-02-25}
|
13
|
+
s.description = %q{json_cache}
|
14
|
+
s.email = %q{mharris717@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"json_cache.gemspec",
|
29
|
+
"lib/json_cache.rb",
|
30
|
+
"lib/json_cache/cache_manager.rb",
|
31
|
+
"lib/json_cache/call_result.rb",
|
32
|
+
"lib/json_cache/method_cache.rb",
|
33
|
+
"spec/json_cache_spec.rb",
|
34
|
+
"spec/spec_helper.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/mharris717/json_cache}
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.5.2}
|
40
|
+
s.summary = %q{json_cache}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/json_cache_spec.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<bson_ext>, [">= 0"])
|
51
|
+
s.add_runtime_dependency(%q<mharris_ext>, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<mongoid>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
54
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
56
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<rr>, [">= 0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<bson_ext>, [">= 0"])
|
60
|
+
s.add_dependency(%q<mharris_ext>, [">= 0"])
|
61
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
62
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
63
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
64
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
65
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rr>, [">= 0"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<bson_ext>, [">= 0"])
|
70
|
+
s.add_dependency(%q<mharris_ext>, [">= 0"])
|
71
|
+
s.add_dependency(%q<mongoid>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
73
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
74
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
75
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
76
|
+
s.add_dependency(%q<rr>, [">= 0"])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module JsonCache
|
2
|
+
class CacheManager
|
3
|
+
include FromHash
|
4
|
+
fattr(:caches) { {} }
|
5
|
+
def reg(name,ops={})
|
6
|
+
res = self.caches[name.to_sym] = JsonCache::MethodCache.new(ops.merge(:name => name))
|
7
|
+
yield(res) if block_given?
|
8
|
+
end
|
9
|
+
def reg_simple(name,&b)
|
10
|
+
reg(name) do |c|
|
11
|
+
c.call_blk = b
|
12
|
+
end
|
13
|
+
end
|
14
|
+
def get_cache(name)
|
15
|
+
caches[name.to_sym] || (raise "no cache #{name}")
|
16
|
+
end
|
17
|
+
def method_missing(sym,*args,&b)
|
18
|
+
get_cache(sym).send(:get,*args,&b)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module JsonCache
|
2
|
+
class MethodCache
|
3
|
+
include FromHash
|
4
|
+
attr_accessor :name, :call_blk, :class_name, :class_blk
|
5
|
+
def call_blk(&b)
|
6
|
+
if block_given?
|
7
|
+
@call_blk = b
|
8
|
+
else
|
9
|
+
@call_blk
|
10
|
+
end
|
11
|
+
end
|
12
|
+
def class_blk(&b)
|
13
|
+
if block_given?
|
14
|
+
@class_blk = b
|
15
|
+
else
|
16
|
+
@class_blk
|
17
|
+
end
|
18
|
+
end
|
19
|
+
def ensure_class_exists
|
20
|
+
eval class_name
|
21
|
+
rescue
|
22
|
+
return make_class
|
23
|
+
end
|
24
|
+
def make_class
|
25
|
+
b = class_blk || lambda { |x| }
|
26
|
+
cls = Class.new(JsonCache::CallResult,&b)
|
27
|
+
Object.const_set(class_name,cls)
|
28
|
+
cls
|
29
|
+
end
|
30
|
+
fattr(:type_class) do
|
31
|
+
if class_name
|
32
|
+
ensure_class_exists
|
33
|
+
else
|
34
|
+
JsonCache::CallResult
|
35
|
+
end
|
36
|
+
end
|
37
|
+
def get_existing(ops)
|
38
|
+
a = type_class.where('_query_params' => ops)
|
39
|
+
f = a.first
|
40
|
+
if !f
|
41
|
+
nil
|
42
|
+
elsif f['_from_array']
|
43
|
+
a.to_a
|
44
|
+
else
|
45
|
+
f
|
46
|
+
end
|
47
|
+
end
|
48
|
+
def need?(ops)
|
49
|
+
!get_existing(ops)
|
50
|
+
end
|
51
|
+
def create_from_raw(raw,ops,from_array)
|
52
|
+
cr_hash = raw.merge('_query_params' => ops, '_query_name' => name, '_from_array' => from_array)
|
53
|
+
type_class.create!(cr_hash)
|
54
|
+
end
|
55
|
+
def get_fresh(ops)
|
56
|
+
res = call_blk[ops]
|
57
|
+
if res.kind_of?(Array)
|
58
|
+
res.map { |x| create_from_raw(x,ops,true) }
|
59
|
+
else
|
60
|
+
create_from_raw(res,ops,false)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
def get(ops)
|
64
|
+
if need?(ops)
|
65
|
+
get_fresh(ops)
|
66
|
+
else
|
67
|
+
get_existing(ops)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
def all
|
71
|
+
JsonCache::CallResult.where('_query_name' => name)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/json_cache.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'mharris_ext'
|
2
|
+
require 'mongoid'
|
3
|
+
|
4
|
+
Mongoid.configure do |config|
|
5
|
+
name = "json_cache_dev"
|
6
|
+
host = "mydesk"
|
7
|
+
config.master = Mongo::Connection.new(host).db(name)
|
8
|
+
end
|
9
|
+
|
10
|
+
%w(call_result method_cache cache_manager).each do |f|
|
11
|
+
require File.dirname(__FILE__) + "/json_cache/#{f}"
|
12
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
if false
|
4
|
+
class Thing < JsonCache::CallResult
|
5
|
+
end
|
6
|
+
|
7
|
+
class Kernel::Thing < JsonCache::CallResult
|
8
|
+
end
|
9
|
+
JsonCache::CallResult.all.each { |x| x.destroy }
|
10
|
+
raise 'foo'
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "JsonCache" do
|
14
|
+
describe 'method cache' do
|
15
|
+
def mc; @mc; end
|
16
|
+
def mc2; @mc2; end
|
17
|
+
before do
|
18
|
+
JsonCache::CallResult.delete_all
|
19
|
+
@blk = lambda do |num|
|
20
|
+
{'num' => num*2}
|
21
|
+
end
|
22
|
+
@mc = JsonCache::MethodCache.new(:name => 'test', :call_blk => @blk)
|
23
|
+
end
|
24
|
+
after do
|
25
|
+
JsonCache::CallResult.delete_all
|
26
|
+
end
|
27
|
+
it 'get first' do
|
28
|
+
mc.get(2)['num'].should == 4
|
29
|
+
end
|
30
|
+
it 'should need' do
|
31
|
+
mc.should be_need(2)
|
32
|
+
end
|
33
|
+
it 'initial get should return call result' do
|
34
|
+
mc.get(2).should be_kind_of(JsonCache::CallResult)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'already got' do
|
38
|
+
before do
|
39
|
+
mc.get(2)
|
40
|
+
end
|
41
|
+
it 'should save a call result' do
|
42
|
+
JsonCache::CallResult.where('_query_params' => 2).count.should == 1
|
43
|
+
end
|
44
|
+
it 'call result should have results' do
|
45
|
+
JsonCache::CallResult.where('_query_params' => 2).first.num.should == 4
|
46
|
+
end
|
47
|
+
it 'should not need' do
|
48
|
+
mc.should_not be_need(2)
|
49
|
+
end
|
50
|
+
it 'should need different query' do
|
51
|
+
mc.should be_need(3)
|
52
|
+
end
|
53
|
+
it 'should get result for diff query' do
|
54
|
+
mc.get(3)['num'].should == 6
|
55
|
+
end
|
56
|
+
it 'get again' do
|
57
|
+
dont_allow(mc).get_fresh(anything)
|
58
|
+
mc.get(2)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'call blk returns array' do
|
63
|
+
before do
|
64
|
+
mc.call_blk = lambda do |num|
|
65
|
+
[num,num*2].map { |x| {'num' => x} }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
it 'should return 2 CallResults' do
|
69
|
+
mc.get(2).map { |x| x.class }.should == [JsonCache::CallResult,JsonCache::CallResult]
|
70
|
+
end
|
71
|
+
it '2nd get should result 2 CallResults' do
|
72
|
+
mc.get(2)
|
73
|
+
mc.get(2).should be_kind_of(Array)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'class block' do
|
78
|
+
before do
|
79
|
+
mc.class_name = 'Thing'
|
80
|
+
mc.class_blk = lambda do |x|
|
81
|
+
def num_plus(n)
|
82
|
+
num + n
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'smoke' do
|
88
|
+
mc.get(2).num.should == 4
|
89
|
+
end
|
90
|
+
it 'type_class' do
|
91
|
+
mc.type_class.should == Thing
|
92
|
+
end
|
93
|
+
it 'call blk method' do
|
94
|
+
mc.get(2).num_plus(3).should == 7
|
95
|
+
end
|
96
|
+
it 'obj class' do
|
97
|
+
mc.get(2).should be_kind_of(Thing)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe 'multiple caches, one with own class' do
|
102
|
+
before do
|
103
|
+
@mc2 = JsonCache::MethodCache.new(:name => 'test2', :call_blk => @blk)
|
104
|
+
mc2.class_name = 'Thing'
|
105
|
+
mc2.class_blk = lambda do |x|
|
106
|
+
def num_plus(n)
|
107
|
+
num + n
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'each has been called' do
|
113
|
+
before do
|
114
|
+
mc.get(2)
|
115
|
+
mc2.get(3)
|
116
|
+
end
|
117
|
+
it 'should be 1 thing' do
|
118
|
+
Thing.count.should == 1
|
119
|
+
mc2.all.count.should == 1
|
120
|
+
end
|
121
|
+
it 'should be 2 call results' do
|
122
|
+
JsonCache::CallResult.count.should == 2
|
123
|
+
mc.all.count.should == 1
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
it 'manager ugly test all' do
|
130
|
+
m = JsonCache::CacheManager.new
|
131
|
+
m.reg :nums, :class_name => 'Num' do |c|
|
132
|
+
c.call_blk do |num|
|
133
|
+
{'num' => num * 2}
|
134
|
+
end
|
135
|
+
c.class_blk do |unused|
|
136
|
+
def num_plus(n)
|
137
|
+
num + n
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
m.nums(2).num.should == 4
|
142
|
+
m.nums(2).num_plus(3).should == 7
|
143
|
+
m.get_cache(:nums).all.count.should == 1
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'manager ugly test all simple' do
|
147
|
+
m = JsonCache::CacheManager.new
|
148
|
+
m.reg_simple :nums do |num|
|
149
|
+
{'num' => num * 2}
|
150
|
+
end
|
151
|
+
|
152
|
+
m.get_cache(:nums).type_class.should == JsonCache::CallResult
|
153
|
+
m.nums(2).num.should == 4
|
154
|
+
|
155
|
+
m.nums(2).class.should == JsonCache::CallResult
|
156
|
+
m.nums(2).should_not be_respond_to(:num_plus)
|
157
|
+
lambda { m.nums(2).num_plus(3) }.should raise_error
|
158
|
+
|
159
|
+
m.get_cache(:nums).all.count.should == 1
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'json_cache'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.mock_with :rr
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,200 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- mharris717
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-25 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bson_ext
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mharris_ext
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: mongoid
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :runtime
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rspec
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ~>
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 2
|
73
|
+
- 3
|
74
|
+
- 0
|
75
|
+
version: 2.3.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: bundler
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
hash: 23
|
87
|
+
segments:
|
88
|
+
- 1
|
89
|
+
- 0
|
90
|
+
- 0
|
91
|
+
version: 1.0.0
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: *id005
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: jeweler
|
97
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ~>
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 7
|
103
|
+
segments:
|
104
|
+
- 1
|
105
|
+
- 5
|
106
|
+
- 2
|
107
|
+
version: 1.5.2
|
108
|
+
type: :development
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: *id006
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rcov
|
113
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
hash: 3
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
version: "0"
|
122
|
+
type: :development
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: *id007
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rr
|
127
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
hash: 3
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
version: "0"
|
136
|
+
type: :development
|
137
|
+
prerelease: false
|
138
|
+
version_requirements: *id008
|
139
|
+
description: json_cache
|
140
|
+
email: mharris717@gmail.com
|
141
|
+
executables: []
|
142
|
+
|
143
|
+
extensions: []
|
144
|
+
|
145
|
+
extra_rdoc_files:
|
146
|
+
- LICENSE.txt
|
147
|
+
- README.rdoc
|
148
|
+
files:
|
149
|
+
- .document
|
150
|
+
- .rspec
|
151
|
+
- Gemfile
|
152
|
+
- Gemfile.lock
|
153
|
+
- LICENSE.txt
|
154
|
+
- README.rdoc
|
155
|
+
- Rakefile
|
156
|
+
- VERSION
|
157
|
+
- json_cache.gemspec
|
158
|
+
- lib/json_cache.rb
|
159
|
+
- lib/json_cache/cache_manager.rb
|
160
|
+
- lib/json_cache/call_result.rb
|
161
|
+
- lib/json_cache/method_cache.rb
|
162
|
+
- spec/json_cache_spec.rb
|
163
|
+
- spec/spec_helper.rb
|
164
|
+
has_rdoc: true
|
165
|
+
homepage: http://github.com/mharris717/json_cache
|
166
|
+
licenses:
|
167
|
+
- MIT
|
168
|
+
post_install_message:
|
169
|
+
rdoc_options: []
|
170
|
+
|
171
|
+
require_paths:
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
none: false
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
hash: 3
|
179
|
+
segments:
|
180
|
+
- 0
|
181
|
+
version: "0"
|
182
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
|
+
none: false
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
hash: 3
|
188
|
+
segments:
|
189
|
+
- 0
|
190
|
+
version: "0"
|
191
|
+
requirements: []
|
192
|
+
|
193
|
+
rubyforge_project:
|
194
|
+
rubygems_version: 1.5.2
|
195
|
+
signing_key:
|
196
|
+
specification_version: 3
|
197
|
+
summary: json_cache
|
198
|
+
test_files:
|
199
|
+
- spec/json_cache_spec.rb
|
200
|
+
- spec/spec_helper.rb
|