catche 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -151,7 +151,7 @@ Catche intercepts a cached value and tags this value using the unique identifier
151
151
 
152
152
  ```ruby
153
153
  Catche::Tag::Collect.resource(@task) # { :set => ["tasks_1"], :expire => ["tasks_1"] }
154
- Catche::Tag::Collect.collection_tags(@task, Task) # { :set => ["projects_1_tasks"], :expire => ["tasks", "projects_1_tasks"] }
154
+ Catche::Tag::Collect.collection(@task) # { :set => ["projects_1_tasks"], :expire => ["tasks", "projects_1_tasks"] }
155
155
  ```
156
156
 
157
157
  The tags will point to different cached values, for example pointing to a cached key or a cached filepath.
@@ -1,15 +1,13 @@
1
+ require 'catche/controller/actions'
2
+ require 'catche/controller/pages'
3
+
1
4
  module Catche
2
5
  module Controller
3
6
 
4
7
  extend ActiveSupport::Concern
5
- extend ActiveSupport::Autoload
6
-
7
- eager_autoload do
8
- autoload :Action
9
- autoload :Page
10
- end
11
8
 
12
- include Action, Page
9
+ include Catche::Controller::Actions
10
+ include Catche::Controller::Pages
13
11
 
14
12
  included do
15
13
 
@@ -1,6 +1,6 @@
1
1
  module Catche
2
2
  module Controller
3
- module Action
3
+ module Actions
4
4
 
5
5
  extend ActiveSupport::Concern
6
6
 
@@ -1,6 +1,6 @@
1
1
  module Catche
2
2
  module Controller
3
- module Page
3
+ module Pages
4
4
 
5
5
  extend ActiveSupport::Concern
6
6
 
@@ -9,7 +9,7 @@ module Catche
9
9
  # Caches an action by file
10
10
  # See ActionController `caches_page` for more information
11
11
  #
12
- # catches_action Project, :index
12
+ # catches_page Project, :index
13
13
  def catches_page(model, *args)
14
14
  catche model, *args, :type => :page
15
15
  end
@@ -29,7 +29,6 @@ module Catche
29
29
  super
30
30
  end
31
31
 
32
-
33
32
  end
34
33
  end
35
34
  end
data/lib/catche/expire.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'catche/expire/view'
2
- require 'catche/expire/page'
1
+ require 'catche/expire/views'
2
+ require 'catche/expire/pages'
3
3
 
4
4
  module Catche
5
5
  module Expire
@@ -7,8 +7,8 @@ module Catche
7
7
  class << self
8
8
 
9
9
  def expire!(data)
10
- Catche::Expire::View.expire! *data[:views]
11
- Catche::Expire::Page.expire! *data[:pages]
10
+ Catche::Expire::Views.expire! *data[:views]
11
+ Catche::Expire::Pages.expire! *data[:pages]
12
12
  end
13
13
 
14
14
  end
@@ -1,6 +1,6 @@
1
1
  module Catche
2
2
  module Expire
3
- module Page
3
+ module Pages
4
4
 
5
5
  class << self
6
6
 
@@ -1,6 +1,6 @@
1
1
  module Catche
2
2
  module Expire
3
- module View
3
+ module Views
4
4
 
5
5
  class << self
6
6
 
data/lib/catche/model.rb CHANGED
@@ -1 +1,78 @@
1
- require 'catche/model/base'
1
+ module Catche
2
+ module Model
3
+
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ class_attribute :catche_class,
8
+ :catche_collection_tag,
9
+ :catche_tag_identifier,
10
+ :catche_associations
11
+
12
+ # Expiration callbacks
13
+
14
+ after_update :expire_resource_and_collection!
15
+ after_destroy :expire_resource_and_collection!
16
+
17
+ after_create :expire_collection!
18
+ end
19
+
20
+ module ClassMethods
21
+
22
+ # Configures catche
23
+ #
24
+ # catche :through => :project, :catche_class => Task
25
+ def catche(options={})
26
+ options = {
27
+ :class => self,
28
+ :tag_identifier => :id,
29
+ :collection_tag => nil,
30
+ :associations => [options[:through]].flatten.compact
31
+ }.merge(options)
32
+
33
+ options.each do |key, value|
34
+ self.send("catche_#{key}=", value) if self.respond_to?("catche_#{key}")
35
+ end
36
+
37
+ self.catche_collection_tag ||= self.catche_class.name.downcase.pluralize
38
+ end
39
+
40
+ def catche_reset!
41
+ catche {}
42
+ end
43
+
44
+ def catche_tag
45
+ self.catche_collection_tag || self.name.downcase.pluralize
46
+ end
47
+
48
+ def catche_tag=(value)
49
+ self.catche_collection_tag = value
50
+ end
51
+
52
+ def catche_tag_identifier
53
+ super || :id
54
+ end
55
+
56
+ end
57
+
58
+ def catche_tag
59
+ Tag.join self.class.catche_tag, self.send(:id)
60
+ end
61
+
62
+ def expire_resource_and_collection!
63
+ expire_collection!
64
+ expire_resource!
65
+ end
66
+
67
+ def expire_collection!
68
+ Catche::Tag.expire! *Catche::Tag::Collect.collection(self)[:expire]
69
+ end
70
+
71
+ def expire_resource!
72
+ Catche::Tag.expire! *Catche::Tag::Collect.resource(self)[:expire]
73
+ end
74
+
75
+ end
76
+ end
77
+
78
+ ActiveRecord::Base.send :include, Catche::Model
@@ -21,11 +21,12 @@ module Catche
21
21
  }
