dm-is-counter_cacheable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.md +6 -0
- data/Gemfile +147 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +29 -0
- data/dm-is-counter_cacheable.gemspec +10 -0
- data/gemspec.yml +18 -0
- data/lib/dm-is-counter_cacheable/is/counter_cacheable.rb +121 -0
- data/lib/dm-is-counter_cacheable.rb +4 -0
- data/spec/integration/counter_cacheable_spec.rb +85 -0
- data/spec/integration/models/comment.rb +23 -0
- data/spec/integration/models/post.rb +19 -0
- data/spec/integration/models/user.rb +17 -0
- data/spec/spec_helper.rb +15 -0
- metadata +125 -0
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title 'dm-predefined Documentation' --protected --files ChangeLog.md,LICENSE.txt
|
data/ChangeLog.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# If you're working on more than one datamapper gem at a time, then it's
|
2
|
+
# recommended to create a local Gemfile and use this instead of the git
|
3
|
+
# sources. This will make sure that you are developing against your
|
4
|
+
# other local datamapper sources that you currently work on. Gemfile.local
|
5
|
+
# will behave identically to the standard Gemfile apart from the fact that
|
6
|
+
# it fetches the datamapper gems from local paths. This means that you can
|
7
|
+
# use the same environment variables, like ADAPTER(S) or PLUGIN(S) when
|
8
|
+
# running
|
9
|
+
# bundle commands. Gemfile.local is added to .gitignore, so you don't need
|
10
|
+
# to worry about accidentally checking local development paths into git.
|
11
|
+
# In order to create a local Gemfile, all you need to do is run:
|
12
|
+
#
|
13
|
+
# bundle exec rake local_gemfile
|
14
|
+
#
|
15
|
+
# This will give you a Gemfile.local file that points to your local clones
|
16
|
+
# of the various datamapper gems. It's assumed that all datamapper repo
|
17
|
+
# clones reside in the same directory. You can use the Gemfile.local like
|
18
|
+
# so for running any bundle command:
|
19
|
+
#
|
20
|
+
# BUNDLE_GEMFILE=Gemfile.local bundle foo
|
21
|
+
#
|
22
|
+
# You can also specify which adapter(s) should be part of the bundle by
|
23
|
+
# setting an environment variable. This of course also works when using the
|
24
|
+
# Gemfile.local
|
25
|
+
#
|
26
|
+
# bundle foo # dm-sqlite-adapter
|
27
|
+
#
|
28
|
+
# ADAPTER=mysql bundle foo # dm-mysql-adapter
|
29
|
+
#
|
30
|
+
# ADAPTERS=sqlite,mysql bundle foo # dm-sqlite-adapter, dm-mysql-adapter
|
31
|
+
#
|
32
|
+
# Of course you can also use the ADAPTER(S) variable when using the
|
33
|
+
# Gemfile.local and running specs against selected adapters.
|
34
|
+
#
|
35
|
+
# For easily working with adapters supported on your machine, it's
|
36
|
+
# recommended that you first install all adapters that you are planning to
|
37
|
+
# use or work on by doing something like
|
38
|
+
#
|
39
|
+
# ADAPTERS=sqlite,mysql,postgres bundle install
|
40
|
+
#
|
41
|
+
# This will clone the various repositories and make them available to
|
42
|
+
# bundler. Once you have them installed you can easily switch between
|
43
|
+
# adapters for the various development tasks. Running something like
|
44
|
+
#
|
45
|
+
# ADAPTER=mysql bundle exec rake spec
|
46
|
+
#
|
47
|
+
# will make sure that the dm-mysql-adapter is part of the bundle, and will
|
48
|
+
# be used when running the specs.
|
49
|
+
#
|
50
|
+
# You can also specify which plugin(s) should be part of the bundle by
|
51
|
+
# setting an environment variable. This also works when using the
|
52
|
+
# Gemfile.local
|
53
|
+
#
|
54
|
+
# bundle foo # dm-migrations
|
55
|
+
#
|
56
|
+
# PLUGINS=dm-validations bundle foo # dm-migrations,
|
57
|
+
# # dm-validations
|
58
|
+
#
|
59
|
+
# PLUGINS=dm-validations,dm-types bundle foo # dm-migrations,
|
60
|
+
# # dm-validations,
|
61
|
+
# # dm-types
|
62
|
+
#
|
63
|
+
# Of course you can combine the PLUGIN(S) and ADAPTER(S) env vars to run
|
64
|
+
# specs for certain adapter/plugin combinations.
|
65
|
+
#
|
66
|
+
# Finally, to speed up running specs and other tasks, it's recommended to
|
67
|
+
# run
|
68
|
+
#
|
69
|
+
# bundle lock
|
70
|
+
#
|
71
|
+
# after running 'bundle install' for the first time. This will make
|
72
|
+
# 'bundle exec' run a lot faster compared to the unlocked version. With an
|
73
|
+
# unlocked bundle you would typically just run 'bundle install' from time
|
74
|
+
# to time to fetch the latest sources from upstream. When you locked your
|
75
|
+
# bundle, you need to run
|
76
|
+
#
|
77
|
+
# bundle install --relock
|
78
|
+
#
|
79
|
+
# to make sure to fetch the latest updates and then lock the bundle again.
|
80
|
+
# Gemfile.lock is added to the .gitignore file, so you don't need to worry
|
81
|
+
# about accidentally checking it into version control.
|
82
|
+
|
83
|
+
source :rubygems
|
84
|
+
|
85
|
+
DATAMAPPER = 'http://github.com/datamapper'
|
86
|
+
DM_VERSION = '~> 1.0.0'
|
87
|
+
DO_VERSION = '~> 0.10.2'
|
88
|
+
DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
|
89
|
+
RAILS = 'http://github.com/rails/rails.git'
|
90
|
+
|
91
|
+
if ENV['EXTLIB']
|
92
|
+
gem 'extlib', '~> 0.9.15', :git => '#{DATAMAPPER}/extlib.git'
|
93
|
+
else
|
94
|
+
gem 'activesupport', '~> 3.0.0', :git => RAILS,
|
95
|
+
:branch => '3-0-stable',
|
96
|
+
:require => nil
|
97
|
+
end
|
98
|
+
|
99
|
+
gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
|
100
|
+
|
101
|
+
group :development do
|
102
|
+
case RUBY_PLATFORM
|
103
|
+
when 'java'
|
104
|
+
gem 'maruku', '~> 0.6.0'
|
105
|
+
else
|
106
|
+
gem 'rdiscount', '~> 1.6.3'
|
107
|
+
end
|
108
|
+
|
109
|
+
gem 'rake', '~> 0.8.7'
|
110
|
+
gem 'ore', '~> 0.2.0'
|
111
|
+
gem 'ore-tasks', '~> 0.1.2'
|
112
|
+
gem 'rspec', '~> 2.0.0'
|
113
|
+
gem 'yard', '~> 0.6.0'
|
114
|
+
end
|
115
|
+
|
116
|
+
group :datamapper do
|
117
|
+
# We need this because we want to pin these dependencies to their git
|
118
|
+
# master sources
|
119
|
+
|
120
|
+
adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
|
121
|
+
adapters = adapters.to_s.tr(',', ' ').split.uniq - %w[ in_memory ]
|
122
|
+
|
123
|
+
if (do_adapters = DM_DO_ADAPTERS & adapters).any?
|
124
|
+
options = {}
|
125
|
+
options[:git] = "#{DATAMAPPER}/do.git" if ENV['DO_GIT'] == 'true'
|
126
|
+
|
127
|
+
gem 'data_objects', DO_VERSION, options.dup
|
128
|
+
|
129
|
+
do_adapters.each do |adapter|
|
130
|
+
adapter = 'sqlite3' if adapter == 'sqlite'
|
131
|
+
gem "do_#{adapter}", DO_VERSION, options.dup
|
132
|
+
end
|
133
|
+
|
134
|
+
gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
|
135
|
+
end
|
136
|
+
|
137
|
+
adapters.each do |adapter|
|
138
|
+
gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
|
139
|
+
end
|
140
|
+
|
141
|
+
plugins = ENV['PLUGINS'] || ENV['PLUGIN']
|
142
|
+
plugins = plugins.to_s.tr(',', ' ').split.push('dm-migrations').uniq
|
143
|
+
|
144
|
+
plugins.each do |plugin|
|
145
|
+
gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
|
146
|
+
end
|
147
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2008-2010 Hal Brodigan
|
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,47 @@
|
|
1
|
+
# dm-is-countercacheable
|
2
|
+
|
3
|
+
* [github.com/postmodern/dm-is-counter_cacheable](http://github.com/postmodern/dm-is-counter_cacheable)
|
4
|
+
* [github.com/postmodern/dm-is-counter_cacheable/issues](http://github.com/postmodern/dm-is-counter_cacheable/issues)
|
5
|
+
* Postmodern (postmodern.mod3 at gmail.com)
|
6
|
+
|
7
|
+
## Description
|
8
|
+
|
9
|
+
A DataMapper plugin for adding counter-cache properties to related models.
|
10
|
+
|
11
|
+
## Example
|
12
|
+
|
13
|
+
Adds counter properties to Post and User for the number of comments:
|
14
|
+
|
15
|
+
require 'dm-core'
|
16
|
+
|
17
|
+
class Comment
|
18
|
+
|
19
|
+
include DataMapper::Resource
|
20
|
+
|
21
|
+
is :counter_cacheable
|
22
|
+
|
23
|
+
property :id, Serial
|
24
|
+
|
25
|
+
property :body, Text
|
26
|
+
|
27
|
+
belongs_to :post
|
28
|
+
|
29
|
+
belongs_to :user
|
30
|
+
|
31
|
+
counter_cacheable :post
|
32
|
+
counter_cacheable :user, :counter_property => :post_comments_counter
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
## Requirements
|
37
|
+
|
38
|
+
* [dm-core](http://github.com/datamapper/dm-core/) ~> 1.0.0
|
39
|
+
|
40
|
+
## Install
|
41
|
+
|
42
|
+
$ sudo gem install dm-is-countercacheable
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
See {file:LICENSE.txt} for license information.
|
47
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler'
|
5
|
+
rescue LoadError => e
|
6
|
+
STDERR.puts e.message
|
7
|
+
STDERR.puts "Run `gem install bundler` to install Bundler."
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
|
11
|
+
begin
|
12
|
+
Bundler.setup(:development)
|
13
|
+
rescue Bundler::BundlerError => e
|
14
|
+
STDERR.puts e.message
|
15
|
+
STDERR.puts "Run `bundle install` to install missing gems"
|
16
|
+
exit e.status_code
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake'
|
20
|
+
|
21
|
+
require 'ore/tasks'
|
22
|
+
Ore::Tasks.new
|
23
|
+
|
24
|
+
require 'rspec/core/rake_task'
|
25
|
+
RSpec::Core::RakeTask.new
|
26
|
+
task :default => :spec
|
27
|
+
|
28
|
+
require 'yard'
|
29
|
+
YARD::Rake::YardocTask.new
|
data/gemspec.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
name: dm-is-counter_cacheable
|
2
|
+
version: 0.1.0
|
3
|
+
summary: DataMapper plugin for adding counter-caching to models.
|
4
|
+
description:
|
5
|
+
A DataMapper plugin for adding counter-cache properties to related models.
|
6
|
+
|
7
|
+
license: MIT
|
8
|
+
authors: Postmodern
|
9
|
+
email: postmodern.mod3@gmail.com
|
10
|
+
homepage: http://github.com/postmodern/dm-is-counter_cacheable
|
11
|
+
has_yard: true
|
12
|
+
|
13
|
+
dependencies:
|
14
|
+
dm-core: ~> 1.0.0
|
15
|
+
|
16
|
+
development_dependencies:
|
17
|
+
bundler: ~> 1.0.0
|
18
|
+
yard: ~> 0.6.0
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module DataMapper
|
2
|
+
module Is
|
3
|
+
module CounterCacheable
|
4
|
+
#
|
5
|
+
# Fired when your plugin gets included into a Resource.
|
6
|
+
#
|
7
|
+
def is_counter_cacheable
|
8
|
+
extend DataMapper::Is::CounterCacheable::ClassMethods
|
9
|
+
include DataMapper::Is::CounterCacheable::InstanceMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
attr_reader :counter_cache
|
14
|
+
|
15
|
+
#
|
16
|
+
# Adds a counter cache property to a related model.
|
17
|
+
#
|
18
|
+
# @param [Symbol] relationship_name
|
19
|
+
# The name of the related model.
|
20
|
+
#
|
21
|
+
# @param [Hash] options
|
22
|
+
# Additional options.
|
23
|
+
#
|
24
|
+
# @option options [Symbol] :counter_property
|
25
|
+
# The optional property name to store the counter cache in.
|
26
|
+
#
|
27
|
+
# @option options [Boolean] :counter_index
|
28
|
+
# Specifies to store the current count in newly created resources.
|
29
|
+
#
|
30
|
+
# @return [DataMapper::Property]
|
31
|
+
# The newly added counter cache property.
|
32
|
+
#
|
33
|
+
def counter_cacheable(relationship_name,options={})
|
34
|
+
@counter_cache ||= []
|
35
|
+
|
36
|
+
unless self.relationships.has_key?(relationship_name)
|
37
|
+
raise(RuntimeError,"unknown relationship #{relationship_name} in #{self}",caller)
|
38
|
+
end
|
39
|
+
|
40
|
+
model_name = DataMapper::NamingConventions::Resource::UnderscoredAndPluralized.call(self.name.split('::').last)
|
41
|
+
counter_property = if options.has_key?(:counter_property)
|
42
|
+
options[:counter_property]
|
43
|
+
else
|
44
|
+
:"#{model_name}_counter"
|
45
|
+
end
|
46
|
+
|
47
|
+
relationship = self.relationships[relationship_name]
|
48
|
+
parent_model = case relationship
|
49
|
+
when DataMapper::Associations::ManyToOne::Relationship,
|
50
|
+
DataMapper::Associations::OneToOne::Relationship
|
51
|
+
relationship.parent_model
|
52
|
+
end
|
53
|
+
|
54
|
+
parent_model.property counter_property, Integer, :default => 0, :min => 0
|
55
|
+
|
56
|
+
if options[:counter_index]
|
57
|
+
counter_index = :"#{relationship_name}_#{model_name}_index"
|
58
|
+
|
59
|
+
self.property counter_index, Integer, :min => 1
|
60
|
+
else
|
61
|
+
counter_index = nil
|
62
|
+
end
|
63
|
+
|
64
|
+
@counter_cache << {
|
65
|
+
:relationship => relationship_name,
|
66
|
+
:counter_property => counter_property,
|
67
|
+
:counter_index => counter_index
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
module InstanceMethods
|
73
|
+
private
|
74
|
+
|
75
|
+
#
|
76
|
+
# Creates a resource and increments the cache counters of the model.
|
77
|
+
#
|
78
|
+
# @return [DataMapper::Resource]
|
79
|
+
# The new resource.
|
80
|
+
#
|
81
|
+
def _save(*arguments)
|
82
|
+
if (self.new? && self.class.counter_cache)
|
83
|
+
self.class.counter_cache.each do |options|
|
84
|
+
parent_resource = self.send(options[:relationship])
|
85
|
+
|
86
|
+
count = parent_resource.attribute_get(options[:counter_property])
|
87
|
+
count += 1
|
88
|
+
|
89
|
+
parent_resource.attribute_set(options[:counter_property],count)
|
90
|
+
|
91
|
+
if options[:counter_index]
|
92
|
+
self.attribute_set(options[:counter_index],count)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
super(*arguments)
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Destroys a resource and decrements the cache counters of the model.
|
102
|
+
#
|
103
|
+
# @return [Boolean]
|
104
|
+
# Specifies whether the resource was successfully destroyed.
|
105
|
+
#
|
106
|
+
def _destroy(*arguments)
|
107
|
+
if self.class.counter_cache
|
108
|
+
self.class.counter_cache.each do |options|
|
109
|
+
parent_resource = self.send(options[:relationship])
|
110
|
+
|
111
|
+
count = parent_resource.attribute_get(options[:counter_property])
|
112
|
+
parent_resource.attribute_set(options[:counter_property],count - 1)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
super(*arguments)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DataMapper::Is::CounterCacheable do
|
4
|
+
before(:all) do
|
5
|
+
DataMapper.auto_migrate!
|
6
|
+
|
7
|
+
User.create(
|
8
|
+
:name => 'bob',
|
9
|
+
:posts => [
|
10
|
+
{:title => 'Hello', :body => 'Hello there.'}
|
11
|
+
]
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@user = User.first
|
17
|
+
@post = @user.posts.first
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should define the default counter cache property" do
|
21
|
+
Post.properties.should be_named('comments_counter')
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should allow defining custom named counter cache properties" do
|
25
|
+
User.properties.should be_named('post_comments_counter')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should optionally define a counter index column" do
|
29
|
+
Comment.properties.should be_named('user_comments_index')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have a counter cache of 0 by default" do
|
33
|
+
@post.comments_counter.should == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should increment the counter cache by 1 when a new resource is created" do
|
37
|
+
orig_counter = @post.comments_counter
|
38
|
+
|
39
|
+
@post.comments.create(
|
40
|
+
:body => 'lol',
|
41
|
+
:user => @user
|
42
|
+
)
|
43
|
+
|
44
|
+
new_counter = @post.comments_counter
|
45
|
+
|
46
|
+
(new_counter - orig_counter).should == 1
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should increment the counter cache by 1 when a new resource is saved" do
|
50
|
+
orig_counter = @post.comments_counter
|
51
|
+
|
52
|
+
@post.comments.new(
|
53
|
+
:body => 'omg',
|
54
|
+
:user => @user
|
55
|
+
).save
|
56
|
+
|
57
|
+
new_counter = @post.comments_counter
|
58
|
+
|
59
|
+
(new_counter - orig_counter).should == 1
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should set the counter index to the counter value when a new resource is created" do
|
63
|
+
@post.comments.create(
|
64
|
+
:body => 'lol',
|
65
|
+
:user => @user
|
66
|
+
)
|
67
|
+
|
68
|
+
@post.comments.last.user_comments_index.should == @user.post_comments_counter
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should decrement the counter cache by 1 when a resource is destroyed" do
|
72
|
+
@post.comments.create(
|
73
|
+
:body => 'wtf',
|
74
|
+
:user => @user
|
75
|
+
)
|
76
|
+
|
77
|
+
orig_counter = @post.comments_counter
|
78
|
+
|
79
|
+
@post.comments.first.destroy
|
80
|
+
|
81
|
+
new_counter = @post.comments_counter
|
82
|
+
|
83
|
+
(new_counter - orig_counter).should == -1
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
require 'dm-migrations'
|
3
|
+
|
4
|
+
class Comment
|
5
|
+
|
6
|
+
include DataMapper::Resource
|
7
|
+
include DataMapper::Migrations
|
8
|
+
|
9
|
+
is :counter_cacheable
|
10
|
+
|
11
|
+
property :id, Serial
|
12
|
+
|
13
|
+
property :body, Text
|
14
|
+
|
15
|
+
belongs_to :post
|
16
|
+
|
17
|
+
belongs_to :user
|
18
|
+
|
19
|
+
counter_cacheable :post
|
20
|
+
counter_cacheable :user, :counter_property => :post_comments_counter,
|
21
|
+
:counter_index => true
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
require 'dm-migrations'
|
3
|
+
|
4
|
+
class Post
|
5
|
+
|
6
|
+
include DataMapper::Resource
|
7
|
+
include DataMapper::Migrations
|
8
|
+
|
9
|
+
property :id, Serial
|
10
|
+
|
11
|
+
property :title, String
|
12
|
+
|
13
|
+
property :body, Text
|
14
|
+
|
15
|
+
has 0..n, :comments
|
16
|
+
|
17
|
+
belongs_to :user
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
require 'dm-migrations'
|
3
|
+
|
4
|
+
class User
|
5
|
+
|
6
|
+
include DataMapper::Resource
|
7
|
+
include DataMapper::Migrations
|
8
|
+
|
9
|
+
property :id, Serial
|
10
|
+
|
11
|
+
property :name, String
|
12
|
+
|
13
|
+
has 0..n, :posts
|
14
|
+
|
15
|
+
has 0..n, :comments, :through => :posts
|
16
|
+
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'dm-core/spec/setup'
|
3
|
+
require 'dm-core/spec/lib/adapter_helpers'
|
4
|
+
|
5
|
+
require 'dm-is-counter_cacheable'
|
6
|
+
|
7
|
+
require 'integration/models/user'
|
8
|
+
require 'integration/models/post'
|
9
|
+
require 'integration/models/comment'
|
10
|
+
|
11
|
+
DataMapper::Spec.setup
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.extend(DataMapper::Spec::Adapters::Helpers)
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm-is-counter_cacheable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Postmodern
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-05 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: dm-core
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 1.0.0
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
version: 1.0.0
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: yard
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
- 6
|
60
|
+
- 0
|
61
|
+
version: 0.6.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
description: A DataMapper plugin for adding counter-cache properties to related models.
|
66
|
+
email: postmodern.mod3@gmail.com
|
67
|
+
executables: []
|
68
|
+
|
69
|
+
extensions: []
|
70
|
+
|
71
|
+
extra_rdoc_files:
|
72
|
+
- README.md
|
73
|
+
files:
|
74
|
+
- .rspec
|
75
|
+
- .yardopts
|
76
|
+
- ChangeLog.md
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- dm-is-counter_cacheable.gemspec
|
82
|
+
- gemspec.yml
|
83
|
+
- lib/dm-is-counter_cacheable.rb
|
84
|
+
- lib/dm-is-counter_cacheable/is/counter_cacheable.rb
|
85
|
+
- spec/integration/counter_cacheable_spec.rb
|
86
|
+
- spec/integration/models/comment.rb
|
87
|
+
- spec/integration/models/post.rb
|
88
|
+
- spec/integration/models/user.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
has_rdoc: yard
|
91
|
+
homepage: http://github.com/postmodern/dm-is-counter_cacheable
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
segments:
|
113
|
+
- 1
|
114
|
+
- 3
|
115
|
+
- 6
|
116
|
+
version: 1.3.6
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project: dm-is-counter_cacheable
|
120
|
+
rubygems_version: 1.3.7
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: DataMapper plugin for adding counter-caching to models.
|
124
|
+
test_files:
|
125
|
+
- spec/integration/counter_cacheable_spec.rb
|