reusable 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,7 @@ end
6
6
 
7
7
  module Reusable
8
8
  autoload :Cucumber, 'reusable/cucumber'
9
+ autoload :Mongoid, 'reusable/mongoid'
9
10
  autoload :Rails, 'reusable/rails'
10
11
  autoload :RSpec, 'reusable/rspec'
11
12
  end
@@ -0,0 +1,5 @@
1
+ module Reusable
2
+ module Mongoid
3
+ autoload :CounterCache, 'reusable/mongoid/counter_cache.rb'
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ # This CounterCache module provides support for an ActiveRecord
2
+ # type counter cache in Mongoid.
3
+ #
4
+ # class Reviews
5
+ # include Mongoid::Document
6
+ # include Reusable::Mongoid::CounterCache
7
+ #
8
+ # counter_cache name: 'profiles', field: 'reviews_count'
9
+ # belongs_to_related :profile
10
+ # end
11
+ module Reusable::Mongoid
12
+ module CounterCache
13
+ extend ActiveSupport::Concern
14
+
15
+ module ClassMethods
16
+ def counter_cache(options)
17
+ name = options[:name]
18
+ counter_field = options[:field]
19
+
20
+ after_create do |document|
21
+ relation = document.send(name)
22
+ relation.collection.update(relation._selector, {'$inc' => {counter_field.to_s => 1}})
23
+ end
24
+
25
+ after_destroy do |document|
26
+ relation = document.send(name)
27
+ relation.collection.update(relation._selector, {'$inc' => {counter_field.to_s => -1}})
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -5,10 +5,9 @@
5
5
  # you also need to add the following to your config/routes.rb file:
6
6
  # get '/:page_name',
7
7
  # to: 'pages#show',
8
- # as: :pages,
9
8
  # constraints: { page_name: /landing/i }
10
9
  #
11
- # root :to => 'pages#show', defaults: { page_name: 'landing' }
10
+ # root to: 'pages#show', defaults: { page_name: 'landing' }
12
11
  #
13
12
  module Reusable::Rails
14
13
  module Controllers
@@ -1,5 +1,5 @@
1
1
  module Reusable
2
- VERSION = '0.0.0'
2
+ VERSION = '0.0.1'
3
3
 
4
4
  def self.version
5
5
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reusable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
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: 2011-12-12 00:00:00.000000000 Z
12
+ date: 2012-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bcrypt-ruby
16
- requirement: &70268164937020 !ruby/object:Gem::Requirement
16
+ requirement: &70306897585580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70268164937020
24
+ version_requirements: *70306897585580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70268164936040 !ruby/object:Gem::Requirement
27
+ requirement: &70306897585080 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,21 @@ dependencies:
32
32
  version: 3.1.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70268164936040
35
+ version_requirements: *70306897585080
36
+ - !ruby/object:Gem::Dependency
37
+ name: mongoid
38
+ requirement: &70306897584660 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70306897584660
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: cucumber-rails
38
- requirement: &70268164935240 !ruby/object:Gem::Requirement
49
+ requirement: &70306897584200 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70268164935240
57
+ version_requirements: *70306897584200
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rspec-rails
49
- requirement: &70268164934140 !ruby/object:Gem::Requirement
60
+ requirement: &70306897583780 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70268164934140
68
+ version_requirements: *70306897583780
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: shoulda-matchers
60
- requirement: &70268164948220 !ruby/object:Gem::Requirement
71
+ requirement: &70306897583360 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *70268164948220
79
+ version_requirements: *70306897583360
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: fabrication
71
- requirement: &70268164947140 !ruby/object:Gem::Requirement
82
+ requirement: &70306897582940 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: '0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *70268164947140
90
+ version_requirements: *70306897582940
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: ffaker
82
- requirement: &70268164945900 !ruby/object:Gem::Requirement
93
+ requirement: &70306897582520 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ! '>='
@@ -87,7 +98,7 @@ dependencies:
87
98
  version: '0'
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *70268164945900
101
+ version_requirements: *70306897582520
91
102
  description: Reusable mixins for Rails, RSpec, and Cucumber.
92
103
  email:
93
104
  - justin.smestad@gmail.com
@@ -100,6 +111,8 @@ files:
100
111
  - lib/reusable/cucumber/step_definitions/authentication_steps.rb
101
112
  - lib/reusable/cucumber/step_definitions/base_steps.rb
102
113
  - lib/reusable/cucumber.rb
114
+ - lib/reusable/mongoid/counter_cache.rb
115
+ - lib/reusable/mongoid.rb
103
116
  - lib/reusable/rails/controllers/authentication_filters.rb
104
117
  - lib/reusable/rails/controllers/flash_messages/assets/javascripts/flash_messages.js
105
118
  - lib/reusable/rails/controllers/flash_messages.rb
@@ -174,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
187
  version: '0'
175
188
  segments:
176
189
  - 0
177
- hash: 1391231471331453295
190
+ hash: -3738770435536697031
178
191
  required_rubygems_version: !ruby/object:Gem::Requirement
179
192
  none: false
180
193
  requirements:
@@ -183,10 +196,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
196
  version: '0'
184
197
  segments:
185
198
  - 0
186
- hash: 1391231471331453295
199
+ hash: -3738770435536697031
187
200
  requirements: []
188
201
  rubyforge_project:
189
- rubygems_version: 1.8.10
202
+ rubygems_version: 1.8.11
190
203
  signing_key:
191
204
  specification_version: 3
192
205
  summary: Reusable mixins for Rails, RSpec, and Cucumber.