22
22
  end
23
23
 
24
- # Collects collection tags for a given context, for example a controller
24
+ # Collects collection tags for a given context, for example the resource or a controller
25
25
  #
26
- # Catche::Tag::Collect.collection_tags(controller, Task)
26
+ # Catche::Tag::Collect.collection(@task)
27
27
  # => { :set => ["projects_1_tasks"], :expire => ["tasks", "projects_1_tasks"] }
28
- def collection(context, resource_class, include_base=true)
28
+ def collection(context, resource_class=nil, include_base=true)
29
+ resource_class ||= context.class
29
30
  associations = Catche::ResourceLoader.fetch(context, *resource_class.catche_associations)
30
31
  association_tags = associations.map { |a| a.catche_tag }
31
32
 
@@ -1,3 +1,3 @@
1
1
  module Catche
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catche
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-24 00:00:00.000000000Z
12
+ date: 2012-06-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70331391407000 !ruby/object:Gem::Requirement
16
+ requirement: &70111289680960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70331391407000
24
+ version_requirements: *70111289680960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70331391406580 !ruby/object:Gem::Requirement
27
+ requirement: &70111289680540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70331391406580
35
+ version_requirements: *70111289680540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &70331391406120 !ruby/object:Gem::Requirement
38
+ requirement: &70111289680080 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70331391406120
46
+ version_requirements: *70111289680080
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: capybara
49
- requirement: &70331391405700 !ruby/object:Gem::Requirement
49
+ requirement: &70111289679660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70331391405700
57
+ version_requirements: *70111289679660
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-rspec
60
- requirement: &70331391405280 !ruby/object:Gem::Requirement
60
+ requirement: &70111289679240 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70331391405280
68
+ version_requirements: *70111289679240
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-spork
71
- requirement: &70331391404860 !ruby/object:Gem::Requirement
71
+ requirement: &70111289678820 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70331391404860
79
+ version_requirements: *70111289678820
80
80
  description: ''
81
81
  email:
82
82
  - mail@arjen.me
@@ -86,13 +86,12 @@ extra_rdoc_files: []
86
86
  files:
87
87
  - lib/catche/adapter/base.rb
88
88
  - lib/catche/adapter.rb
89
- - lib/catche/controller/action.rb
90
- - lib/catche/controller/page.rb
89
+ - lib/catche/controller/actions.rb
90
+ - lib/catche/controller/pages.rb
91
91
  - lib/catche/controller.rb
92
- - lib/catche/expire/page.rb
93
- - lib/catche/expire/view.rb
92
+ - lib/catche/expire/pages.rb
93
+ - lib/catche/expire/views.rb
94
94
  - lib/catche/expire.rb
95
- - lib/catche/model/base.rb
96
95
  - lib/catche/model.rb
97
96
  - lib/catche/railtie.rb
98
97
  - lib/catche/resource_loader.rb
@@ -127,5 +126,5 @@ rubyforge_project:
127
126
  rubygems_version: 1.8.10
128
127
  signing_key:
129
128
  specification_version: 3
130
- summary: Smart collection and resource caching
129
+ summary: Automatic resource and collection caching/expiration for Ruby on Rails
131
130
  test_files: []
@@ -1,79 +0,0 @@
1
- module Catche
2
- module Model
3
- module Base
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- class_attribute :catche_class,
8
- :catche_collection_tag,
9
- :catche_tag_identifier,
10
- :catche_associations
11
-
12
- # Expiration callbacks
13
-
14
- after_update :expire_resource_and_collection!
15
- after_destroy :expire_resource_and_collection!
16
-
17
- after_create :expire_collection!
18
- end
19
-
20
- module ClassMethods
21
-
22
- # Configures catche
23
- #
24
- # catche :through => :project, :catche_class => Task
25
- def catche(options={})
26
- options = {
27
- :class => self,
28
- :tag_identifier => :id,
29
- :collection_tag => nil,
30
- :associations => [options[:through]].flatten.compact
31
- }.merge(options)
32
-
33
- options.each do |key, value|
34
- self.send("catche_#{key}=", value) if self.respond_to?("catche_#{key}")
35
- end
36
-
37
- self.catche_collection_tag ||= self.catche_class.name.downcase.pluralize
38
- end
39
-
40
- def catche_reset!
41
- catche {}
42
- end
43
-
44
- def catche_tag
45
- self.catche_collection_tag || self.name.downcase.pluralize
46
- end
47
-
48
- def catche_tag=(value)
49
- self.catche_collection_tag = value
50
- end
51
-
52
- def catche_tag_identifier
53
- super || :id
54
- end
55
-
56
- end
57
-
58
- def catche_tag
59
- Tag.join self.class.catche_tag, self.send(:id)
60
- end
61
-
62
- def expire_resource_and_collection!
63
- expire_collection!
64
- expire_resource!
65
- end
66
-
67
- def expire_collection!
68
- Catche::Tag.expire! *Catche::Tag::Collect.collection(self, self.class)[:expire]
69
- end
70
-
71
- def expire_resource!
72
- Catche::Tag.expire! *Catche::Tag::Collect.resource(self)[:expire]
73
- end
74
-
75
- end
76
- end
77
- end
78
-
79
- ActiveRecord::Base.send :include, Catche::Model::Base