voltaire 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ce67879a2722aed80afbab466884e3980224948
4
- data.tar.gz: 758e40e64ab0c7bb1f6cee51b14067b0a3dd32c4
3
+ metadata.gz: c28cec632b79a5fcac75a29d2fbec19aaa9fd51e
4
+ data.tar.gz: 29e6a75c640ac2e8134a54608486a4f2033fe510
5
5
  SHA512:
6
- metadata.gz: 1f0bf5163ea394906d53c4c1abef8f80ed7c4be6dba01b9f23c5d208ae367b5a787d1619056cc2a51de461c2730c50384072e0c88cb826784fd6f138781f6a75
7
- data.tar.gz: ecec57a8f5f5444e49b2da1097358dd76100ce1ddef736c2e0dac1b51891ac96b0ff18d8e840d059759606d52abc7f0ef9c1777512f5422746f857652c09756e
6
+ metadata.gz: 93fdff51da9b305f2a5bf4b7c1516c653535b9b8caf0c82c6270cba87d0438a56f36f5bb169a344d04012d339de846c8ac4085973a7eabbf800629c6a45add1d
7
+ data.tar.gz: 2049b6be8ac30566be38d6c77e27adb1e7f7c66e2af8bf0277a03a9513fc9b8b74adc90673e5c29427dcd0a56f9a8b267d77ecb2ac900397c805f628c3a30228
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
  > A witty quote proves nothing. - Voltaire
3
3
 
4
4
  Voltaire provides a very simple way to manage user reputation points. It lets you increase or decrease reputation
5
- (points, level, whatever you want to call it in your app) as needed, whenever.
5
+ (points, level, whatever you want to call it in your app) as needed, whenever. It is intended to be extremely light-weight,
6
+ when all you want to track is some kind of points system and nothing else.
6
7
 
7
8
  All you have to do is add a column for reputation in your users table and let Voltaire do the rest.
8
9
 
@@ -11,7 +12,7 @@ All you have to do is add a column for reputation in your users table and let Vo
11
12
  Add this line to your application's Gemfile:
12
13
 
13
14
  ```ruby
14
- gem 'voltaire', '~> 0.2.0'
15
+ gem 'voltaire', '~> 0.3.0'
15
16
  ```
16
17
 
17
18
  And then execute:
@@ -43,8 +44,11 @@ rails db:migrate
43
44
  ## Implementing Voltaire's Powerful Mechanism
44
45
 
45
46
  Now you're ready to roll. Voltaire has two methods you can call to increase or decrease the user's reputation score.
46
- It requires three arguments: amount (the amount you want to increase or decrease by), reputation (the database column
47
- you want to alter), and user (the user whose reputation will be increased).
47
+ It requires 3 arguments: amount (the amount you want to increase or decrease by), reputation (the database column
48
+ you want to alter), and user (the user or item whose points will be increased).
49
+
50
+ _Note: if you are using any model other than users, you will need to use the_ ```voltaire_up_other``` and ```voltaire_down_other``` _methods_
51
+ _(instructions farther down)._
48
52
 
49
53
  The two methods are
50
54
 
@@ -135,6 +139,38 @@ def create
135
139
  end
136
140
  ```
137
141
 
142
+ ## Something Besides Users
143
+ If you want to implement a score system on some other than users, you will need to pass that in to the method as a fourth parameter.
144
+ In the example below, there is a World class for an app that helps writers create new worlds. If we implement a scoring
145
+ system on the world, we can easily see which ones are more fleshed out. The methods in this case will look like this:
146
+
147
+ ```ruby
148
+ voltaire_up_other(amount, reputation, user, other)
149
+
150
+ voltaire_down_other(amount, reputation, user, other)
151
+ ```
152
+
153
+ The fourth parameter, other, indicates the class. In this case, it would be ```World```. _This parameter needs to be uppercase._
154
+
155
+ ```ruby
156
+ def create
157
+ @city = City.new(city_params)
158
+ @city.user = current_user
159
+
160
+ respond_to do |format|
161
+ if @city.save
162
+ voltaire_up_other(1, :score, @city.world_id, World)
163
+ format.html { redirect_to @city, notice: 'City was successfully created.' }
164
+ else
165
+ format.html { render :new }
166
+ end
167
+ end
168
+ end
169
+ ```
170
+
171
+ Now, the author can easily see which of their worlds (characters, locations, etc.) are more developed, vs. ones that may need more work.
172
+ (Maybe they also compete with other authors to get their creations more points.)
173
+
138
174
  ## Development
139
175
 
140
176
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/voltaire.rb CHANGED
@@ -12,6 +12,18 @@ module Voltaire
12
12
  User.decrement_counter(reputation, user)
13
13
  end
14
14
  end
15
+
16
+ def voltaire_up_other(amount, reputation, user, other)
17
+ amount.times.collect do
18
+ other.increment_counter(reputation, user)
19
+ end
20
+ end
21
+
22
+ def voltaire_down_other(amount, reputation, user, other)
23
+ amount.times.collect do
24
+ other.decrement_counter(reputation, user)
25
+ end
26
+ end
15
27
  end
16
28
 
17
29
  if defined? ActionController::Base
@@ -1,3 +1,3 @@
1
1
  module Voltaire
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voltaire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Donche
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-24 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler