recognition 0.6.0 → 0.8.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/lib/recognition/models/gift.rb +10 -1
- data/lib/recognition/models/recognizable.rb +2 -0
- data/lib/recognition/models/redeemable.rb +5 -0
- data/lib/recognition/rails/railtie.rb +6 -3
- data/lib/recognition/version.rb +1 -1
- data/lib/recognition.rb +8 -3
- metadata +3 -4
- data/lib/recognition/logger.rb +0 -22
|
@@ -6,7 +6,16 @@ module Recognition
|
|
|
6
6
|
include Recognition::Models::Redeemable
|
|
7
7
|
|
|
8
8
|
def redeemable? recognizable
|
|
9
|
-
|
|
9
|
+
pass = false
|
|
10
|
+
if recognizable.points >= self.amount
|
|
11
|
+
if is_redeemable?(recognizable)
|
|
12
|
+
pass = true
|
|
13
|
+
end
|
|
14
|
+
else
|
|
15
|
+
errors.add(:base, "#{self.class.to_s} has already been redeemed")
|
|
16
|
+
pass = false
|
|
17
|
+
end
|
|
18
|
+
pass
|
|
10
19
|
end
|
|
11
20
|
|
|
12
21
|
def execute_redemption id
|
|
@@ -27,16 +27,21 @@ module Recognition
|
|
|
27
27
|
# only check if the redeemable did not expire
|
|
28
28
|
if expired?
|
|
29
29
|
Recognition.log self.class.to_s.downcase.to_sym, "validation error for #{self.class.to_s}##{self.id}: expired"
|
|
30
|
+
errors.add(:base, "#{self.class.to_s} expired")
|
|
30
31
|
else
|
|
31
32
|
# has the redeemable ever been redeemed?
|
|
32
33
|
if transactions.any?
|
|
33
34
|
# has the redeemable ever been redeemed by this user?
|
|
34
35
|
if get_user_counter(recognizable.id) != 0
|
|
35
36
|
Recognition.log self.class.to_s.downcase.to_sym, "validation error for #{self.class.to_s}##{self.id}: user has already redeemed the voucher"
|
|
37
|
+
errors.add(:base, "#{self.class.to_s} has already been redeemed")
|
|
36
38
|
pass = false
|
|
37
39
|
# is the redeemable reusable?
|
|
38
40
|
elsif defined?(self.reusable?) && self.reusable?
|
|
39
41
|
pass = true
|
|
42
|
+
else
|
|
43
|
+
errors.add(:base, "#{self.class.to_s} has already been redeemed")
|
|
44
|
+
pass = false
|
|
40
45
|
end
|
|
41
46
|
else
|
|
42
47
|
pass = true
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require
|
|
2
|
-
require
|
|
3
|
-
require
|
|
1
|
+
require 'recognition/extensions/active_record'
|
|
2
|
+
require 'recognition/extensions/action_controller'
|
|
3
|
+
require 'rails'
|
|
4
4
|
|
|
5
5
|
module Recognition
|
|
6
6
|
class Railtie < ::Rails::Railtie
|
|
@@ -12,5 +12,8 @@ module Recognition
|
|
|
12
12
|
ActionController::Base.send(:include, Recognition::Extensions::ActionController)
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
|
+
initializer 'recognition.logger' do
|
|
16
|
+
Recognition.logger = ::Rails.logger
|
|
17
|
+
end
|
|
15
18
|
end
|
|
16
19
|
end
|
data/lib/recognition/version.rb
CHANGED
data/lib/recognition.rb
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
require "recognition/version"
|
|
2
|
-
require "recognition/logger"
|
|
3
2
|
require "recognition/rails/engine"
|
|
4
3
|
require "recognition/rails/railtie"
|
|
5
4
|
require "redis"
|
|
6
5
|
|
|
7
6
|
module Recognition
|
|
8
|
-
extend Recognition::Logger
|
|
9
|
-
|
|
10
7
|
mattr_accessor :redis
|
|
11
8
|
# Redis Db connection parameters
|
|
12
9
|
@@redis = 'localhost:6378'
|
|
@@ -15,6 +12,10 @@ module Recognition
|
|
|
15
12
|
# Show debugging messages in log
|
|
16
13
|
@@debug = false
|
|
17
14
|
|
|
15
|
+
mattr_accessor :logger
|
|
16
|
+
# Set logger class
|
|
17
|
+
@@logger = ::Logger.new(STDOUT)
|
|
18
|
+
|
|
18
19
|
mattr_accessor :backend
|
|
19
20
|
# Redis Db active connection
|
|
20
21
|
@@backend = nil
|
|
@@ -24,6 +25,10 @@ module Recognition
|
|
|
24
25
|
yield self
|
|
25
26
|
end
|
|
26
27
|
|
|
28
|
+
def self.log key, message
|
|
29
|
+
Recognition.logger.info("[recognition] [#{key}] #{message}") if Recognition.debug
|
|
30
|
+
end
|
|
31
|
+
|
|
27
32
|
# Connect to Redis Db
|
|
28
33
|
def self.backend
|
|
29
34
|
if self.redis['redis://']
|
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.8.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -156,7 +156,6 @@ files:
|
|
|
156
156
|
- lib/recognition/database.rb
|
|
157
157
|
- lib/recognition/extensions/action_controller.rb
|
|
158
158
|
- lib/recognition/extensions/active_record.rb
|
|
159
|
-
- lib/recognition/logger.rb
|
|
160
159
|
- lib/recognition/models/gift.rb
|
|
161
160
|
- lib/recognition/models/recognizable.rb
|
|
162
161
|
- lib/recognition/models/recognizer.rb
|
|
@@ -185,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
185
184
|
version: '0'
|
|
186
185
|
segments:
|
|
187
186
|
- 0
|
|
188
|
-
hash:
|
|
187
|
+
hash: 3026903823241376003
|
|
189
188
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
189
|
none: false
|
|
191
190
|
requirements:
|
|
@@ -194,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
194
193
|
version: '0'
|
|
195
194
|
segments:
|
|
196
195
|
- 0
|
|
197
|
-
hash:
|
|
196
|
+
hash: 3026903823241376003
|
|
198
197
|
requirements: []
|
|
199
198
|
rubyforge_project:
|
|
200
199
|
rubygems_version: 1.8.23
|
data/lib/recognition/logger.rb
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
require 'logger'
|
|
2
|
-
|
|
3
|
-
module Recognition
|
|
4
|
-
module Logger
|
|
5
|
-
def log key, message
|
|
6
|
-
logger.info("[recognition] [#{key}] #{message}") if logging?
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def logger #:nodoc:
|
|
10
|
-
@logger ||= ::Logger.new(STDOUT)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def logger=(logger)
|
|
14
|
-
@logger = logger
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def logging? #:nodoc:
|
|
18
|
-
# TODO: Add an option to toggle logging
|
|
19
|
-
Recognition.debug
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|