recognition 0.5.0 → 0.6.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.
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
- Use an existing model or generate a new one using:
106
+ Use an existing model or generate a new one using:
108
107
 
109
- $ rails generate recogintion:voucher
108
+ $ rails generate recogintion:voucher
110
109
 
111
- Your model might have the following attributes:
110
+ Your model might have the following attributes:
112
111
 
113
- * `:code` **required**
114
- * `:amount` **required**
115
- * `:expires_at` _optional_
116
- * `:reusable` _optional_
112
+ * `:code` **required**
113
+ * `:amount` **required**
114
+ * `:expires_at` _optional_
115
+ * `:reusable` _optional_
117
116
 
118
- You can specify the following extra parameters for vouchers:
117
+ You can specify the following extra parameters for vouchers:
119
118
 
120
- * `:prefix` can be a number, string or method name or even an anonymous function.
121
- * `:suffix` can be a number, string or method name or even an anonymous function.
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
- app/models/voucher.rb:
122
+ app/models/voucher.rb:
124
123
 
125
- class Voucher < ActiveRecord::Base
126
- attr_accessible :code, :amount, :expires_at, :reusable
127
- acts_as_voucher code_length: 14
128
- end
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
- Then, you may do:
129
+ Then, you may do:
131
130
 
132
- voucher = Voucher.create!(amount: 20, expires_at: (DateTime.now + 1.day), reusable: true)
133
- voucher.redeem current_user
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
 
@@ -3,4 +3,5 @@ rails_env = Rails.env || 'development'
3
3
 
4
4
  Recognition.setup do |config|
5
5
  config.redis = YAML.load_file("#{ rails_root.to_s }/config/recognition.yml")[Rails.env.to_s]
6
+ config.debug = false
6
7
  end
data/lib/recognition.rb CHANGED
@@ -11,6 +11,10 @@ module Recognition
11
11
  # Redis Db connection parameters
12
12
  @@redis = 'localhost:6378'
13
13
 
14
+ mattr_accessor :debug
15
+ # Show debugging messages in log
16
+ @@debug = false
17
+
14
18
  mattr_accessor :backend
15
19
  # Redis Db active connection
16
20
  @@backend = nil
@@ -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?
@@ -16,7 +16,7 @@ module Recognition
16
16
 
17
17
  def logging? #:nodoc:
18
18
  # TODO: Add an option to toggle logging
19
- false
19
+ Recognition.debug
20
20
  end
21
21
  end
22
22
  end
@@ -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)) || 10
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
- unless expired?
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}:#{self.id}"
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
 
@@ -1,4 +1,4 @@
1
1
  module Recognition
2
2
  # Current Version
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
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.5.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-29 00:00:00.000000000 Z
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: 2026242214967045348
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: 2026242214967045348
197
+ hash: 2674790401115674200
198
198
  requirements: []
199
199
  rubyforge_project:
200
200
  rubygems_version: 1.8.23