perma_cache 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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZmZmZTYxYWI3YWZjZDgzMjdmMDRhMGViMmM1MWJlYzQ1NTYzNTg0Nw==
5
- data.tar.gz: !binary |-
6
- ZWRiYTQzNTc3YjY1N2M3Y2YxMzA2YmMwZjMxZWFmMGQ4YmJkOTNlNA==
2
+ SHA1:
3
+ metadata.gz: 921cb4e2804330effa28815fd21d2d7a8dc03b28
4
+ data.tar.gz: d9d136e1f7d48776b1dae411947cdff474863ac1
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YzJlMWQ1NWFjY2RlNjkyZTIyODBkNDFjYTBkYzAyNGMzMmYxMTE3YTM4Y2I2
10
- NTkyMjBhYjRhODdhMTFmNDQ3MmNkZjExNGFjY2UxMjEwZGNhMmI5YzYzZDMw
11
- N2RiZTM2ZTkxZmVhYTZhNWMyMjk4MTdhNzhhZTE3ZGY4ODRlMDQ=
12
- data.tar.gz: !binary |-
13
- YjA3ZGJkYzM5N2I2ZThiNDhjNDZkZjlmODY1OGViNzcyNDMyN2VmMjgzNjYx
14
- OWEzZTVjM2NjMDhkNGI3MGVjMjEzMTE3MGQzMmNjOWMyZjUyM2FjZmIwOGMw
15
- YmVkNWY0ZmIxNjhkZjYwNjUwOTg3NGEwNDU3OGUyMTA5ZDkxYmY=
6
+ metadata.gz: 579934a7efa6f9850295bd935bfb1de69912c19531669c79e3d35cbb981b2fdfac36745b38c0fda46a032a30dc423b3899fd468d4be0ecf7498e36b2d6d29b01
7
+ data.tar.gz: 67a176a6d87eb548d9101ea02901792dc6766bb7fd0e544e1f94558e78dfa25cdd0c89e7d69b224ca140c58c627dfeee60e2cce812b2b769feb7a23a8a47dd84
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -1 +1 @@
1
- 1.9.3-p484
1
+ 2.1.6
data/Gemfile CHANGED
@@ -2,3 +2,11 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in perma_cache.gemspec
4
4
  gemspec
5
+
6
+ gem "bundler"
7
+ gem "rake"
8
+ gem "minitest"
9
+ gem "shoulda"
10
+ gem "mocha"
11
+ gem "byebug"
12
+
@@ -0,0 +1,122 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ perma_cache (0.0.7)
5
+ rails
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.2.1)
11
+ actionpack (= 4.2.1)
12
+ actionview (= 4.2.1)
13
+ activejob (= 4.2.1)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ actionpack (4.2.1)
17
+ actionview (= 4.2.1)
18
+ activesupport (= 4.2.1)
19
+ rack (~> 1.6)
20
+ rack-test (~> 0.6.2)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
23
+ actionview (4.2.1)
24
+ activesupport (= 4.2.1)
25
+ builder (~> 3.1)
26
+ erubis (~> 2.7.0)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
29
+ activejob (4.2.1)
30
+ activesupport (= 4.2.1)
31
+ globalid (>= 0.3.0)
32
+ activemodel (4.2.1)
33
+ activesupport (= 4.2.1)
34
+ builder (~> 3.1)
35
+ activerecord (4.2.1)
36
+ activemodel (= 4.2.1)
37
+ activesupport (= 4.2.1)
38
+ arel (~> 6.0)
39
+ activesupport (4.2.1)
40
+ i18n (~> 0.7)
41
+ json (~> 1.7, >= 1.7.7)
42
+ minitest (~> 5.1)
43
+ thread_safe (~> 0.3, >= 0.3.4)
44
+ tzinfo (~> 1.1)
45
+ arel (6.0.0)
46
+ builder (3.2.2)
47
+ byebug (4.0.5)
48
+ columnize (= 0.9.0)
49
+ columnize (0.9.0)
50
+ erubis (2.7.0)
51
+ globalid (0.3.5)
52
+ activesupport (>= 4.1.0)
53
+ i18n (0.7.0)
54
+ json (1.8.2)
55
+ loofah (2.0.2)
56
+ nokogiri (>= 1.5.9)
57
+ mail (2.6.3)
58
+ mime-types (>= 1.16, < 3)
59
+ metaclass (0.0.4)
60
+ mime-types (2.5)
61
+ mini_portile (0.6.2)
62
+ minitest (5.6.1)
63
+ mocha (1.1.0)
64
+ metaclass (~> 0.0.1)
65
+ nokogiri (1.6.6.2)
66
+ mini_portile (~> 0.6.0)
67
+ rack (1.6.1)
68
+ rack-test (0.6.3)
69
+ rack (>= 1.0)
70
+ rails (4.2.1)
71
+ actionmailer (= 4.2.1)
72
+ actionpack (= 4.2.1)
73
+ actionview (= 4.2.1)
74
+ activejob (= 4.2.1)
75
+ activemodel (= 4.2.1)
76
+ activerecord (= 4.2.1)
77
+ activesupport (= 4.2.1)
78
+ bundler (>= 1.3.0, < 2.0)
79
+ railties (= 4.2.1)
80
+ sprockets-rails
81
+ rails-deprecated_sanitizer (1.0.3)
82
+ activesupport (>= 4.2.0.alpha)
83
+ rails-dom-testing (1.0.6)
84
+ activesupport (>= 4.2.0.beta, < 5.0)
85
+ nokogiri (~> 1.6.0)
86
+ rails-deprecated_sanitizer (>= 1.0.1)
87
+ rails-html-sanitizer (1.0.2)
88
+ loofah (~> 2.0)
89
+ railties (4.2.1)
90
+ actionpack (= 4.2.1)
91
+ activesupport (= 4.2.1)
92
+ rake (>= 0.8.7)
93
+ thor (>= 0.18.1, < 2.0)
94
+ rake (10.4.2)
95
+ shoulda (3.5.0)
96
+ shoulda-context (~> 1.0, >= 1.0.1)
97
+ shoulda-matchers (>= 1.4.1, < 3.0)
98
+ shoulda-context (1.2.1)
99
+ shoulda-matchers (2.8.0)
100
+ activesupport (>= 3.0.0)
101
+ sprockets (3.0.3)
102
+ rack (~> 1.0)
103
+ sprockets-rails (2.2.4)
104
+ actionpack (>= 3.0)
105
+ activesupport (>= 3.0)
106
+ sprockets (>= 2.8, < 4.0)
107
+ thor (0.19.1)
108
+ thread_safe (0.3.5)
109
+ tzinfo (1.2.2)
110
+ thread_safe (~> 0.1)
111
+
112
+ PLATFORMS
113
+ ruby
114
+
115
+ DEPENDENCIES
116
+ bundler
117
+ byebug
118
+ minitest
119
+ mocha
120
+ perma_cache!
121
+ rake
122
+ shoulda
@@ -41,8 +41,12 @@ module PermaCache
41
41
  end
