arid_cache 1.3.6 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +14 -7
- data/Gemfile.lock +40 -18
- data/Gemfile.rails2 +25 -0
- data/Gemfile.rails2.lock +70 -0
- data/Gemfile.rails3 +25 -0
- data/Gemfile.rails3.lock +80 -0
- data/README.rdoc +13 -7
- data/Rakefile +5 -11
- data/VERSION +1 -1
- data/arid_cache.gemspec +7 -2
- data/init.rb +1 -1
- data/lib/arid_cache.rb +9 -6
- data/lib/arid_cache/cache_proxy.rb +2 -2
- data/lib/arid_cache/cache_proxy/options.rb +20 -3
- data/lib/arid_cache/cache_proxy/result_processor.rb +44 -10
- data/lib/arid_cache/cache_proxy/utilities.rb +11 -6
- data/lib/arid_cache/framework.rb +22 -0
- data/spec/arid_cache/arid_cache_spec.rb +1 -1
- data/spec/arid_cache/cache_proxy/options_spec.rb +41 -13
- data/spec/arid_cache/cache_proxy/result_processor_spec.rb +43 -1
- data/spec/arid_cache/cache_proxy_spec.rb +1 -1
- data/spec/spec_helper.rb +16 -6
- data/spec/support/matchers.rb +2 -2
- data/test/arid_cache_test.rb +1 -1
- data/test/console +10 -2
- data/test/lib/add_query_counting_to_active_record.rb +2 -0
- data/test/lib/mock_rails.rb +7 -1
- data/test/lib/models/company.rb +2 -1
- data/test/lib/models/user.rb +7 -7
- data/test/test_helper.rb +12 -4
- metadata +10 -5
data/Gemfile
CHANGED
@@ -1,18 +1,25 @@
|
|
1
1
|
# A sample Gemfile
|
2
2
|
source "http://rubygems.org"
|
3
3
|
|
4
|
-
gem 'activerecord', '=
|
5
|
-
gem 'activesupport', '=
|
4
|
+
gem 'activerecord', '=3.0.6', :require => 'active_record'
|
5
|
+
gem 'activesupport', '=3.0.6', :require => 'active_support'
|
6
6
|
gem 'sqlite3-ruby', '=1.3.1'
|
7
|
-
|
8
|
-
gem 'will_paginate', '=2.3.15'
|
7
|
+
gem "will_paginate", "~> 3.0.pre2"
|
9
8
|
gem 'jeweler', '=1.4.0'
|
10
9
|
|
11
10
|
gem 'ruby-debug', '=0.10.3'
|
12
11
|
gem 'ruby-debug-base', '=0.10.3'
|
13
12
|
gem 'machinist', '=1.0.6'
|
14
|
-
gem
|
15
|
-
gem 'rspec', '~>1.3.1', :require => 'spec'
|
13
|
+
gem "rspec", "~> 2"
|
16
14
|
gem 'test-unit', '=1.2.3'
|
17
|
-
gem 'arid_cache', :path => "./"
|
18
15
|
gem 'rr', '~>1.0.2'
|
16
|
+
|
17
|
+
gem 'i18n', :require => 'I18n' # required by Faker
|
18
|
+
gem 'faker', '=0.9.5'
|
19
|
+
|
20
|
+
|
21
|
+
# Required by the ActiveSupport::Cache::FileStore.
|
22
|
+
# Get a "no such file to load -- rack/utils" otherwise.
|
23
|
+
gem 'rack'
|
24
|
+
|
25
|
+
gem 'arid_cache', :path => "./"
|
data/Gemfile.lock
CHANGED
@@ -1,32 +1,51 @@
|
|
1
1
|
PATH
|
2
|
-
remote:
|
2
|
+
remote: ./
|
3
3
|
specs:
|
4
|
-
arid_cache (1.3.
|
4
|
+
arid_cache (1.3.6)
|
5
5
|
will_paginate
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
|
11
|
-
activesupport (=
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
activemodel (3.0.6)
|
11
|
+
activesupport (= 3.0.6)
|
12
|
+
builder (~> 2.1.2)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
activerecord (3.0.6)
|
15
|
+
activemodel (= 3.0.6)
|
16
|
+
activesupport (= 3.0.6)
|
17
|
+
arel (~> 2.0.2)
|
18
|
+
tzinfo (~> 0.3.23)
|
19
|
+
activesupport (3.0.6)
|
20
|
+
arel (2.0.9)
|
21
|
+
builder (2.1.2)
|
22
|
+
columnize (0.3.2)
|
23
|
+
diff-lcs (1.1.2)
|
24
|
+
faker (0.9.5)
|
25
|
+
i18n (~> 0.4)
|
26
|
+
gemcutter (0.7.0)
|
16
27
|
git (1.2.5)
|
17
|
-
hoe (2.
|
28
|
+
hoe (2.9.4)
|
18
29
|
rake (>= 0.8.7)
|
19
|
-
|
30
|
+
i18n (0.5.0)
|
20
31
|
jeweler (1.4.0)
|
21
32
|
gemcutter (>= 0.1.0)
|
22
33
|
git (>= 1.2.5)
|
23
34
|
rubyforge (>= 2.0.0)
|
24
|
-
json_pure (1.
|
35
|
+
json_pure (1.5.1)
|
25
36
|
linecache (0.43)
|
26
37
|
machinist (1.0.6)
|
38
|
+
rack (1.2.2)
|
27
39
|
rake (0.8.7)
|
28
40
|
rr (1.0.2)
|
29
|
-
rspec (
|
41
|
+
rspec (2.5.0)
|
42
|
+
rspec-core (~> 2.5.0)
|
43
|
+
rspec-expectations (~> 2.5.0)
|
44
|
+
rspec-mocks (~> 2.5.0)
|
45
|
+
rspec-core (2.5.1)
|
46
|
+
rspec-expectations (2.5.0)
|
47
|
+
diff-lcs (~> 1.1.2)
|
48
|
+
rspec-mocks (2.5.0)
|
30
49
|
ruby-debug (0.10.3)
|
31
50
|
columnize (>= 0.1)
|
32
51
|
ruby-debug-base (~> 0.10.3.0)
|
@@ -37,22 +56,25 @@ GEM
|
|
37
56
|
sqlite3-ruby (1.3.1)
|
38
57
|
test-unit (1.2.3)
|
39
58
|
hoe (>= 1.5.1)
|
40
|
-
|
59
|
+
tzinfo (0.3.26)
|
60
|
+
will_paginate (3.0.pre2)
|
41
61
|
|
42
62
|
PLATFORMS
|
43
63
|
ruby
|
44
64
|
|
45
65
|
DEPENDENCIES
|
46
|
-
activerecord (=
|
47
|
-
activesupport (=
|
66
|
+
activerecord (= 3.0.6)
|
67
|
+
activesupport (= 3.0.6)
|
48
68
|
arid_cache!
|
49
|
-
faker (= 0.
|
69
|
+
faker (= 0.9.5)
|
70
|
+
i18n
|
50
71
|
jeweler (= 1.4.0)
|
51
72
|
machinist (= 1.0.6)
|
73
|
+
rack
|
52
74
|
rr (~> 1.0.2)
|
53
|
-
rspec (~>
|
75
|
+
rspec (~> 2)
|
54
76
|
ruby-debug (= 0.10.3)
|
55
77
|
ruby-debug-base (= 0.10.3)
|
56
78
|
sqlite3-ruby (= 1.3.1)
|
57
79
|
test-unit (= 1.2.3)
|
58
|
-
will_paginate (
|
80
|
+
will_paginate (~> 3.0.pre2)
|
data/Gemfile.rails2
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# A sample Gemfile
|
2
|
+
source "http://rubygems.org"
|
3
|
+
|
4
|
+
gem 'activerecord', '2.3.11'
|
5
|
+
gem 'activesupport', '2.3.11', :require => 'active_support'
|
6
|
+
gem 'sqlite3-ruby', '1.3.1'
|
7
|
+
gem "will_paginate", "2.3.15"
|
8
|
+
gem 'jeweler', '1.4.0'
|
9
|
+
|
10
|
+
gem 'ruby-debug', '0.10.3'
|
11
|
+
gem 'ruby-debug-base', '0.10.3'
|
12
|
+
gem 'machinist', '1.0.6'
|
13
|
+
gem "rspec", "~> 2"
|
14
|
+
gem 'test-unit', '1.2.3'
|
15
|
+
gem 'rr', '~>1.0.2'
|
16
|
+
|
17
|
+
gem 'i18n', :require => 'I18n' # required by Faker
|
18
|
+
gem 'faker', '0.9.5'
|
19
|
+
|
20
|
+
|
21
|
+
# Required by the ActiveSupport::Cache::FileStore.
|
22
|
+
# Get a "no such file to load -- rack/utils" otherwise.
|
23
|
+
gem 'rack'
|
24
|
+
|
25
|
+
gem 'arid_cache', :path => "./"
|
data/Gemfile.rails2.lock
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ./
|
3
|
+
specs:
|
4
|
+
arid_cache (1.3.6)
|
5
|
+
will_paginate
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activerecord (2.3.11)
|
11
|
+
activesupport (= 2.3.11)
|
12
|
+
activesupport (2.3.11)
|
13
|
+
columnize (0.3.2)
|
14
|
+
diff-lcs (1.1.2)
|
15
|
+
faker (0.9.5)
|
16
|
+
i18n (~> 0.4)
|
17
|
+
gemcutter (0.7.0)
|
18
|
+
git (1.2.5)
|
19
|
+
hoe (2.9.4)
|
20
|
+
rake (>= 0.8.7)
|
21
|
+
i18n (0.5.0)
|
22
|
+
jeweler (1.4.0)
|
23
|
+
gemcutter (>= 0.1.0)
|
24
|
+
git (>= 1.2.5)
|
25
|
+
rubyforge (>= 2.0.0)
|
26
|
+
json_pure (1.5.1)
|
27
|
+
linecache (0.43)
|
28
|
+
machinist (1.0.6)
|
29
|
+
rack (1.2.2)
|
30
|
+
rake (0.8.7)
|
31
|
+
rr (1.0.2)
|
32
|
+
rspec (2.5.0)
|
33
|
+
rspec-core (~> 2.5.0)
|
34
|
+
rspec-expectations (~> 2.5.0)
|
35
|
+
rspec-mocks (~> 2.5.0)
|
36
|
+
rspec-core (2.5.1)
|
37
|
+
rspec-expectations (2.5.0)
|
38
|
+
diff-lcs (~> 1.1.2)
|
39
|
+
rspec-mocks (2.5.0)
|
40
|
+
ruby-debug (0.10.3)
|
41
|
+
columnize (>= 0.1)
|
42
|
+
ruby-debug-base (~> 0.10.3.0)
|
43
|
+
ruby-debug-base (0.10.3)
|
44
|
+
linecache (>= 0.3)
|
45
|
+
rubyforge (2.0.4)
|
46
|
+
json_pure (>= 1.1.7)
|
47
|
+
sqlite3-ruby (1.3.1)
|
48
|
+
test-unit (1.2.3)
|
49
|
+
hoe (>= 1.5.1)
|
50
|
+
will_paginate (2.3.15)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
activerecord (= 2.3.11)
|
57
|
+
activesupport (= 2.3.11)
|
58
|
+
arid_cache!
|
59
|
+
faker (= 0.9.5)
|
60
|
+
i18n
|
61
|
+
jeweler (= 1.4.0)
|
62
|
+
machinist (= 1.0.6)
|
63
|
+
rack
|
64
|
+
rr (~> 1.0.2)
|
65
|
+
rspec (~> 2)
|
66
|
+
ruby-debug (= 0.10.3)
|
67
|
+
ruby-debug-base (= 0.10.3)
|
68
|
+
sqlite3-ruby (= 1.3.1)
|
69
|
+
test-unit (= 1.2.3)
|
70
|
+
will_paginate (= 2.3.15)
|
data/Gemfile.rails3
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# A sample Gemfile
|
2
|
+
source "http://rubygems.org"
|
3
|
+
|
4
|
+
gem 'activerecord', '=3.0.6', :require => 'active_record'
|
5
|
+
gem 'activesupport', '=3.0.6', :require => 'active_support'
|
6
|
+
gem 'sqlite3-ruby', '=1.3.1'
|
7
|
+
gem "will_paginate", "~> 3.0.pre2"
|
8
|
+
gem 'jeweler', '=1.4.0'
|
9
|
+
|
10
|
+
gem 'ruby-debug', '=0.10.3'
|
11
|
+
gem 'ruby-debug-base', '=0.10.3'
|
12
|
+
gem 'machinist', '=1.0.6'
|
13
|
+
gem "rspec", "~> 2"
|
14
|
+
gem 'test-unit', '=1.2.3'
|
15
|
+
gem 'rr', '~>1.0.2'
|
16
|
+
|
17
|
+
gem 'i18n', :require => 'I18n' # required by Faker
|
18
|
+
gem 'faker', '=0.9.5'
|
19
|
+
|
20
|
+
|
21
|
+
# Required by the ActiveSupport::Cache::FileStore.
|
22
|
+
# Get a "no such file to load -- rack/utils" otherwise.
|
23
|
+
gem 'rack'
|
24
|
+
|
25
|
+
gem 'arid_cache', :path => "./"
|
data/Gemfile.rails3.lock
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ./
|
3
|
+
specs:
|
4
|
+
arid_cache (1.3.6)
|
5
|
+
will_paginate
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (3.0.6)
|
11
|
+
activesupport (= 3.0.6)
|
12
|
+
builder (~> 2.1.2)
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
activerecord (3.0.6)
|
15
|
+
activemodel (= 3.0.6)
|
16
|
+
activesupport (= 3.0.6)
|
17
|
+
arel (~> 2.0.2)
|
18
|
+
tzinfo (~> 0.3.23)
|
19
|
+
activesupport (3.0.6)
|
20
|
+
arel (2.0.9)
|
21
|
+
builder (2.1.2)
|
22
|
+
columnize (0.3.2)
|
23
|
+
diff-lcs (1.1.2)
|
24
|
+
faker (0.9.5)
|
25
|
+
i18n (~> 0.4)
|
26
|
+
gemcutter (0.7.0)
|
27
|
+
git (1.2.5)
|
28
|
+
hoe (2.9.4)
|
29
|
+
rake (>= 0.8.7)
|
30
|
+
i18n (0.5.0)
|
31
|
+
jeweler (1.4.0)
|
32
|
+
gemcutter (>= 0.1.0)
|
33
|
+
git (>= 1.2.5)
|
34
|
+
rubyforge (>= 2.0.0)
|
35
|
+
json_pure (1.5.1)
|
36
|
+
linecache (0.43)
|
37
|
+
machinist (1.0.6)
|
38
|
+
rack (1.2.2)
|
39
|
+
rake (0.8.7)
|
40
|
+
rr (1.0.2)
|
41
|
+
rspec (2.5.0)
|
42
|
+
rspec-core (~> 2.5.0)
|
43
|
+
rspec-expectations (~> 2.5.0)
|
44
|
+
rspec-mocks (~> 2.5.0)
|
45
|
+
rspec-core (2.5.1)
|
46
|
+
rspec-expectations (2.5.0)
|
47
|
+
diff-lcs (~> 1.1.2)
|
48
|
+
rspec-mocks (2.5.0)
|
49
|
+
ruby-debug (0.10.3)
|
50
|
+
columnize (>= 0.1)
|
51
|
+
ruby-debug-base (~> 0.10.3.0)
|
52
|
+
ruby-debug-base (0.10.3)
|
53
|
+
linecache (>= 0.3)
|
54
|
+
rubyforge (2.0.4)
|
55
|
+
json_pure (>= 1.1.7)
|
56
|
+
sqlite3-ruby (1.3.1)
|
57
|
+
test-unit (1.2.3)
|
58
|
+
hoe (>= 1.5.1)
|
59
|
+
tzinfo (0.3.26)
|
60
|
+
will_paginate (3.0.pre2)
|
61
|
+
|
62
|
+
PLATFORMS
|
63
|
+
ruby
|
64
|
+
|
65
|
+
DEPENDENCIES
|
66
|
+
activerecord (= 3.0.6)
|
67
|
+
activesupport (= 3.0.6)
|
68
|
+
arid_cache!
|
69
|
+
faker (= 0.9.5)
|
70
|
+
i18n
|
71
|
+
jeweler (= 1.4.0)
|
72
|
+
machinist (= 1.0.6)
|
73
|
+
rack
|
74
|
+
rr (~> 1.0.2)
|
75
|
+
rspec (~> 2)
|
76
|
+
ruby-debug (= 0.10.3)
|
77
|
+
ruby-debug-base (= 0.10.3)
|
78
|
+
sqlite3-ruby (= 1.3.1)
|
79
|
+
test-unit (= 1.2.3)
|
80
|
+
will_paginate (~> 3.0.pre2)
|
data/README.rdoc
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
= AridCache
|
2
2
|
|
3
|
-
AridCache
|
3
|
+
AridCache now supports Rails 3!
|
4
|
+
|
5
|
+
AridCache is a caching framework written in Ruby which makes caching easy and effective. AridCache supports Rails 2 and 3 and provides caching on any ActiveRecord class or instance method right out of the box. AridCache keeps caching logic in your cache configuration rather than dispersed throughout your code, and makes your code easy to manage by making cached calls explicit.
|
4
6
|
|
5
7
|
AridCache supports caching large, expensive ActiveRecord collections by caching only the model IDs, provides efficient in-memory pagination of your cached collections, and gives you collection counts for free. Non-ActiveRecord collection data is cached unchanged allowing you to cache the results of anything simply by prepending your method call with <tt>cached_</tt>.
|
6
8
|
|
7
|
-
AridCache simplifies caching by supporting auto-expiring cache keys - as well as common options like <tt>:expires_in</tt> - and provides methods to help you manage your caches.
|
9
|
+
AridCache simplifies caching by supporting auto-expiring cache keys - as well as common options like <tt>:expires_in</tt> - and provides methods to help you manage your caches. AridCache now supports counts, limits, pagination and in-memory sorting of any cached Enumerable, as well as Proxies, a powerful new feature which gives you total control over your cached data.
|
8
10
|
|
9
11
|
== Changes
|
10
12
|
|
11
|
-
* v1.
|
13
|
+
* v1.4.0: Rails 3 fully supported!
|
14
|
+
* v1.3.5: Backwards-compatibility fixes
|
12
15
|
* v1.3.4: Inherited cache configurations: Cache options and cache blocks are inherited from superclasses
|
13
16
|
* v1.3.2: <tt>AridCache.raw_with_options</tt> configuration for better <tt>:raw</tt> handling on cached ActiveRecord collections
|
14
17
|
* v1.3.1: Proxy support which allow you to control how your objects get serialized and unserialized
|
@@ -41,8 +44,9 @@ Then
|
|
41
44
|
== Features
|
42
45
|
|
43
46
|
* Include the AridCache module in any Class
|
44
|
-
* <b>Rails 2 & 3
|
45
|
-
*
|
47
|
+
* <b>Rails 2 & 3 supported</b> with automatic ActiveRecord::Base integration.
|
48
|
+
* When using ActiveRecord 3, returns lazy-loaded result sets.
|
49
|
+
* Auto-generated, namespaced cache keys
|
46
50
|
* <b>auto-expiring cache keys</b> - your cache expires when the updated_at timestamp changes
|
47
51
|
* Supports *limits*, *ordering* & *pagination* of cached Enumerables and ActiveRecord collections
|
48
52
|
* Define caches and their options on your class using +instance_caches+ and +class_caches+
|
@@ -508,8 +512,9 @@ Here +cached_actual_name+ is using its own <tt>:limit => 1</tt> but since no anc
|
|
508
512
|
|
509
513
|
== Compatibility
|
510
514
|
|
511
|
-
|
512
|
-
|
515
|
+
Ruby: 1.8.6, 1.8.7, REE 1.8.7 and 1.9.1.
|
516
|
+
Rails: 2.3.8, 2.3.11, 3.0.0, Rails 3.0.5, 3.0.6
|
517
|
+
WillPaginate: 2.3.15 (Rails 2), 3.0.pre2 (Rails 3)
|
513
518
|
|
514
519
|
For Ruby < 1.8.7 you probably want to include the following to extend the Array class with a <tt>count</tt> method. Otherwise your <tt>cached_<key>_count</tt> calls probably won't work:
|
515
520
|
|
@@ -525,6 +530,7 @@ For Ruby < 1.8.7 you probably want to include the following to extend the Array
|
|
525
530
|
2. <b>You can't cache polymorphic arrays</b> e.g. [#<User id: 1>, #<Pet id: 5>] because it expects all ActiveRecords to be of the same class. If you need polymorphism consider using a proxy and do the record-loading yourself.
|
526
531
|
3. Rails ActiveRecord (or SQL) has a quirk where if you pass an +offset+ without a +limit+ the +offset+ is ignored. AridCache fixes this unexpected behaviour by including a +limit+ on its queries.
|
527
532
|
4. When you use the <tt>:order</tt> option with a cached ActiveRecord collection we have to go to the database to order. So we also do pagination and limiting there because we want to retrieve as few records as possible. So we use WillPaginate's ActiveRecord::Base#paginate method. Unfortunately if you pass <tt>:limit</tt> or <tt>:offset</tt> in addition to your pagination options, the limit and offset are ignored. This is not the behaviour when interacting with other cached types. In that case we apply the order, then the limits and finally the pagination, which is what you would expect.
|
533
|
+
5. There is a {bug in ActiveRecord 3's AREL}[http://breakthebit.org/post/3487560245/rails-3-arel-count-size-length-weirdness] where calling +count+ or +size+ on an AREL query will cause a </tt>COUNT(*)<tt> to be executed but without applying a +LIMIT+. Calling +length+ works as expected, and returns the number of records that matched the query. So we alias +count+ and +size+ to the +length+ on the AREL object that is returned.
|
528
534
|
|
529
535
|
== Contributors
|
530
536
|
|
data/Rakefile
CHANGED
@@ -27,16 +27,10 @@ rescue LoadError
|
|
27
27
|
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
28
28
|
end
|
29
29
|
|
30
|
-
require
|
31
|
-
|
32
|
-
spec.
|
33
|
-
spec.
|
34
|
-
end
|
35
|
-
|
36
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
37
|
-
spec.libs << 'lib' << 'spec'
|
38
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
39
|
-
spec.rcov = true
|
30
|
+
require "rspec/core/rake_task"
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
spec.rspec_opts = ['--backtrace']
|
40
34
|
end
|
41
35
|
|
42
36
|
require 'rake/testtask'
|
@@ -71,4 +65,4 @@ namespace :release do
|
|
71
65
|
Rake::Task['git:release'].invoke
|
72
66
|
Rake::Task['gemcutter:release'].invoke
|
73
67
|
end
|
74
|
-
end
|
68
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/arid_cache.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{arid_cache}
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Karl Varga"]
|
12
|
-
s.date = %q{2011-04-
|
12
|
+
s.date = %q{2011-04-18}
|
13
13
|
s.description = %q{AridCache makes caching easy and effective. AridCache supports caching on all your model named scopes, class methods and instance methods right out of the box. AridCache prevents caching logic from cluttering your models and clarifies your logic by making explicit calls to cached result sets.
|
14
14
|
AridCache is designed for handling large, expensive ActiveRecord collections but is equally useful for caching anything else as well.
|
15
15
|
}
|
@@ -22,6 +22,10 @@ AridCache is designed for handling large, expensive ActiveRecord collections but
|
|
22
22
|
".gitignore",
|
23
23
|
"Gemfile",
|
24
24
|
"Gemfile.lock",
|
25
|
+
"Gemfile.rails2",
|
26
|
+
"Gemfile.rails2.lock",
|
27
|
+
"Gemfile.rails3",
|
28
|
+
"Gemfile.rails3.lock",
|
25
29
|
"LICENSE",
|
26
30
|
"README.rdoc",
|
27
31
|
"Rakefile",
|
@@ -34,6 +38,7 @@ AridCache is designed for handling large, expensive ActiveRecord collections but
|
|
34
38
|
"lib/arid_cache/cache_proxy/options.rb",
|
35
39
|
"lib/arid_cache/cache_proxy/result_processor.rb",
|
36
40
|
"lib/arid_cache/cache_proxy/utilities.rb",
|
41
|
+
"lib/arid_cache/framework.rb",
|
37
42
|
"lib/arid_cache/helpers.rb",
|
38
43
|
"lib/arid_cache/inflector.rb",
|
39
44
|
"lib/arid_cache/inflector/inflections.rb",
|
data/init.rb
CHANGED
data/lib/arid_cache.rb
CHANGED
@@ -7,11 +7,16 @@ require 'arid_cache/active_record'
|
|
7
7
|
require 'arid_cache/cache_proxy'
|
8
8
|
require 'arid_cache/railtie' if defined?(Rails)
|
9
9
|
require 'arid_cache/inflector'
|
10
|
+
require 'arid_cache/framework'
|
10
11
|
|
11
12
|
module AridCache
|
12
13
|
extend AridCache::Helpers
|
13
14
|
Error = Class.new(StandardError) #:nodoc:
|
14
15
|
|
16
|
+
class << self
|
17
|
+
attr_accessor :framework
|
18
|
+
end
|
19
|
+
|
15
20
|
# Set to true to make the :raw option return ids after applying options to them.
|
16
21
|
# The deprecated behaviour is to return a CachedResult and ignore all options.
|
17
22
|
def self.raw_with_options=(value)
|
@@ -49,11 +54,9 @@ module AridCache
|
|
49
54
|
base.send(:include, AridCache::ActiveRecord)
|
50
55
|
end
|
51
56
|
|
52
|
-
|
53
|
-
|
54
|
-
# This method is called by `init.rb`,
|
55
|
-
# which is run by Rails on startup.
|
56
|
-
def self.init_rails
|
57
|
-
::ActiveRecord::Base.send(:include, AridCache::ActiveRecord)
|
57
|
+
def self.version
|
58
|
+
@version ||= File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).strip
|
58
59
|
end
|
60
|
+
|
61
|
+
self.framework = AridCache::Framework.new
|
59
62
|
end
|
@@ -29,7 +29,7 @@ module AridCache
|
|
29
29
|
|
30
30
|
OPTIONS_FOR_PAGINATE = [:page, :per_page, :total_entries, :finder]
|
31
31
|
OPTIONS_FOR_CACHE_PROXY = [:raw, :clear]
|
32
|
-
OPTIONS_FOR_FIND = [ :conditions, :include, :joins, :limit, :offset, :order, :select, :readonly, :group, :having, :from, :lock ]
|
32
|
+
OPTIONS_FOR_FIND = [ :conditions, :where, :include, :includes, :joins, :limit, :offset, :order, :select, :readonly, :group, :having, :from, :lock ]
|
33
33
|
OPTIONS_FOR_CACHE = [ :expires_in ]
|
34
34
|
OPTIONS_FOR_CACHE_KEY = [ :auto_expire ]
|
35
35
|
|
@@ -69,7 +69,7 @@ module AridCache
|
|
69
69
|
# Combine the options from the blueprint with the options for this call
|
70
70
|
opts = opts.symbolize_keys
|
71
71
|
@options = Options.new(@blueprint.nil? ? opts : @blueprint.opts.merge(opts))
|
72
|
-
@options[:
|
72
|
+
@options[:receiver_klass] = Utilities.object_class(receiver)
|
73
73
|
@cache_key = @receiver.arid_cache_key(@method, @options.opts_for_cache_key)
|
74
74
|
end
|
75
75
|
|
@@ -7,13 +7,18 @@ module AridCache
|
|
7
7
|
self.merge!(opts)
|
8
8
|
end
|
9
9
|
|
10
|
-
# Filter options for paginate.
|
10
|
+
# Filter options for paginate.
|
11
11
|
# Set total_entries to +records.size+ if +records+ is supplied
|
12
|
+
# Get the :per_page value from the +result_klass+, or +receiver_klass+ if its set
|
13
|
+
# and responds to +per_page+. Otherwise default to 30 results per page.
|
12
14
|
def opts_for_paginate(records=nil)
|
13
15
|
paginate_opts = reject { |k,v| !OPTIONS_FOR_PAGINATE.include?(k) }
|
14
16
|
paginate_opts[:finder] = :find_all_by_id unless paginate_opts.include?(:finder)
|
15
|
-
|
16
|
-
|
17
|
+
unless paginate_opts.key?(:per_page)
|
18
|
+
klass = values_at(:result_klass, :receiver_klass).find do |klass|
|
19
|
+
klass.respond_to?(:per_page)
|
20
|
+
end
|
21
|
+
paginate_opts[:per_page] = klass && klass.per_page || 30
|
17
22
|
end
|
18
23
|
paginate_opts[:total_entries] = records.size unless records.nil?
|
19
24
|
paginate_opts
|
@@ -76,6 +81,18 @@ module AridCache
|
|
76
81
|
def deprecated_raw?
|
77
82
|
!!(raw? && !AridCache.raw_with_options)
|
78
83
|
end
|
84
|
+
|
85
|
+
# Returns the class of the receiver object or raises IndexError if the
|
86
|
+
# receiver klass has not been set.
|
87
|
+
def receiver_klass
|
88
|
+
fetch :receiver_klass
|
89
|
+
end
|
90
|
+
|
91
|
+
# Returns the class of the result records or raises IndexError if the
|
92
|
+
# result klass has not been set.
|
93
|
+
def result_klass
|
94
|
+
fetch :result_klass
|
95
|
+
end
|
79
96
|
end
|
80
97
|
end
|
81
98
|
end
|
@@ -42,11 +42,11 @@ module AridCache
|
|
42
42
|
# Return true if the result is an enumerable and the first item is
|
43
43
|
# an active record.
|
44
44
|
def is_activerecord?
|
45
|
-
is_enumerable? && @result.first.is_a?(::ActiveRecord::Base)
|
45
|
+
AridCache.framework.active_record? && is_enumerable? && @result.first.is_a?(::ActiveRecord::Base)
|
46
46
|
end
|
47
47
|
|
48
48
|
def is_activerecord_reflection?
|
49
|
-
@result.respond_to?(:proxy_reflection) || @result.respond_to?(:proxy_options)
|
49
|
+
AridCache.framework.active_record? && (@result.respond_to?(:proxy_reflection) || @result.respond_to?(:proxy_options) || (AridCache.framework.active_record?(3) && @result.is_a?(::ActiveRecord::Relation)))
|
50
50
|
end
|
51
51
|
|
52
52
|
def is_cached_result?
|
@@ -64,7 +64,7 @@ module AridCache
|
|
64
64
|
if is_activerecord_reflection?
|
65
65
|
@result = @result.collect { |r| r } # force it to load
|
66
66
|
end
|
67
|
-
|
67
|
+
@options.receiver_klass.send(@options[:proxy], @result)
|
68
68
|
elsif is_activerecord_reflection?
|
69
69
|
|
70
70
|
if @options.count_only?
|
@@ -108,7 +108,7 @@ module AridCache
|
|
108
108
|
end
|
109
109
|
filtered = filter_results(results)
|
110
110
|
if @cached.nil? && !@options.raw?
|
111
|
-
proxy_result =
|
111
|
+
proxy_result = @options.receiver_klass.send(@options[:proxy], filtered)
|
112
112
|
if filtered.is_a?(WillPaginate::Collection) && proxy_result.is_a?(Enumerable)
|
113
113
|
filtered.replace(proxy_result)
|
114
114
|
else
|
@@ -213,6 +213,8 @@ module AridCache
|
|
213
213
|
# If an arder is specified then
|
214
214
|
# order, limit and paginate in the database.
|
215
215
|
def fetch_activerecords(records)
|
216
|
+
@options[:result_klass] = result_klass
|
217
|
+
|
216
218
|
if records.empty?
|
217
219
|
if @options.paginate?
|
218
220
|
return records.paginate(@options.opts_for_paginate(records))
|
@@ -221,26 +223,58 @@ module AridCache
|
|
221
223
|
end
|
222
224
|
end
|
223
225
|
|
224
|
-
ids = records.first.is_a?(ActiveRecord) ? records.collect { |record| record[:id] } : records
|
226
|
+
ids = AridCache.framework.active_record? && records.first.is_a?(ActiveRecord) ? records.collect { |record| record[:id] } : records
|
225
227
|
find_opts = @options.opts_for_find(ids)
|
226
228
|
if order_in_database?
|
227
229
|
if @options.paginate?
|
228
|
-
|
229
|
-
|
230
|
+
if AridCache.framework.active_record?(3)
|
231
|
+
page_opts = @options.opts_for_paginate(ids)
|
232
|
+
WillPaginate::Collection.create(page_opts[:page], page_opts[:per_page], page_opts[:total_entries]) do |pager|
|
233
|
+
result = find_all_by_id(ids, find_opts.merge(:limit => pager.per_page, :offset => pager.offset))
|
234
|
+
pager.replace(result)
|
235
|
+
end
|
236
|
+
else
|
237
|
+
find_opts.merge!(@options.opts_for_paginate(ids))
|
238
|
+
result_klass.paginate(ids, find_opts)
|
239
|
+
end
|
230
240
|
else
|
231
|
-
|
241
|
+
find_all_by_id(ids, find_opts)
|
232
242
|
end
|
233
243
|
else
|
234
244
|
# Limits will have already been applied, remove them from the options for find.
|
235
245
|
[:offset, :limit].each { |key| find_opts.delete(key) }
|
236
|
-
result =
|
246
|
+
result = find_all_by_id(ids, find_opts)
|
237
247
|
records.is_a?(::WillPaginate::Collection) ? records.replace(result) : result
|
238
248
|
end
|
239
249
|
end
|
240
250
|
|
241
251
|
# Return the klass to use for building results (only applies to ActiveRecord results)
|
252
|
+
# Warning, calling this can trigger Relations/Associations to load.
|
242
253
|
def result_klass
|
243
|
-
is_cached_result? ? @result.klass : (@cached.is_a?(AridCache::CacheProxy::CachedResult) ? @cached.klass :
|
254
|
+
is_cached_result? ? @result.klass : (@cached.is_a?(AridCache::CacheProxy::CachedResult) ? @cached.klass : @options[:receiver_klass])
|
255
|
+
end
|
256
|
+
|
257
|
+
def find_all_by_id(ids, find_opts)
|
258
|
+
if AridCache.framework.active_record?(3)
|
259
|
+
option_map = {
|
260
|
+
:conditions => :where,
|
261
|
+
:include => :includes
|
262
|
+
}
|
263
|
+
query = find_opts.inject(result_klass.scoped) do |scope, pair|
|
264
|
+
key, value = pair
|
265
|
+
key = option_map[key] || key
|
266
|
+
scope.send(key, pair[1])
|
267
|
+
end
|
268
|
+
query = query.scoped.where(Utilities.namespaced_column(:id, result_klass) + ' in (?)', ids)
|
269
|
+
# Fix http://breakthebit.org/post/3487560245/rails-3-arel-count-size-length-weirdness
|
270
|
+
query.class_eval do
|
271
|
+
alias_method :size, :length
|
272
|
+
alias_method :count, :length
|
273
|
+
end
|
274
|
+
query
|
275
|
+
else
|
276
|
+
result_klass.find_all_by_id(ids, find_opts)
|
277
|
+
end
|
244
278
|
end
|
245
279
|
end
|
246
280
|
end
|
@@ -9,12 +9,7 @@ module AridCache
|
|
9
9
|
# supports the ORDER BY FIELD() function. For other databases we use
|
10
10
|
# a CASE statement.
|
11
11
|
def order_by(ids, klass=nil)
|
12
|
-
column =
|
13
|
-
::ActiveRecord::Base.connection.quote_table_name(klass.table_name) + '.id'
|
14
|
-
else
|
15
|
-
"id"
|
16
|
-
end
|
17
|
-
|
12
|
+
column = namespaced_column(:id, klass)
|
18
13
|
if ids.empty?
|
19
14
|
nil
|
20
15
|
elsif ::ActiveRecord::Base.is_mysql_adapter?
|
@@ -26,6 +21,16 @@ module AridCache
|
|
26
21
|
end
|
27
22
|
end
|
28
23
|
|
24
|
+
# Return the column name quoted and namespaced by the table name, if the klass
|
25
|
+
# responds to +table_name+. Otherwise just return the column unchanged.
|
26
|
+
def namespaced_column(column, klass=nil)
|
27
|
+
if klass.respond_to?(:table_name)
|
28
|
+
::ActiveRecord::Base.connection.quote_table_name(klass.table_name) + '.' + column.to_s
|
29
|
+
else
|
30
|
+
column.to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
29
34
|
# Return the object's class or the object if it is a class.
|
30
35
|
def object_class(object)
|
31
36
|
object.is_a?(Class) ? object : object.class
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module AridCache
|
2
|
+
# A class with framework/application related methods like discovering
|
3
|
+
# which version of Rails we are running under.
|
4
|
+
class Framework
|
5
|
+
def active_record?(major=nil)
|
6
|
+
defined?(::ActiveRecord) && (major.nil? || (major && ::ActiveRecord::VERSION::MAJOR == major))
|
7
|
+
end
|
8
|
+
|
9
|
+
# Include framework hooks for Rails
|
10
|
+
#
|
11
|
+
# This method is called by <tt>init.rb</tt>, which is run by Rails on startup.
|
12
|
+
#
|
13
|
+
# Customize rendering. Include custom headers and don't render the layout for AJAX.
|
14
|
+
# Insert the Rack::Ajax middleware to rewrite and handle requests.
|
15
|
+
# Add custom attributes to outgoing links.
|
16
|
+
#
|
17
|
+
# Hooks for Rails 3 are installed using Railties.
|
18
|
+
def init
|
19
|
+
::ActiveRecord::Base.send(:include, AridCache::ActiveRecord) if active_record?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -52,30 +52,52 @@ describe AridCache::CacheProxy::Options do
|
|
52
52
|
|
53
53
|
describe "options for paginate" do
|
54
54
|
before :each do
|
55
|
-
@
|
55
|
+
@receiver_klass = Class.new do
|
56
56
|
def self.per_page; 23; end
|
57
57
|
end
|
58
|
+
@result_klass = Class.new do
|
59
|
+
def self.per_page; 17; end
|
60
|
+
end
|
58
61
|
end
|
59
62
|
|
60
|
-
it "should
|
61
|
-
|
62
|
-
@opts[:per_page].should == 23
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should use the provided per_page value" do
|
66
|
-
@opts = new_options(:result_klass => @result_klass, :per_page => 3).opts_for_paginate
|
67
|
-
@opts[:per_page].should == 3
|
63
|
+
it "total_entries should be nil by default" do
|
64
|
+
new_options.opts_for_paginate[:total_entries].should be_nil
|
68
65
|
end
|
69
66
|
|
70
|
-
it "should set total_entries" do
|
71
|
-
new_options.opts_for_paginate[:total_entries].should
|
72
|
-
@opts = new_options.opts_for_paginate((1..10).to_a)
|
73
|
-
@opts[:total_entries].should == 10
|
67
|
+
it "should set total_entries to the size of the collection" do
|
68
|
+
new_options.opts_for_paginate((1..10).to_a)[:total_entries].should == 10
|
74
69
|
end
|
75
70
|
|
76
71
|
it "should use find_all_by_id as the finder" do
|
77
72
|
new_options.opts_for_paginate[:finder].should == :find_all_by_id
|
78
73
|
end
|
74
|
+
|
75
|
+
it "per_page should default to 30" do
|
76
|
+
new_options.opts_for_paginate[:per_page].should == 30
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should get per_page from the result class" do
|
80
|
+
new_options(:result_klass => @result_klass).opts_for_paginate[:per_page].should == 17
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should get per_page from the receiver class" do
|
84
|
+
new_options(:receiver_klass => @receiver_klass).opts_for_paginate[:per_page].should == 23
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should get per_page from the result class, then the receiver class" do
|
88
|
+
new_options(
|
89
|
+
:result_klass => @result_klass,
|
90
|
+
:receiver_klass => @receiver_klass
|
91
|
+
).opts_for_paginate[:per_page].should == 17
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should use per_page if provided" do
|
95
|
+
new_options(
|
96
|
+
:result_klass => @result_klass,
|
97
|
+
:receiver_klass => @receiver_klass,
|
98
|
+
:per_page => 3
|
99
|
+
).opts_for_paginate[:per_page].should == 3
|
100
|
+
end
|
79
101
|
end
|
80
102
|
|
81
103
|
describe "proxies" do
|
@@ -95,4 +117,10 @@ describe AridCache::CacheProxy::Options do
|
|
95
117
|
new_options(:raw => true).deprecated_raw?.should be_false
|
96
118
|
end
|
97
119
|
end
|
120
|
+
|
121
|
+
describe "receiver_klass" do
|
122
|
+
it "should be the class of the receiver" do
|
123
|
+
new_options(:receiver_klass => User)[:receiver_klass].should be(User)
|
124
|
+
end
|
125
|
+
end
|
98
126
|
end
|
@@ -476,9 +476,51 @@ describe AridCache::CacheProxy::ResultProcessor do
|
|
476
476
|
end
|
477
477
|
|
478
478
|
it "should fall back to the receiver class" do
|
479
|
-
cache = new_result(@obj, :
|
479
|
+
cache = new_result(@obj, :receiver_klass => User).to_cache
|
480
480
|
cache.klass.should be(User)
|
481
481
|
end
|
482
482
|
end
|
483
483
|
end
|
484
|
+
|
485
|
+
describe "find_all_by_id" do
|
486
|
+
before :each do
|
487
|
+
@user = User.make
|
488
|
+
@user.companies << Company.make
|
489
|
+
@user.companies << Company.make
|
490
|
+
Company.make # there must be more than 2 companies for it to fail
|
491
|
+
@cached = AridCache::CacheProxy::CachedResult.new
|
492
|
+
@cached.ids = @user.companies.reverse.map(&:id)
|
493
|
+
@cached.klass = Company
|
494
|
+
@result = new_result(@cached)
|
495
|
+
mock.proxy(@result).find_all_by_id(@cached.ids, anything)
|
496
|
+
end
|
497
|
+
|
498
|
+
it "should maintain order" do
|
499
|
+
@result.to_result.should == @user.companies.reverse
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
describe "result_klass" do
|
504
|
+
before :each do
|
505
|
+
@obj = Class.new do
|
506
|
+
def self.per_page; 11; end
|
507
|
+
end.new
|
508
|
+
@options = AridCache::CacheProxy::Options.new(:receiver_klass => @obj.class)
|
509
|
+
@result = new_result(@obj, @options)
|
510
|
+
end
|
511
|
+
|
512
|
+
it "the mock class should define per_page" do
|
513
|
+
@obj.class.per_page.should == 11
|
514
|
+
end
|
515
|
+
|
516
|
+
it "should be the class of the receiver object" do
|
517
|
+
@result.send(:result_klass).should == @obj.class
|
518
|
+
end
|
519
|
+
|
520
|
+
it "should be set on the options when fetch_activerecords is called" do
|
521
|
+
@options[:result_klass].should == nil
|
522
|
+
@result.send(:fetch_activerecords, [])
|
523
|
+
@options[:result_klass].should be(@obj.class)
|
524
|
+
end
|
525
|
+
end
|
484
526
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,29 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
1
3
|
root_path = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
2
4
|
$LOAD_PATH.unshift(File.join(root_path, '/test/lib')) # add test/lib to the load path
|
3
5
|
|
4
6
|
require 'bundler/setup'
|
5
7
|
Bundler.require
|
6
8
|
|
7
|
-
require 'spec/autorun'
|
8
9
|
require 'mock_rails'
|
9
10
|
require 'blueprint'
|
11
|
+
AridCache.framework.init
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
require 'will_paginate/version'
|
14
|
+
if WillPaginate::VERSION::MAJOR < 3
|
15
|
+
WillPaginate.enable_activerecord
|
16
|
+
else
|
17
|
+
require 'will_paginate/collection'
|
18
|
+
require 'will_paginate/finders/active_record'
|
19
|
+
WillPaginate::Finders::ActiveRecord.enable!
|
20
|
+
end
|
13
21
|
|
14
|
-
|
22
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
23
|
+
# in spec/support/ and its subdirectories.
|
24
|
+
Dir[File.join(root_path, "spec/support/**/*.rb")].each {|f| require f}
|
15
25
|
|
16
|
-
|
26
|
+
RSpec.configure do |config|
|
17
27
|
include ActiveRecordQueryMatchers
|
18
28
|
config.mock_with :rr
|
19
29
|
|
@@ -26,4 +36,4 @@ Spec::Runner.configure do |config|
|
|
26
36
|
full_example_description = "#{self.class.description} #{@method_name}"
|
27
37
|
RAILS_DEFAULT_LOGGER.info("\n\n#{full_example_description}\n#{'-' * (full_example_description.length)}")
|
28
38
|
end
|
29
|
-
end
|
39
|
+
end
|
data/spec/support/matchers.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
RSpec::Matchers.define :include_keys do |*expected|
|
2
2
|
|
3
3
|
match do |actual|
|
4
4
|
check_all_present(actual, expected) == []
|
@@ -15,7 +15,7 @@ Spec::Matchers.define :include_keys do |*expected|
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
RSpec::Matchers.define :match_object do |object, *expected_matching_keys|
|
19
19
|
|
20
20
|
match do |actual|
|
21
21
|
check_specified_keys_match(actual, object, expected_matching_keys) == []
|
data/test/arid_cache_test.rb
CHANGED
@@ -299,7 +299,7 @@ class AridCacheTest < ActiveSupport::TestCase
|
|
299
299
|
cached_result.ids.push(24342234, 243234132)
|
300
300
|
Rails.cache.write(key, cached_result)
|
301
301
|
assert_nothing_raised { @user.cached_companies }
|
302
|
-
assert_equal @user.cached_companies, @user.companies
|
302
|
+
assert_equal @user.cached_companies, @user.companies.all
|
303
303
|
end
|
304
304
|
|
305
305
|
test "should not raise an error if all cached ids cannot be found while paginating" do
|
data/test/console
CHANGED
@@ -9,9 +9,17 @@ require 'mock_rails'
|
|
9
9
|
require 'blueprint'
|
10
10
|
require 'irb'
|
11
11
|
|
12
|
-
|
13
|
-
AridCache.init_rails
|
12
|
+
AridCache.framework.init
|
14
13
|
Blueprint.seeds
|
15
14
|
|
15
|
+
require 'will_paginate/version'
|
16
|
+
if WillPaginate::VERSION::MAJOR < 3
|
17
|
+
WillPaginate.enable_activerecord
|
18
|
+
else
|
19
|
+
require 'will_paginate/collection'
|
20
|
+
require 'will_paginate/finders/active_record'
|
21
|
+
WillPaginate::Finders::ActiveRecord.enable!
|
22
|
+
end
|
23
|
+
|
16
24
|
ARGV.clear
|
17
25
|
IRB.start
|
data/test/lib/mock_rails.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'fix_active_support_file_store_expires_in'
|
3
|
+
require 'active_record'
|
3
4
|
|
4
5
|
root_path = File.expand_path(File.join(File.dirname(__FILE__), '../../'))
|
5
6
|
RAILS_DEFAULT_LOGGER = ENV["STDOUT"] ? Logger.new(STDOUT) : Logger.new(File.join(root_path, '/test/log/test.log'))
|
@@ -14,6 +15,11 @@ Rails = Class.new do
|
|
14
15
|
def self.logger
|
15
16
|
return RAILS_DEFAULT_LOGGER
|
16
17
|
end
|
18
|
+
def self.rails3?
|
19
|
+
ActiveRecord::VERSION::STRING.to_i >= 3
|
20
|
+
rescue
|
21
|
+
false
|
22
|
+
end
|
17
23
|
end
|
18
24
|
|
19
25
|
# Set loggers for all frameworks
|
@@ -22,7 +28,7 @@ for framework in ([ :active_record, :action_controller, :action_mailer ])
|
|
22
28
|
framework.to_s.camelize.constantize.const_get("Base").logger = Rails.logger
|
23
29
|
end
|
24
30
|
end
|
25
|
-
ActiveSupport::Dependencies.logger = Rails.logger
|
31
|
+
ActiveSupport::Dependencies.logger = Rails.logger if defined?(ActiveSupport::Dependencies)
|
26
32
|
Rails.cache.logger = Rails.logger
|
27
33
|
|
28
34
|
# Include this last otherwise the logger isn't set properly
|
data/test/lib/models/company.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'arid_cache'
|
2
2
|
|
3
3
|
class Company < ActiveRecord::Base
|
4
|
-
|
4
|
+
|
5
|
+
send(Rails.rails3? ? :scope : :named_scope, :owned, :conditions => ['owner_id is not null'])
|
5
6
|
belongs_to :owner, :class_name => 'User'
|
6
7
|
end
|
data/test/lib/models/user.rb
CHANGED
@@ -3,9 +3,9 @@ require 'arid_cache'
|
|
3
3
|
class User < ActiveRecord::Base
|
4
4
|
has_many :companies, :foreign_key => :owner_id
|
5
5
|
has_many :empty_user_relations # This must always return an empty list
|
6
|
-
named_scope :companies, :joins => :companies
|
7
|
-
named_scope :successful, :joins => :companies, :conditions => 'companies.employees > 50', :group => 'users.id'
|
8
|
-
|
6
|
+
send(Rails.rails3? ? :scope : :named_scope, :companies, :joins => :companies)
|
7
|
+
send(Rails.rails3? ? :scope : :named_scope, :successful, :joins => :companies, :conditions => 'companies.employees > 50', :group => 'users.id')
|
8
|
+
|
9
9
|
def big_companies
|
10
10
|
companies.find :all, :conditions => [ 'employees > 20' ]
|
11
11
|
end
|
@@ -13,7 +13,7 @@ class User < ActiveRecord::Base
|
|
13
13
|
def pet_names
|
14
14
|
['Fuzzy', 'Peachy']
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def method_missing(method, *args)
|
18
18
|
if method == :is_high?
|
19
19
|
true
|
@@ -21,12 +21,12 @@ class User < ActiveRecord::Base
|
|
21
21
|
super
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
|
-
def respond_to?(method)
|
24
|
+
|
25
|
+
def respond_to?(method, include_private=false)
|
26
26
|
if method == :respond_not_overridden
|
27
27
|
true
|
28
28
|
else
|
29
29
|
super
|
30
30
|
end
|
31
31
|
end
|
32
|
-
end
|
32
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -12,9 +12,17 @@ require 'mock_rails'
|
|
12
12
|
require 'blueprint'
|
13
13
|
require 'add_query_counting_to_active_record'
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
require 'will_paginate/version'
|
16
|
+
if WillPaginate::VERSION::MAJOR < 3
|
17
|
+
WillPaginate.enable_activerecord
|
18
|
+
else
|
19
|
+
require 'will_paginate/collection'
|
20
|
+
require 'will_paginate/finders/active_record'
|
21
|
+
WillPaginate::Finders::ActiveRecord.enable!
|
22
|
+
end
|
23
|
+
|
24
|
+
AridCache.framework.init
|
17
25
|
Blueprint.seeds
|
18
26
|
|
19
|
-
ActiveRecord::Base.logger.info("#{"="*25} RUNNING UNIT TESTS #{"="*25}\n\t\t\t#{Time.now.to_s}\n#{"="*70}")
|
20
|
-
Array.class_eval { alias count size } if RUBY_VERSION < '1.8.7'
|
27
|
+
ActiveRecord::Base.logger && ActiveRecord::Base.logger.info("#{"="*25} RUNNING UNIT TESTS #{"="*25}\n\t\t\t#{Time.now.to_s}\n#{"="*70}")
|
28
|
+
Array.class_eval { alias count size } if RUBY_VERSION < '1.8.7'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arid_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 1.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 1.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Karl Varga
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-18 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -90,6 +90,10 @@ files:
|
|
90
90
|
- .gitignore
|
91
91
|
- Gemfile
|
92
92
|
- Gemfile.lock
|
93
|
+
- Gemfile.rails2
|
94
|
+
- Gemfile.rails2.lock
|
95
|
+
- Gemfile.rails3
|
96
|
+
- Gemfile.rails3.lock
|
93
97
|
- LICENSE
|
94
98
|
- README.rdoc
|
95
99
|
- Rakefile
|
@@ -102,6 +106,7 @@ files:
|
|
102
106
|
- lib/arid_cache/cache_proxy/options.rb
|
103
107
|
- lib/arid_cache/cache_proxy/result_processor.rb
|
104
108
|
- lib/arid_cache/cache_proxy/utilities.rb
|
109
|
+
- lib/arid_cache/framework.rb
|
105
110
|
- lib/arid_cache/helpers.rb
|
106
111
|
- lib/arid_cache/inflector.rb
|
107
112
|
- lib/arid_cache/inflector/inflections.rb
|