thumbs_up 0.2.2 → 0.2.3
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/.gitignore +1 -0
- data/README.markdown +6 -3
- data/VERSION +1 -1
- data/lib/acts_as_voter.rb +22 -4
- data/thumbs_up.gemspec +5 -4
- metadata +4 -6
data/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.gem
|
data/README.markdown
CHANGED
|
@@ -59,9 +59,12 @@ Usage
|
|
|
59
59
|
### To cast a vote for a Model you can do the following:
|
|
60
60
|
|
|
61
61
|
#### Shorthand syntax
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
voter.vote_for(voteable) # Adds a +1 vote
|
|
63
|
+
voter.vote_against(voteable) # Adds a -1 vote
|
|
64
|
+
voter.vote(voteable, vote) # Adds either a +1 or -1 vote: vote => true (+1), vote => false (-1)
|
|
65
|
+
|
|
66
|
+
voter.vote_exclusively_for(voteable) # Removes any previous votes by that particular voter, and votes for.
|
|
67
|
+
voter.vote_exclusively_for(voteable) # Removes any previous votes by that particular voter, and votes against.
|
|
65
68
|
|
|
66
69
|
### Querying votes
|
|
67
70
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.3
|
data/lib/acts_as_voter.rb
CHANGED
|
@@ -57,15 +57,33 @@ module ThumbsUp #:nodoc:
|
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
def vote_for(voteable)
|
|
60
|
-
self.vote(voteable,
|
|
60
|
+
self.vote(voteable, { :direction => :up, :exclusive => false })
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
def vote_against(voteable)
|
|
64
|
-
self.vote(voteable, false)
|
|
64
|
+
self.vote(voteable, { :direction => :down, :exclusive => false })
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
def
|
|
68
|
-
|
|
67
|
+
def vote_exclusively_for(voteable)
|
|
68
|
+
self.vote(voteable, { :direction => :up, :exclusive => true })
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def vote_exclusively_against(voteable)
|
|
72
|
+
self.vote(voteable, { :direction => :down, :exclusive => true })
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def vote(voteable, options = {})
|
|
76
|
+
raise ArgumentError "you must specify :up or :down in order to vote" unless options[:direction] && [:up, :down].include?(options[:direction].to_sym)
|
|
77
|
+
if options[:exclusive]
|
|
78
|
+
Vote.where(
|
|
79
|
+
:voter_id => self.id,
|
|
80
|
+
:voter_type => self.class.name,
|
|
81
|
+
:voteable_id => voteable.id,
|
|
82
|
+
:voteable_type => voteable.class.name
|
|
83
|
+
).map(&:destroy)
|
|
84
|
+
end
|
|
85
|
+
direction = (options[:direction].to_sym == :up ? true : false)
|
|
86
|
+
Vote.create!(:vote => direction, :voteable => voteable, :voter => self)
|
|
69
87
|
end
|
|
70
88
|
|
|
71
89
|
def voted_which_way?(voteable, direction)
|
data/thumbs_up.gemspec
CHANGED
|
@@ -5,18 +5,19 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{thumbs_up}
|
|
8
|
-
s.version = "0.2.
|
|
8
|
+
s.version = "0.2.3"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
-
s.authors = ["Brady Bouchard", "Peter Jackson", "Cosmin Radoi", "Bence Nagy", "Rob Maddox", "Wojciech
|
|
12
|
-
s.date = %q{2010-08-
|
|
11
|
+
s.authors = ["Brady Bouchard", "Peter Jackson", "Cosmin Radoi", "Bence Nagy", "Rob Maddox", "Wojciech Wnętrzak"]
|
|
12
|
+
s.date = %q{2010-08-06}
|
|
13
13
|
s.description = %q{ThumbsUp provides dead-simple voting capabilities to ActiveRecord models with karma calculation, a la stackoverflow.com.}
|
|
14
14
|
s.email = %q{brady@ldawn.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
|
16
16
|
"README.markdown"
|
|
17
17
|
]
|
|
18
18
|
s.files = [
|
|
19
|
-
"
|
|
19
|
+
".gitignore",
|
|
20
|
+
"CHANGELOG.markdown",
|
|
20
21
|
"MIT-LICENSE",
|
|
21
22
|
"README.markdown",
|
|
22
23
|
"Rakefile",
|
metadata
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: thumbs_up
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash: 19
|
|
5
4
|
prerelease: false
|
|
6
5
|
segments:
|
|
7
6
|
- 0
|
|
8
7
|
- 2
|
|
9
|
-
-
|
|
10
|
-
version: 0.2.
|
|
8
|
+
- 3
|
|
9
|
+
version: 0.2.3
|
|
11
10
|
platform: ruby
|
|
12
11
|
authors:
|
|
13
12
|
- Brady Bouchard
|
|
@@ -20,7 +19,7 @@ autorequire:
|
|
|
20
19
|
bindir: bin
|
|
21
20
|
cert_chain: []
|
|
22
21
|
|
|
23
|
-
date: 2010-08-
|
|
22
|
+
date: 2010-08-06 00:00:00 +10:00
|
|
24
23
|
default_executable:
|
|
25
24
|
dependencies: []
|
|
26
25
|
|
|
@@ -33,6 +32,7 @@ extensions: []
|
|
|
33
32
|
extra_rdoc_files:
|
|
34
33
|
- README.markdown
|
|
35
34
|
files:
|
|
35
|
+
- .gitignore
|
|
36
36
|
- CHANGELOG.markdown
|
|
37
37
|
- MIT-LICENSE
|
|
38
38
|
- README.markdown
|
|
@@ -61,7 +61,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
61
61
|
requirements:
|
|
62
62
|
- - ">="
|
|
63
63
|
- !ruby/object:Gem::Version
|
|
64
|
-
hash: 3
|
|
65
64
|
segments:
|
|
66
65
|
- 0
|
|
67
66
|
version: "0"
|
|
@@ -70,7 +69,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
70
69
|
requirements:
|
|
71
70
|
- - ">="
|
|
72
71
|
- !ruby/object:Gem::Version
|
|
73
|
-
hash: 3
|
|
74
72
|
segments:
|
|
75
73
|
- 0
|
|
76
74
|
version: "0"
|