mongoid_magic_counter_cache 0.0.2 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/README.md +2 -3
- data/lib/mongoid/magic-counter-cache/version.rb +1 -1
- data/lib/mongoid/magic_counter_cache.rb +1 -2
- data/lib/mongoid_magic_counter_cache/version.rb +1 -1
- data/mongoid_magic_counter_cache.gemspec +1 -3
- data/spec/models/book.rb +2 -0
- data/spec/models/book/foreign_publication.rb +9 -0
- data/spec/mongoid/magic_counter_cache_spec.rb +9 -0
- data/spec/spec_helper.rb +3 -4
- metadata +26 -26
- data/lib/mongoid/.DS_Store +0 -0
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -56,9 +56,8 @@ If you do not wish to use the `model_count` naming convention, you can override
|
|
56
56
|
|
57
57
|
## TODO
|
58
58
|
|
59
|
-
1.
|
60
|
-
2.
|
61
|
-
3. Simplify syntax (I.E. including MagicCounterCache will add counts for all `belongs_to` associations on a document
|
59
|
+
1. Add additional options parameters
|
60
|
+
2. Simplify syntax (I.E. including MagicCounterCache will add counts for all `belongs_to` associations on a document
|
62
61
|
|
63
62
|
|
64
63
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'mongoid'
|
2
|
-
require 'pry'
|
3
2
|
module Mongoid #:nodoc:
|
4
3
|
|
5
4
|
# The Counter Cache will yada yada
|
@@ -51,7 +50,7 @@ module Mongoid #:nodoc:
|
|
51
50
|
if options[:field]
|
52
51
|
counter_name = "#{options[:field].to_s}"
|
53
52
|
else
|
54
|
-
counter_name = "#{model_name.
|
53
|
+
counter_name = "#{model_name.demodulize.underscore}_count"
|
55
54
|
end
|
56
55
|
after_create do |doc|
|
57
56
|
if doc.embedded?
|
@@ -19,9 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency("mongoid", "
|
22
|
+
s.add_dependency("mongoid", ">= 2.2", "<= 3.0")
|
23
23
|
s.add_dependency("rake")
|
24
|
-
s.add_dependency("bson_ext","~> 1.5")
|
25
24
|
s.add_development_dependency "rspec"
|
26
|
-
s.add_development_dependency "pry"
|
27
25
|
end
|
data/spec/models/book.rb
CHANGED
@@ -3,9 +3,11 @@ class Book
|
|
3
3
|
include Mongoid::MagicCounterCache
|
4
4
|
|
5
5
|
belongs_to :library
|
6
|
+
embeds_many :foreign_publications, :class_name => "Book::ForeignPublication"
|
6
7
|
embeds_many :pages
|
7
8
|
|
8
9
|
field :title
|
10
|
+
field :foreign_publication_count, :type => Integer, :default => 0
|
9
11
|
field :page_count, :type => Integer, :default => 0
|
10
12
|
|
11
13
|
counter_cache :library
|
@@ -74,6 +74,13 @@ module Mongoid
|
|
74
74
|
library.book_count.should == library.books.entries.size
|
75
75
|
end
|
76
76
|
|
77
|
+
it "should by default use demodulized and underscored model names for the count field" do
|
78
|
+
book = library.books.last
|
79
|
+
book.foreign_publication_count.should == 0
|
80
|
+
book.foreign_publications.push( Book::ForeignPublication.new )
|
81
|
+
book.foreign_publication_count.should == 1
|
82
|
+
end
|
83
|
+
|
77
84
|
context "when the referenced document has an embedded document" do
|
78
85
|
|
79
86
|
let(:page) do
|
@@ -81,6 +88,7 @@ module Mongoid
|
|
81
88
|
end
|
82
89
|
|
83
90
|
before do
|
91
|
+
book.save
|
84
92
|
book.pages.create(:title => "it was a long and stormy night")
|
85
93
|
library.books << book
|
86
94
|
end
|
@@ -126,6 +134,7 @@ module Mongoid
|
|
126
134
|
end
|
127
135
|
|
128
136
|
before do
|
137
|
+
album.save
|
129
138
|
album.songs.create(:title => "create you a song")
|
130
139
|
end
|
131
140
|
|
data/spec/spec_helper.rb
CHANGED
@@ -2,19 +2,18 @@ require "rubygems"
|
|
2
2
|
require "mongoid"
|
3
3
|
require "bundler/setup"
|
4
4
|
require "rspec"
|
5
|
-
require "pry"
|
6
5
|
require File.expand_path("../../lib/mongoid_magic_counter_cache", __FILE__)
|
7
6
|
|
8
7
|
Mongoid.configure do |config|
|
9
8
|
name = "mongoid_magic_counter_cache_test"
|
10
|
-
config.master = Mongo::Connection.new.db(name)
|
9
|
+
config.respond_to?(:connect_to) ? config.connect_to(name) : config.master = Mongo::Connection.new.db(name)
|
11
10
|
end
|
12
11
|
|
13
|
-
Dir["#{File.dirname(__FILE__)}/models
|
12
|
+
Dir["#{File.dirname(__FILE__)}/models/**/*.rb"].each { |f| require f }
|
14
13
|
|
15
14
|
RSpec.configure do |c|
|
16
15
|
c.mock_with :rspec
|
17
16
|
c.before(:each) do
|
18
|
-
Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
|
17
|
+
Mongoid::Config.respond_to?(:purge!) ? Mongoid::Config.purge! : Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
|
19
18
|
end
|
20
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_magic_counter_cache
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,33 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.2'
|
22
|
+
- - <=
|
20
23
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
24
|
+
version: '3.0'
|
22
25
|
type: :runtime
|
23
26
|
prerelease: false
|
24
|
-
version_requirements:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.2'
|
33
|
+
- - <=
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '3.0'
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
37
|
name: rake
|
27
|
-
requirement:
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,21 +43,15 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :runtime
|
34
45
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: bson_ext
|
38
|
-
requirement: &70293416286720 !ruby/object:Gem::Requirement
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
47
|
none: false
|
40
48
|
requirements:
|
41
|
-
- -
|
49
|
+
- - ! '>='
|
42
50
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
44
|
-
type: :runtime
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *70293416286720
|
51
|
+
version: '0'
|
47
52
|
- !ruby/object:Gem::Dependency
|
48
53
|
name: rspec
|
49
|
-
requirement:
|
54
|
+
requirement: !ruby/object:Gem::Requirement
|
50
55
|
none: false
|
51
56
|
requirements:
|
52
57
|
- - ! '>='
|
@@ -54,18 +59,12 @@ dependencies:
|
|
54
59
|
version: '0'
|
55
60
|
type: :development
|
56
61
|
prerelease: false
|
57
|
-
version_requirements:
|
58
|
-
- !ruby/object:Gem::Dependency
|
59
|
-
name: pry
|
60
|
-
requirement: &70293416285240 !ruby/object:Gem::Requirement
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
63
|
none: false
|
62
64
|
requirements:
|
63
65
|
- - ! '>='
|
64
66
|
- !ruby/object:Gem::Version
|
65
67
|
version: '0'
|
66
|
-
type: :development
|
67
|
-
prerelease: false
|
68
|
-
version_requirements: *70293416285240
|
69
68
|
description: A quick and easy way to add counter cache functionality to model/document
|
70
69
|
associations in Mongoid
|
71
70
|
email:
|
@@ -82,7 +81,6 @@ files:
|
|
82
81
|
- LICENSE
|
83
82
|
- README.md
|
84
83
|
- Rakefile
|
85
|
-
- lib/mongoid/.DS_Store
|
86
84
|
- lib/mongoid/magic-counter-cache/version.rb
|
87
85
|
- lib/mongoid/magic_counter_cache.rb
|
88
86
|
- lib/mongoid_magic_counter_cache.rb
|
@@ -90,6 +88,7 @@ files:
|
|
90
88
|
- mongoid_magic_counter_cache.gemspec
|
91
89
|
- spec/models/album.rb
|
92
90
|
- spec/models/book.rb
|
91
|
+
- spec/models/book/foreign_publication.rb
|
93
92
|
- spec/models/feeling.rb
|
94
93
|
- spec/models/library.rb
|
95
94
|
- spec/models/page.rb
|
@@ -117,13 +116,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
116
|
version: '0'
|
118
117
|
requirements: []
|
119
118
|
rubyforge_project: mongoid_magic_counter_cache
|
120
|
-
rubygems_version: 1.8.
|
119
|
+
rubygems_version: 1.8.22
|
121
120
|
signing_key:
|
122
121
|
specification_version: 3
|
123
122
|
summary: Setup Counter Caches in Mongoid Documents
|
124
123
|
test_files:
|
125
124
|
- spec/models/album.rb
|
126
125
|
- spec/models/book.rb
|
126
|
+
- spec/models/book/foreign_publication.rb
|
127
127
|
- spec/models/feeling.rb
|
128
128
|
- spec/models/library.rb
|
129
129
|
- spec/models/page.rb
|
data/lib/mongoid/.DS_Store
DELETED
Binary file
|