42
42
 
43
43
  module ClassMethods
44
- def perma_cache(method_name, options = {})
44
+ def perma_cache(original_name, options = {})
45
45
  class_eval do
46
+ regex = /[\?\!]\Z/
47
+ method_name = original_name.to_s.gsub("!", "_exclamation").gsub("?", "_question")
48
+ method_base = original_name.to_s.gsub(regex,'')
49
+ method_suffix = original_name.to_s.match(regex)
46
50
 
47
51
  was_rebuilt_inst_var = "@#{method_name}_was_rebuilt"
48
52
 
@@ -74,7 +78,7 @@ module PermaCache
74
78
 
75
79
  define_method "#{method_name}!" do
76
80
  instance_variable_set(was_rebuilt_inst_var , true)
77
- send("#{method_name}_without_perma_cache").tap do |result|
81
+ send("#{method_base}_without_perma_cache#{method_suffix}").tap do |result|
78
82
  PermaCache.cache.write(send("#{method_name}_perma_cache_key"), result, :expires_in => options[:expires_in])
79
83
  end
80
84
  end
@@ -83,7 +87,7 @@ module PermaCache
83
87
  PermaCache.cache.read(send("#{method_name}_perma_cache_key"))
84
88
  end
85
89
 
86
- define_method "#{method_name}_with_perma_cache" do
90
+ define_method "#{method_base}_with_perma_cache#{method_suffix}" do
87
91
  instance_variable_set(was_rebuilt_inst_var , false)
88
92
 
89
93
  send("#{method_name}_get_perma_cache") ||
@@ -97,7 +101,7 @@ module PermaCache
97
101
  instance_variable_get(was_rebuilt_inst_var ) == true
98
102
  end
99
103
 
100
- alias_method_chain method_name, :perma_cache
104
+ alias_method_chain [method_base, method_suffix].join, :perma_cache
101
105
  end
102
106
  end
103
107
  end
@@ -1,3 +1,3 @@
1
1
  module PermaCache
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -19,11 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "rails"
22
-
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "shoulda"
26
- spec.add_development_dependency "mocha"
27
- spec.add_development_dependency "debugger"
28
22
  end
29
23
 
@@ -24,6 +24,18 @@ class KlassOne
24
24
  end
25
25
  perma_cache :method3, :version => 2, :expires_in => 5
26
26
 
27
+ def question?
28
+ sleep 1
29
+ 4
30
+ end
31
+ perma_cache :question?
32
+
33
+ def exclamation!
34
+ sleep 1
35
+ 4
36
+ end
37
+ perma_cache :exclamation!
38
+
27
39
  def other_klass
28
40
  KlassTwo.new
29
41
  end
@@ -55,7 +67,7 @@ module ModuleOne
55
67
  end
56
68
  end
57
69
 
