thumbs_up 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2eb255a6f08815057ab4a1896ed3e9d854c1c9c1
4
+ data.tar.gz: 8dc62bc7e179b16b6e2e307493f2a84b35445738
5
+ SHA512:
6
+ metadata.gz: 708c9cf6c4b659a8d56d5cd56dafd785d6e05bfd0c9d85e177abe94b832f9e85cf7278482ae6149e52234f3ff085be80a27845975800a395e480e81839dbf7cb
7
+ data.tar.gz: 31d121f34fa8dd291fec0f33a7411842bb548f773f28d01434c5b07efd869a60b0d325acb848f743f0d0361eafd10df574ea3ea529e263c92152ebca7a7e3a6d
data/README.md CHANGED
@@ -142,14 +142,32 @@ You can also use `--unique-voting false` when running the generator command:
142
142
 
143
143
  Testing is a bit more than trivial now as our #tally and #plusminus_tally queries don't function properly under SQLite. To set up for testing:
144
144
 
145
- ```
146
- $ mysql -uroot # You may have set a password locally. Change as needed.
147
- > GRANT ALL PRIVILEGES ON 'thumbs_up_test' to 'test'@'localhost' IDENTIFIED BY 'test';
148
- > CREATE DATABASE 'thumbs_up_test';
149
- > exit;
150
-
151
- $ rake # Runs the test suite.
152
- ```
145
+ * mysql
146
+
147
+ ```
148
+ $ mysql -uroot # You may have set a password locally. Change as needed.
149
+ > CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';
150
+ > CREATE DATABASE thumbs_up_test;
151
+ > USE thumbs_up_test;
152
+ > GRANT ALL PRIVILEGES ON thumbs_up_test TO 'test'@'localhost' IDENTIFIED BY 'test';
153
+ > exit;
154
+ ```
155
+ * Postgres
156
+
157
+ ```
158
+ $ psql # You may have set a password locally. Change as needed.
159
+ > CREATE ROLE test;
160
+ > ALTER ROLE test WITH SUPERUSER;
161
+ > ALTER ROLE test WITH LOGIN;
162
+ > CREATE DATABASE thumbs_up_test;
163
+ > GRANT ALL PRIVILEGES ON DATABASE thumbs_up_test to test;
164
+ > \q
165
+ ```
166
+ * Run tests
167
+
168
+ ```
169
+ $ rake # Runs the test suite against all adapters.
170
+ ```
153
171
 
154
172
  Credits
155
173
  =======
data/Rakefile CHANGED
@@ -40,4 +40,4 @@ task :test_all_databases do
40
40
  Rake::Task['test'].execute
41
41
  end
42
42
 
43
- task :default => :test_all_databases
43
+ task :default => :test_all_databases
@@ -8,7 +8,10 @@ module ThumbsUp
8
8
 
9
9
  module ClassMethods
10
10
  def acts_as_voteable
11
- has_many :votes, :as => :voteable, :dependent => :destroy
11
+ has_many ThumbsUp.configuration[:voteable_relationship_name],
12
+ :as => :voteable,
13
+ :dependent => :destroy,
14
+ :class_name => 'Vote'
12
15
 
13
16
  include ThumbsUp::ActsAsVoteable::InstanceMethods
14
17
  extend ThumbsUp::ActsAsVoteable::SingletonMethods
@@ -61,20 +64,25 @@ module ThumbsUp
61
64
 
62
65
  module InstanceMethods
63
66
 
67
+ # wraps the dynamic, configured, relationship name
68
+ def _votes_by
69
+ self.send(ThumbsUp.configuration[:voteable_relationship_name])
70
+ end
71
+
64
72
  def votes_for
65
- self.votes.where(:vote => true).count
73
+ self._votes_by.where(:vote => true).count
66
74
  end
67
75
 
68
76
  def votes_against
69
- self.votes.where(:vote => false).count
77
+ self._votes_by.where(:vote => false).count
70
78
  end
71
79
 
72
80
  def percent_for
73
- (votes_for.to_f * 100 / (self.votes.size + 0.0001)).round
81
+ (votes_for.to_f * 100 / (self._votes_by.size + 0.0001)).round
74
82
  end
75
83
 
76
84
  def percent_against
