ballot_box 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +20 -0
- data/README.rdoc +5 -1
- data/lib/ballot_box/base.rb +14 -2
- data/lib/ballot_box/version.rb +1 -1
- data/lib/ballot_box/voting.rb +8 -7
- metadata +12 -13
data/Gemfile.lock
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.1.1)
|
5
|
+
activesupport (= 3.1.1)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
i18n (~> 0.6)
|
8
|
+
activesupport (3.1.1)
|
9
|
+
multi_json (~> 1.0)
|
10
|
+
browser (0.1.3)
|
11
|
+
builder (3.0.0)
|
12
|
+
i18n (0.6.0)
|
13
|
+
multi_json (1.0.3)
|
14
|
+
|
15
|
+
PLATFORMS
|
16
|
+
ruby
|
17
|
+
|
18
|
+
DEPENDENCIES
|
19
|
+
activemodel
|
20
|
+
browser (~> 0.1.2)
|
data/README.rdoc
CHANGED
@@ -40,9 +40,13 @@ or update place scope conditions:
|
|
40
40
|
unscoped.order("rating DESC").where(:is_visible => true)
|
41
41
|
end
|
42
42
|
|
43
|
-
Update votes directly:
|
43
|
+
Update votes sum directly:
|
44
44
|
|
45
45
|
Post.ballot_box_update_votes!
|
46
|
+
|
47
|
+
or update votes sum only for one record:
|
48
|
+
|
49
|
+
@post.ballot_box_update_votes!
|
46
50
|
|
47
51
|
Update place directly:
|
48
52
|
|
data/lib/ballot_box/base.rb
CHANGED
@@ -16,8 +16,9 @@ module BallotBox
|
|
16
16
|
|
17
17
|
options = {
|
18
18
|
:strategies => [:authenticated],
|
19
|
-
:place => false
|
20
|
-
|
19
|
+
:place => false,
|
20
|
+
:refresh => true
|
21
|
+
}.merge(options)
|
21
22
|
|
22
23
|
class_attribute :ballot_box_options, :instance_writer => false
|
23
24
|
self.ballot_box_options = options
|
@@ -119,6 +120,17 @@ module BallotBox
|
|
119
120
|
def ballot_box_valid?(vote)
|
120
121
|
self.class.ballot_box_strategies.map { |st| st.new(self, vote) }.map(&:valid?).all?
|
121
122
|
end
|
123
|
+
|
124
|
+
def ballot_box_refresh?
|
125
|
+
self.class.ballot_box_options[:refresh]
|
126
|
+
end
|
127
|
+
|
128
|
+
def ballot_box_update_votes!
|
129
|
+
if persisted? && ballot_box_cached_column
|
130
|
+
count = self.votes.select("SUM(value)")
|
131
|
+
self.class.update_all("#{ballot_box_cached_column} = (#{count.to_sql})", ["id = ?", id])
|
132
|
+
end
|
133
|
+
end
|
122
134
|
end
|
123
135
|
end
|
124
136
|
end
|
data/lib/ballot_box/version.rb
CHANGED
data/lib/ballot_box/voting.rb
CHANGED
@@ -22,8 +22,8 @@ module BallotBox
|
|
22
22
|
|
23
23
|
# Callbacks
|
24
24
|
before_create :parse_browser
|
25
|
-
after_save :update_cached_columns
|
26
|
-
after_destroy :update_cached_columns
|
25
|
+
after_save :update_cached_columns, :if => :refresh?
|
26
|
+
after_destroy :update_cached_columns, :if => :refresh?
|
27
27
|
|
28
28
|
attr_accessible :request, :ip_address, :user_agent
|
29
29
|
|
@@ -116,6 +116,10 @@ module BallotBox
|
|
116
116
|
|
117
117
|
protected
|
118
118
|
|
119
|
+
def refresh?
|
120
|
+
voteable && voteable.ballot_box_refresh?
|
121
|
+
end
|
122
|
+
|
119
123
|
def parse_browser
|
120
124
|
self.browser_name ||= browser.id.to_s
|
121
125
|
self.browser_version ||= browser.version
|
@@ -128,14 +132,11 @@ module BallotBox
|
|
128
132
|
end
|
129
133
|
|
130
134
|
def update_votes_count
|
131
|
-
|
132
|
-
count = voteable.votes.select("SUM(value)")
|
133
|
-
voteable.class.update_all("#{voteable.ballot_box_cached_column} = (#{count.to_sql})", ["id = ?", voteable.id])
|
134
|
-
end
|
135
|
+
voteable.ballot_box_update_votes!
|
135
136
|
end
|
136
137
|
|
137
138
|
def update_place
|
138
|
-
if voteable
|
139
|
+
if voteable.ballot_box_place_column
|
139
140
|
voteable.class.ballot_box_update_place!
|
140
141
|
end
|
141
142
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ballot_box
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Igor Galeta
|
@@ -16,12 +16,10 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-10-
|
20
|
-
default_executable:
|
19
|
+
date: 2011-10-10 00:00:00 Z
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
23
|
none: false
|
26
24
|
requirements:
|
27
25
|
- - ~>
|
@@ -33,11 +31,11 @@ dependencies:
|
|
33
31
|
- 2
|
34
32
|
version: 0.1.2
|
35
33
|
name: browser
|
36
|
-
version_requirements: *id001
|
37
34
|
prerelease: false
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
35
|
type: :runtime
|
40
|
-
requirement:
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
40
|
requirements:
|
43
41
|
- - ">="
|
@@ -47,8 +45,9 @@ dependencies:
|
|
47
45
|
- 0
|
48
46
|
version: "0"
|
49
47
|
name: activemodel
|
50
|
-
version_requirements: *id002
|
51
48
|
prerelease: false
|
49
|
+
type: :runtime
|
50
|
+
requirement: *id002
|
52
51
|
description: The BallotBox gem enables visitors to vote for and against voteable objects
|
53
52
|
email: galeta.igor@gmail.com
|
54
53
|
executables: []
|
@@ -59,6 +58,7 @@ extra_rdoc_files:
|
|
59
58
|
- LICENSE
|
60
59
|
- README.rdoc
|
61
60
|
files:
|
61
|
+
- Gemfile.lock
|
62
62
|
- LICENSE
|
63
63
|
- README.rdoc
|
64
64
|
- Rakefile
|
@@ -76,7 +76,6 @@ files:
|
|
76
76
|
- lib/generators/ballot_box/USAGE
|
77
77
|
- lib/generators/ballot_box/install_generator.rb
|
78
78
|
- lib/generators/ballot_box/templates/migrate/create_votes.rb
|
79
|
-
has_rdoc: true
|
80
79
|
homepage: https://github.com/galetahub/ballot_box
|
81
80
|
licenses: []
|
82
81
|
|
@@ -106,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
105
|
requirements: []
|
107
106
|
|
108
107
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.
|
108
|
+
rubygems_version: 1.8.10
|
110
109
|
signing_key:
|
111
110
|
specification_version: 3
|
112
111
|
summary: The BallotBox gem enables visitors to vote for and against voteable objects
|