58
- class PermaCacheTest < Test::Unit::TestCase
70
+ class PermaCacheTest < Minitest::Test
59
71
 
60
72
  context "build_key_from_object" do
61
73
  context "for a class" do
@@ -87,7 +99,7 @@ class PermaCacheTest < Test::Unit::TestCase
87
99
  context "calling cache" do
88
100
  context "without setting a cache source" do
89
101
  setup do
90
- PermaCache.send :remove_instance_variable, :@cache
102
+ PermaCache.send :remove_instance_variable, :@cache rescue nil
91
103
  end
92
104
  should "raise" do
93
105
  assert_raises PermaCache::UndefinedCache do
@@ -106,11 +118,37 @@ class PermaCacheTest < Test::Unit::TestCase
106
118
  end
107
119
 
108
120
  context "KlassOne" do
109
- should "have some additional methods defined" do
121
+ should "have some methods defined for :method1" do
110
122
  obj = KlassOne.new
123
+ assert obj.respond_to?(:method1_base_key)
111
124
  assert obj.respond_to?(:method1_perma_cache_key)
112
125
  assert obj.respond_to?(:method1!)
126
+ assert obj.respond_to?(:method1_get_perma_cache)
113
127
  assert obj.respond_to?(:method1_with_perma_cache)
128
+ assert obj.respond_to?(:method1_without_perma_cache)
129
+ assert obj.respond_to?(:method1_was_rebuilt?)
130
+ end
131
+
132
+ should "have some methods defined for :question?" do
133
+ obj = KlassOne.new
134
+ assert obj.respond_to?(:question_question_base_key)
135
+ assert obj.respond_to?(:question_question_perma_cache_key)
136
+ assert obj.respond_to?(:question_question!)
137
+ assert obj.respond_to?(:question_question_get_perma_cache)
138
+ assert obj.respond_to?(:question_with_perma_cache?)
139
+ assert obj.respond_to?(:question_without_perma_cache?)
140
+ assert obj.respond_to?(:question_question_was_rebuilt?)
141
+ end
142
+
143
+ should "have some methods defined for :exclamation!" do
144
+ obj = KlassOne.new
145
+ assert obj.respond_to?(:exclamation_exclamation_base_key)
146
+ assert obj.respond_to?(:exclamation_exclamation_perma_cache_key)
147
+ assert obj.respond_to?(:exclamation_exclamation!)
148
+ assert obj.respond_to?(:exclamation_exclamation_get_perma_cache)
149
+ assert obj.respond_to?(:exclamation_with_perma_cache!)
150
+ assert obj.respond_to?(:exclamation_without_perma_cache!)
151
+ assert obj.respond_to?(:exclamation_exclamation_was_rebuilt?)
114
152
  end
115
153
 
116
154
  should "calling #method1 should write and return the result if the cache is empty" do
@@ -1,9 +1,10 @@
1
1
  require "rubygems"
2
- require 'test/unit'
2
+ require 'bundler/setup'
3
+
4
+ require 'byebug'
5
+ require 'minitest/autorun'
6
+ require 'mocha/mini_test'
3
7
  require 'shoulda'
4
- require 'mocha/test_unit'
5
- require 'debugger'
6
8
 
7
- require 'bundler/setup'
8
9
  require 'perma_cache'
9
10
 
metadata CHANGED
@@ -1,97 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perma_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Sharpe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-29 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
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.3'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: '1.3'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ! '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: shoulda
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: mocha
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
- - !ruby/object:Gem::Dependency
84
- name: debugger
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ! '>='
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ! '>='
24
+ - - ">="
95
25
  - !ruby/object:Gem::Version
96
26
  version: '0'
97
27
  description: It's a perma cache, duh
@@ -101,10 +31,11 @@ executables: []
101
31
  extensions: []
102
32
  extra_rdoc_files: []
103
33
  files:
104
- - .gitignore
105
- - .ruby-gemset
106
- - .ruby-version
34
+ - ".gitignore"
35
+ - ".ruby-gemset"
36
+ - ".ruby-version"
107
37
  - Gemfile
38
+ - Gemfile.lock
108
39
  - LICENSE.txt
109
40
  - README.md
110
41
  - Rakefile
@@ -123,17 +54,17 @@ require_paths:
123
54
  - lib
124
55
  required_ruby_version: !ruby/object:Gem::Requirement
125
56
  requirements:
126
- - - ! '>='
57
+ - - ">="
127
58
  - !ruby/object:Gem::Version
128
59
  version: '0'
129
60
  required_rubygems_version: !ruby/object:Gem::Requirement
130
61
  requirements:
131
- - - ! '>='
62
+ - - ">="
132
63
  - !ruby/object:Gem::Version
133
64
  version: '0'
134
65
  requirements: []
135
66
  rubyforge_project:
136
- rubygems_version: 2.2.2
67
+ rubygems_version: 2.4.6
137
68
  signing_key:
138
69
  specification_version: 4
139
70
  summary: It's a perma cache, duh