77
- (votes_against.to_f * 100 / (self.votes.size + 0.0001)).round
85
+ (votes_against.to_f * 100 / (self._votes_by.size + 0.0001)).round
78
86
  end
79
87
 
80
88
  # You'll probably want to use this method to display how 'good' a particular voteable
@@ -113,7 +121,7 @@ module ThumbsUp
113
121
  def voters_who_voted_against
114
122
  votes.where(:vote => false).map(&:voter).uniq
115
123
  end
116
-
124
+
117
125
  def voted_by?(voter)
118
126
  0 < Vote.where(
119
127
  :voteable_id => self.id,
data/lib/acts_as_voter.rb CHANGED
@@ -12,8 +12,11 @@ module ThumbsUp #:nodoc:
12
12
  # If you want to nullify (and keep the votes), you'll need to remove
13
13
  # the unique constraint on the [ voter, voteable ] index in the database.
14
14
  # has_many :votes, :as => :voter, :dependent => :nullify
15
- # Destroy votes when a user is deleted.
16
- has_many :votes, :as => :voter, :dependent => :destroy
15
+ # Destroy voter's votes when the voter is deleted.
16
+ has_many ThumbsUp.configuration[:voter_relationship_name],
17
+ :as => :voter,
18
+ :dependent => :destroy,
19
+ :class_name => 'Vote'
17
20
 
18
21
  include ThumbsUp::ActsAsVoter::InstanceMethods
19
22
  extend ThumbsUp::ActsAsVoter::SingletonMethods
@@ -27,6 +30,11 @@ module ThumbsUp #:nodoc:
27
30
  # This module contains instance methods
28
31
  module InstanceMethods
29
32
 
33
+ # wraps the dynamic, configured, relationship name
34
+ def _votes_on
35
+ self.send(ThumbsUp.configuration[:voteable_relationship_name])
36
+ end
37
+
30
38
  # Usage user.vote_count(:up) # All +1 votes
31
39
  # user.vote_count(:down) # All -1 votes
32
40
  # user.vote_count() # All votes
@@ -0,0 +1,11 @@
1
+ module ThumbsUp
2
+ module Base
3
+ def quoted_true
4
+ ActiveRecord::Base.connection.quoted_true
5
+ end
6
+
7
+ def quoted_false
8
+ ActiveRecord::Base.connection.quoted_false
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,51 @@
1
+ module ThumbsUp
2
+ class Configuration
3
+
4
+ OPTIONS = [:voteable_relationship_name, :voter_relationship_name].freeze
5
+
6
+ # Specify the name of the relationship from voted on things to voters.
7
+ # Default is votes
8
+ # In order to have a model that votes on itself,
9
+ # e.g. Users vote on Users,
10
+ # must change :voteable_relationship_name or :voter_relationship_name
11
+ # to a non-default value
12
+ attr_accessor :voteable_relationship_name
13
+
14
+ # Specify the name of the relationship from voters to voted on things
15
+ # Default is votes
16
+ # In order to have a model that votes on itself,
17
+ # e.g. Users vote on Users,
18
+ # must change :voteable_relationship_name or :voter_relationship_name
19
+ # to a non-default value
20
+ attr_accessor :voter_relationship_name
21
+
22
+ def initialize
23
+ # these defaults can be overridden in the ThumbsUp.config block
24
+ @voteable_relationship_name = :votes
25
+ @voter_relationship_name = :votes
26
+ end
27
+
28
+ # Allows config options to be read like a hash
29
+ #
30
+ # @param [Symbol] option Key for a given attribute
31
+ def [](option)
32
+ send(option)
33
+ end
34
+
35
+ # Returns a hash of all configurable options
36
+ def to_hash
37
+ OPTIONS.inject({}) do |hash, option|
38
+ hash[option.to_sym] = self.send(option)
39
+ hash
40
+ end
41
+ end
42
+
43
+ # Returns a hash of all configurable options merged with +hash+
44
+ #
45
+ # @param [Hash] hash A set of configuration options that will take precedence over the defaults
46
+ def merge(hash)
47
+ to_hash.merge(hash)
48
+ end
49
+
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module ThumbsUp
2
- VERSION = '0.6.3'
2
+ VERSION = '0.6.4'
3
3
  end
data/lib/thumbs_up.rb CHANGED
@@ -1,17 +1,36 @@
1
1
  require 'acts_as_voteable'
2
2
  require 'acts_as_voter'
3
3
  require 'has_karma'
4
+ require 'thumbs_up/configuration'
5
+ require 'thumbs_up/base'
6
+ require 'thumbs_up/version'
4
7
 
5
8
  module ThumbsUp
6
- module Base
7
- def quoted_true
8
- ActiveRecord::Base.connection.quoted_true
9
+
10
+ class << self
11
+
12
+ # An ThumbsUp::Configuration object. Must act like a hash and return sensible
13
+ # values for all ThumbsUp::Configuration::OPTIONS. See ThumbsUp::Configuration.
14
+ attr_writer :configuration
15
+
16
+ # Call this method to modify defaults in your initializers.
17
+ #
18
+ # @example
19
+ # ThumbsUp.configure do |config|
20
+ # config.voteable_relationship_name = :votes_by
21
+ # config.voter_relationship_name = :votes_on
22
+ # end
23
+ def configure
24
+ yield(configuration)
9
25
  end
10
26
 
11
- def quoted_false
12
- ActiveRecord::Base.connection.quoted_false
27
+ # The configuration object.
28
+ # @see I18::Airbrake.configure
29
+ def configuration
30
+ @configuration ||= Configuration.new
13
31
  end
14
32
  end
33
+
15
34
  end
16
35
 
17
36
  ActiveRecord::Base.send(:include, ThumbsUp::ActsAsVoteable)
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thumbs_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
5
- prerelease:
4
+ version: 0.6.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brady Bouchard
@@ -14,134 +13,118 @@ authors:
14
13
  autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
- date: 2013-01-20 00:00:00.000000000 Z
16
+ date: 2013-02-15 00:00:00.000000000 Z
18
17
  dependencies:
19
18
  - !ruby/object:Gem::Dependency
20
19
  name: activerecord
21
20
  requirement: !ruby/object:Gem::Requirement
22
- none: false
23
21
  requirements:
24
- - - ! '>='
22
+ - - '>='
25
23
  - !ruby/object:Gem::Version
26
24
  version: '0'
27
25
  type: :runtime
28
26
  prerelease: false
29
27
  version_requirements: !ruby/object:Gem::Requirement
30
- none: false
31
28
  requirements:
32
- - - ! '>='
29
+ - - '>='
33
30
  - !ruby/object:Gem::Version
34
31
  version: '0'
35
32
  - !ruby/object:Gem::Dependency
36
33
  name: statistics2
37
34
  requirement: !ruby/object:Gem::Requirement
38
- none: false
39
35
  requirements:
40
- - - ! '>='
36
+ - - '>='
41
37
  - !ruby/object:Gem::Version
42
38
  version: '0'
43
39
  type: :runtime
44
40
  prerelease: false
45
41
  version_requirements: !ruby/object:Gem::Requirement
46
- none: false
47
42
  requirements:
48
- - - ! '>='
43
+ - - '>='
49
44
  - !ruby/object:Gem::Version
50
45
  version: '0'
51
46
  - !ruby/object:Gem::Dependency
52
47
  name: simplecov
53
48
  requirement: !ruby/object:Gem::Requirement
54
- none: false
55
49
  requirements:
56
- - - ! '>='
50
+ - - '>='
57
51
  - !ruby/object:Gem::Version
58
52
  version: '0'
59
53
  type: :development
60
54
  prerelease: false
61
55
  version_requirements: !ruby/object:Gem::Requirement
62
- none: false
63
56
  requirements:
64
- - - ! '>='
57
+ - - '>='
65
58
  - !ruby/object:Gem::Version
66
59
  version: '0'
67
60
  - !ruby/object:Gem::Dependency
68
61
  name: bundler
69
62
  requirement: !ruby/object:Gem::Requirement
70
- none: false
71
63
  requirements:
72
- - - ! '>='
64
+ - - '>='
73
65
  - !ruby/object:Gem::Version
74
66
  version: '0'
75
67
  type: :development
76
68
  prerelease: false
77
69
  version_requirements: !ruby/object:Gem::Requirement
78
- none: false
79
70
  requirements:
80
- - - ! '>='
71
+ - - '>='
81
72
  - !ruby/object:Gem::Version
82
73
  version: '0'
83
74
  - !ruby/object:Gem::Dependency
84
75
  name: mysql2
85
76
  requirement: !ruby/object:Gem::Requirement
86
- none: false
87
77
  requirements:
88
- - - ! '>='
78
+ - - '>='
89
79
  - !ruby/object:Gem::Version
90
80
  version: '0'
91
81
  type: :development
92
82
  prerelease: false
93
83
  version_requirements: !ruby/object:Gem::Requirement
94
- none: false
95
84
  requirements:
96
- - - ! '>='
85
+ - - '>='
97
86
  - !ruby/object:Gem::Version
98
87
  version: '0'
99
88
  - !ruby/object:Gem::Dependency
100
89
  name: pg
101
90
  requirement: !ruby/object:Gem::Requirement
102
- none: false
103
91
  requirements:
104
- - - ! '>='
92
+ - - '>='
105
93
  - !ruby/object:Gem::Version
106
94
  version: '0'
107
95
  type: :development
108
96
  prerelease: false
109
97
  version_requirements: !ruby/object:Gem::Requirement
110
- none: false
111
98
  requirements:
112
- - - ! '>='
99
+ - - '>='
113
100
  - !ruby/object:Gem::Version
114
101
  version: '0'
115
102
  - !ruby/object:Gem::Dependency
116
103
  name: sqlite3
117
104
  requirement: !ruby/object:Gem::Requirement
118
- none: false
119
105
  requirements:
120
- - - ! '>='
106
+ - - '>='
121
107
  - !ruby/object:Gem::Version
122
108
  version: '0'
123
109
  type: :development
124
110
  prerelease: false
125
111
  version_requirements: !ruby/object:Gem::Requirement
126
- none: false
127
112
  requirements:
128
- - - ! '>='
113
+ - - '>='
129
114
  - !ruby/object:Gem::Version
130
115
  version: '0'
131
116
  - !ruby/object:Gem::Dependency
132
117
  name: rake
133
118
  requirement: !ruby/object:Gem::Requirement
134
- none: false
135
119
  requirements:
136
- - - ! '>='
120
+ - - '>='
137
121
  - !ruby/object:Gem::Version
138
122
  version: '0'
139
123
  type: :development
140
124
  prerelease: false
141
125
  version_requirements: !ruby/object:Gem::Requirement
142
- none: false
143
126
  requirements:
144
- - - ! '>='
127
+ - - '>='
145
128
  - !ruby/object:Gem::Version
146
129
  version: '0'
147
130
  description: ThumbsUp provides dead-simple voting capabilities to ActiveRecord models
@@ -158,6 +141,8 @@ files:
158
141
  - lib/generators/thumbs_up/templates/vote.rb
159
142
  - lib/generators/thumbs_up/thumbs_up_generator.rb
160
143
  - lib/has_karma.rb
144
+ - lib/thumbs_up/base.rb
145
+ - lib/thumbs_up/configuration.rb
161
146
  - lib/thumbs_up/version.rb
162
147
  - lib/thumbs_up.rb
163
148
  - rails/init.rb
@@ -170,32 +155,25 @@ files:
170
155
  - Rakefile
171
156
  homepage: http://github.com/bouchard/thumbs_up
172
157
  licenses: []
158
+ metadata: {}
173
159
  post_install_message:
174
160
  rdoc_options: []
175
161
  require_paths:
176
162
  - lib
177
163
  required_ruby_version: !ruby/object:Gem::Requirement
178
- none: false
179
164
  requirements:
180
- - - ! '>='
165
+ - - '>='
181
166
  - !ruby/object:Gem::Version
182
167
  version: '0'
183
- segments:
184
- - 0
185
- hash: 2682672596544266431
186
168
  required_rubygems_version: !ruby/object:Gem::Requirement
187
- none: false
188
169
  requirements:
189
- - - ! '>='
170
+ - - '>='
190
171
  - !ruby/object:Gem::Version
191
172
  version: '0'
192
- segments:
193
- - 0
194
- hash: 2682672596544266431
195
173
  requirements: []
196
174
  rubyforge_project:
197
- rubygems_version: 1.8.23
175
+ rubygems_version: 2.0.0.rc.2
198
176
  signing_key:
199
- specification_version: 3
177
+ specification_version: 4
200
178
  summary: Voting for ActiveRecord with multiple vote sources and karma calculation.
201
179
  test_files: []