ballot_box 0.1.4 → 0.1.5
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 +9 -0
- data/{LICENSE → MIT-LICENSE} +0 -0
- data/README.rdoc +13 -4
- data/Rakefile +0 -20
- data/lib/ballot_box.rb +2 -1
- data/lib/ballot_box/base.rb +44 -9
- data/lib/ballot_box/version.rb +1 -1
- metadata +26 -28
- data/Gemfile.lock +0 -20
data/Gemfile
ADDED
data/{LICENSE → MIT-LICENSE}
RENAMED
File without changes
|
data/README.rdoc
CHANGED
@@ -10,9 +10,9 @@ The BallotBox gem enables visitors to vote for and against voteable objects
|
|
10
10
|
|
11
11
|
== Usage
|
12
12
|
|
13
|
-
Use middleware with options:
|
13
|
+
Use middleware with options: route and voteable_type
|
14
14
|
|
15
|
-
# Initialize BallotBox and set its configurations.
|
15
|
+
# Initialize BallotBox request manager and set its configurations.
|
16
16
|
config.app_middleware.use BallotBox::Manager do |config|
|
17
17
|
config.routes = { "/posts/votes" => "Post" }
|
18
18
|
end
|
@@ -20,7 +20,10 @@ Use middleware with options:
|
|
20
20
|
Set voteable model:
|
21
21
|
|
22
22
|
class Post < ActiveRecord::Base
|
23
|
-
ballot_box :counter_cache => true
|
23
|
+
ballot_box :counter_cache => true,
|
24
|
+
:strategies => [:authenticated],
|
25
|
+
:place => :position,
|
26
|
+
:scope => :group_id
|
24
27
|
end
|
25
28
|
|
26
29
|
Set votes sum column:
|
@@ -48,9 +51,13 @@ or update votes sum only for one record:
|
|
48
51
|
|
49
52
|
@post.ballot_box_update_votes!
|
50
53
|
|
51
|
-
Update place directly:
|
54
|
+
Update place directly for all scopes:
|
52
55
|
|
53
56
|
Post.ballot_box_update_place!
|
57
|
+
|
58
|
+
or update place only for one scope:
|
59
|
+
|
60
|
+
@post.ballot_box_update_place!
|
54
61
|
|
55
62
|
View (just send post request to configure route):
|
56
63
|
|
@@ -122,3 +129,5 @@ ActiveRecord callbacks:
|
|
122
129
|
|
123
130
|
end
|
124
131
|
end
|
132
|
+
|
133
|
+
This project rocks and uses MIT-LICENSE.
|
data/Rakefile
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
require 'rake'
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'rake/rdoctask'
|
5
|
-
require File.join(File.dirname(__FILE__), 'lib', 'ballot_box', 'version')
|
6
5
|
|
7
6
|
desc 'Default: run unit tests.'
|
8
7
|
task :default => :test
|
@@ -23,22 +22,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
23
22
|
rdoc.rdoc_files.include('README')
|
24
23
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
24
|
end
|
26
|
-
|
27
|
-
begin
|
28
|
-
require 'jeweler'
|
29
|
-
Jeweler::Tasks.new do |s|
|
30
|
-
s.name = "ballot_box"
|
31
|
-
s.version = BallotBox::VERSION.dup
|
32
|
-
s.summary = "The BallotBox gem enables visitors to vote for and against voteable objects"
|
33
|
-
s.description = "The BallotBox gem enables visitors to vote for and against voteable objects"
|
34
|
-
s.email = "galeta.igor@gmail.com"
|
35
|
-
s.homepage = "https://github.com/galetahub/ballot_box"
|
36
|
-
s.authors = ["Igor Galeta", "Pavlo Galeta"]
|
37
|
-
s.files = FileList["[A-Z]*", "{app,lib}/**/*"] - ["Gemfile"]
|
38
|
-
#s.extra_rdoc_files = FileList["[A-Z]*"]
|
39
|
-
end
|
40
|
-
|
41
|
-
Jeweler::GemcutterTasks.new
|
42
|
-
rescue LoadError
|
43
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
44
|
-
end
|
data/lib/ballot_box.rb
CHANGED
data/lib/ballot_box/base.rb
CHANGED
@@ -8,17 +8,23 @@ module BallotBox
|
|
8
8
|
#
|
9
9
|
# ballot_box :counter_cache => true,
|
10
10
|
# :strategies => [:authenticated],
|
11
|
-
# :place =>
|
11
|
+
# :place => :position,
|
12
|
+
# :scope => :group_id
|
12
13
|
#
|
13
14
|
def ballot_box(options = {})
|
14
15
|
extend ClassMethods
|
15
16
|
include InstanceMethods
|
16
17
|
|
17
|
-
|
18
|
-
:strategies => [:authenticated],
|
18
|
+
default_options = {
|
19
|
+
:strategies => [:authenticated],
|
20
|
+
:counter_cache => false,
|
19
21
|
:place => false,
|
20
|
-
:refresh => true
|
21
|
-
|
22
|
+
:refresh => true,
|
23
|
+
:scope => nil
|
24
|
+
}
|
25
|
+
|
26
|
+
options.assert_valid_keys(default_options.keys)
|
27
|
+
options = default_options.merge(options)
|
22
28
|
|
23
29
|
class_attribute :ballot_box_options, :instance_writer => false
|
24
30
|
self.ballot_box_options = options
|
@@ -92,14 +98,37 @@ module BallotBox
|
|
92
98
|
unscoped.order("#{quoted_table_name}.#{ballot_box_cached_column} DESC")
|
93
99
|
end
|
94
100
|
|
95
|
-
def ballot_box_update_place!(
|
101
|
+
def ballot_box_update_place!(record = nil)
|
102
|
+
relation = ballot_box_place_scope
|
103
|
+
|
104
|
+
if ballot_box_options[:scope]
|
105
|
+
scope_columns = Array.wrap(ballot_box_options[:scope])
|
106
|
+
|
107
|
+
unless record.nil?
|
108
|
+
scope_columns.each do |scope_item|
|
109
|
+
scope_value = record.send(scope_item)
|
110
|
+
relation = relation.where(scope_item => scope_value)
|
111
|
+
end
|
112
|
+
else
|
113
|
+
unscoped.select(scope_columns).group(scope_columns).each do |record|
|
114
|
+
ballot_box_update_place!(record)
|
115
|
+
end
|
116
|
+
|
117
|
+
return
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
ballot_box_update_place_by_relation(relation)
|
122
|
+
end
|
123
|
+
|
124
|
+
def ballot_box_update_place_by_relation(relation)
|
96
125
|
table = quoted_table_name
|
97
|
-
|
98
|
-
|
126
|
+
|
127
|
+
relation = relation.select("@row := @row + 1 AS row, #{table}.id").from("#{table}, (SELECT @row := 0) r")
|
99
128
|
|
100
129
|
query = %(UPDATE #{table} AS a
|
101
130
|
INNER JOIN (
|
102
|
-
#{
|
131
|
+
#{relation.to_sql}
|
103
132
|
) AS b ON a.id = b.id
|
104
133
|
SET a.#{ballot_box_place_column} = b.row;)
|
105
134
|
|
@@ -131,6 +160,12 @@ module BallotBox
|
|
131
160
|
self.class.update_all("#{ballot_box_cached_column} = (#{count.to_sql})", ["id = ?", id])
|
132
161
|
end
|
133
162
|
end
|
163
|
+
|
164
|
+
def ballot_box_update_place!
|
165
|
+
if persisted? && ballot_box_place_column
|
166
|
+
self.class.ballot_box_update_place!(self)
|
167
|
+
end
|
168
|
+
end
|
134
169
|
end
|
135
170
|
end
|
136
171
|
end
|
data/lib/ballot_box/version.rb
CHANGED
metadata
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ballot_box
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Igor Galeta
|
14
|
-
- Pavlo Galeta
|
15
14
|
autorequire:
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-17 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
21
|
+
name: browser
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
24
|
none: false
|
24
25
|
requirements:
|
25
26
|
- - ~>
|
@@ -30,12 +31,12 @@ dependencies:
|
|
30
31
|
- 1
|
31
32
|
- 2
|
32
33
|
version: 0.1.2
|
33
|
-
name: browser
|
34
|
-
prerelease: false
|
35
34
|
type: :runtime
|
36
|
-
|
35
|
+
version_requirements: *id001
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
37
|
+
name: activemodel
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
40
|
none: false
|
40
41
|
requirements:
|
41
42
|
- - ">="
|
@@ -44,10 +45,8 @@ dependencies:
|
|
44
45
|
segments:
|
45
46
|
- 0
|
46
47
|
version: "0"
|
47
|
-
name: activemodel
|
48
|
-
prerelease: false
|
49
48
|
type: :runtime
|
50
|
-
|
49
|
+
version_requirements: *id002
|
51
50
|
description: The BallotBox gem enables visitors to vote for and against voteable objects
|
52
51
|
email: galeta.igor@gmail.com
|
53
52
|
executables: []
|
@@ -55,27 +54,26 @@ executables: []
|
|
55
54
|
extensions: []
|
56
55
|
|
57
56
|
extra_rdoc_files:
|
58
|
-
- LICENSE
|
59
57
|
- README.rdoc
|
60
58
|
files:
|
61
|
-
- Gemfile.lock
|
62
|
-
- LICENSE
|
63
|
-
- README.rdoc
|
64
|
-
- Rakefile
|
65
59
|
- app/models/ballot_box/vote.rb
|
66
|
-
- lib/ballot_box.rb
|
60
|
+
- lib/generators/ballot_box/install_generator.rb
|
61
|
+
- lib/generators/ballot_box/USAGE
|
62
|
+
- lib/generators/ballot_box/templates/migrate/create_votes.rb
|
67
63
|
- lib/ballot_box/base.rb
|
68
|
-
- lib/ballot_box/callbacks.rb
|
69
64
|
- lib/ballot_box/config.rb
|
70
|
-
- lib/ballot_box/
|
65
|
+
- lib/ballot_box/callbacks.rb
|
71
66
|
- lib/ballot_box/manager.rb
|
72
|
-
- lib/ballot_box/strategies/authenticated.rb
|
73
|
-
- lib/ballot_box/strategies/base.rb
|
74
67
|
- lib/ballot_box/version.rb
|
68
|
+
- lib/ballot_box/engine.rb
|
75
69
|
- lib/ballot_box/voting.rb
|
76
|
-
- lib/
|
77
|
-
- lib/
|
78
|
-
- lib/
|
70
|
+
- lib/ballot_box/strategies/base.rb
|
71
|
+
- lib/ballot_box/strategies/authenticated.rb
|
72
|
+
- lib/ballot_box.rb
|
73
|
+
- MIT-LICENSE
|
74
|
+
- Rakefile
|
75
|
+
- Gemfile
|
76
|
+
- README.rdoc
|
79
77
|
homepage: https://github.com/galetahub/ballot_box
|
80
78
|
licenses: []
|
81
79
|
|
@@ -104,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
102
|
version: "0"
|
105
103
|
requirements: []
|
106
104
|
|
107
|
-
rubyforge_project:
|
108
|
-
rubygems_version: 1.8.
|
105
|
+
rubyforge_project: ballot_box
|
106
|
+
rubygems_version: 1.8.11
|
109
107
|
signing_key:
|
110
108
|
specification_version: 3
|
111
109
|
summary: The BallotBox gem enables visitors to vote for and against voteable objects
|
data/Gemfile.lock
DELETED
@@ -1,20 +0,0 @@
|
|
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)
|