recognition 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -12,7 +12,6 @@ A fully-fledged reward system for Rails 3.1+.
|
|
12
12
|
|
13
13
|
* [Installation](#Installation)
|
14
14
|
* [Usage](#usage)
|
15
|
-
* [Examples](#example)
|
16
15
|
* [Wiki](https://github.com/rayasocialmedia/recognition/wiki)
|
17
16
|
* [Code Documentation](http://rubydoc.info/gems/recognition/frames)
|
18
17
|
* [Changelog](https://raw.github.com/rayasocialmedia/recognition/master/CHANGELOG.txt)
|
@@ -104,33 +103,33 @@ This one will:
|
|
104
103
|
|
105
104
|
### Vouchers
|
106
105
|
|
107
|
-
|
106
|
+
Use an existing model or generate a new one using:
|
108
107
|
|
109
|
-
|
108
|
+
$ rails generate recogintion:voucher
|
110
109
|
|
111
|
-
|
110
|
+
Your model might have the following attributes:
|
112
111
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
112
|
+
* `:code` **required**
|
113
|
+
* `:amount` **required**
|
114
|
+
* `:expires_at` _optional_
|
115
|
+
* `:reusable` _optional_
|
117
116
|
|
118
|
-
|
117
|
+
You can specify the following extra parameters for vouchers:
|
119
118
|
|
120
|
-
|
121
|
-
|
119
|
+
* `:prefix` can be a number, string or method name or even an anonymous function.
|
120
|
+
* `:suffix` can be a number, string or method name or even an anonymous function.
|
122
121
|
|
123
|
-
|
122
|
+
app/models/voucher.rb:
|
124
123
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
124
|
+
class Voucher < ActiveRecord::Base
|
125
|
+
attr_accessible :code, :amount, :expires_at, :reusable
|
126
|
+
acts_as_voucher code_length: 14
|
127
|
+
end
|
129
128
|
|
130
|
-
|
129
|
+
Then, you may do:
|
131
130
|
|
132
|
-
|
133
|
-
|
131
|
+
voucher = Voucher.create!(amount: 20, expires_at: (DateTime.now + 1.day), reusable: true)
|
132
|
+
voucher.redeem current_user
|
134
133
|
|
135
134
|
### Gifts
|
136
135
|
|
data/lib/recognition.rb
CHANGED
data/lib/recognition/database.rb
CHANGED
@@ -26,7 +26,6 @@ module Recognition
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.update_points object, action, condition
|
29
|
-
Recognition.log 'foo', condition.to_s
|
30
29
|
condition[:bucket] ||= "#{ object.class.to_s.camelize }:#{ action }"
|
31
30
|
user = Recognition::Parser.parse_recognizable(object, condition[:recognizable], condition[:proc_params])
|
32
31
|
# Do we have a valid user?
|
data/lib/recognition/logger.rb
CHANGED
@@ -2,9 +2,10 @@ module Recognition
|
|
2
2
|
module Models
|
3
3
|
module Redeemable
|
4
4
|
def regenerate_code
|
5
|
+
self.class.recognitions[:code_length] = 10 if self.class.recognitions[:code_length].nil?
|
5
6
|
prefix = Recognition::Parser.parse_code_part(self.class.recognitions[:prefix], self)
|
6
7
|
suffix = Recognition::Parser.parse_code_part(self.class.recognitions[:suffix], self)
|
7
|
-
l = (self.class.recognitions[:code_length] - (prefix.length + suffix.length))
|
8
|
+
l = (self.class.recognitions[:code_length] - (prefix.length + suffix.length))
|
8
9
|
dict = [('a'..'z'),('A'..'Z'),(0..9)].map{|i| i.to_a}.flatten
|
9
10
|
code = (1..l).map{ dict[rand(dict.length)] }.prepend(prefix).append(suffix).join
|
10
11
|
# Prevent code collision at all costs
|
@@ -24,11 +25,14 @@ module Recognition
|
|
24
25
|
# default: not redeemable
|
25
26
|
pass = false
|
26
27
|
# only check if the redeemable did not expire
|
27
|
-
|
28
|
+
if expired?
|
29
|
+
Recognition.log self.class.to_s.downcase.to_sym, "validation error for #{self.class.to_s}##{self.id}: expired"
|
30
|
+
else
|
28
31
|
# has the redeemable ever been redeemed?
|
29
32
|
if transactions.any?
|
30
33
|
# has the redeemable ever been redeemed by this user?
|
31
34
|
if get_user_counter(recognizable.id) != 0
|
35
|
+
Recognition.log self.class.to_s.downcase.to_sym, "validation error for #{self.class.to_s}##{self.id}: user has already redeemed the voucher"
|
32
36
|
pass = false
|
33
37
|
# is the redeemable reusable?
|
34
38
|
elsif defined?(self.reusable?) && self.reusable?
|
@@ -50,7 +54,7 @@ module Recognition
|
|
50
54
|
self.class.redemption_validators.each do |validator|
|
51
55
|
# quit if any validator returned false
|
52
56
|
if send(validator) == false
|
53
|
-
Recognition.log self.class.to_s.to_sym, "validation error for #{self.class.to_s}
|
57
|
+
Recognition.log self.class.to_s.downcase.to_sym, "validation error for #{self.class.to_s}##{self.id}: custom validation error"
|
54
58
|
return
|
55
59
|
end
|
56
60
|
end
|
@@ -58,6 +62,8 @@ module Recognition
|
|
58
62
|
# If all went well:
|
59
63
|
execute_redemption recognizable.id
|
60
64
|
end
|
65
|
+
else
|
66
|
+
Recognition.log self.class.to_s.downcase.to_sym, "validation error for #{self.class.to_s}##{self.id}: amount is nil"
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
data/lib/recognition/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recognition
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
segments:
|
187
187
|
- 0
|
188
|
-
hash:
|
188
|
+
hash: 2674790401115674200
|
189
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
190
|
none: false
|
191
191
|
requirements:
|
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '0'
|
195
195
|
segments:
|
196
196
|
- 0
|
197
|
-
hash:
|
197
|
+
hash: 2674790401115674200
|
198
198
|
requirements: []
|
199
199
|
rubyforge_project:
|
200
200
|
rubygems_version: 1.8.23
|