recognition 0.3.6 → 0.3.7
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
@@ -75,7 +75,11 @@ app/controllers/profiles_controller.rb:
|
|
75
75
|
|
76
76
|
### Vouchers
|
77
77
|
|
78
|
-
Use an existing model or generate a new one
|
78
|
+
Use an existing model or generate a new one using:
|
79
|
+
|
80
|
+
$ rails generate recogintion:voucher
|
81
|
+
|
82
|
+
Your model might have the following attributes:
|
79
83
|
|
80
84
|
* `:code` **required**
|
81
85
|
* `:amount` **required**
|
@@ -86,7 +90,7 @@ app/models/voucher.rb:
|
|
86
90
|
|
87
91
|
class Voucher < ActiveRecord::Base
|
88
92
|
attr_accessible :code, :amount, :expires_at, :reusable
|
89
|
-
|
93
|
+
acts_as_voucher code_length: 14
|
90
94
|
end
|
91
95
|
|
92
96
|
Then, you may do:
|
@@ -59,6 +59,12 @@ module Recognition
|
|
59
59
|
require "recognition/activerecord/voucher"
|
60
60
|
include Recognition::ActiveRecord::Voucher
|
61
61
|
self.recognitions = options
|
62
|
+
cattr_accessor :voucher_validators
|
63
|
+
def self.validates_voucher_redmeption validators
|
64
|
+
self.voucher_validators ||= []
|
65
|
+
self.voucher_validators << validators
|
66
|
+
self.voucher_validators.flatten!
|
67
|
+
end
|
62
68
|
before_create :regenerate_code
|
63
69
|
end
|
64
70
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Recognition
|
2
2
|
module ActiveRecord
|
3
3
|
module Voucher
|
4
|
+
# class_attribute :voucher_validators
|
5
|
+
|
4
6
|
def regenerate_code
|
5
7
|
l = self.class.recognitions[:code_length] || 10
|
6
8
|
dict = [('a'..'z'),('A'..'Z'),(0..9)].map{|i| i.to_a}.flatten
|
@@ -18,6 +20,14 @@ module Recognition
|
|
18
20
|
# Make sure we have an amount beforehand
|
19
21
|
if defined? self.amount
|
20
22
|
if self.redeemable? recognizable
|
23
|
+
# Call custom validators
|
24
|
+
if defined? self.class.voucher_validators
|
25
|
+
self.class.voucher_validators.each do |validator|
|
26
|
+
# quit if any validator returned false
|
27
|
+
return if send(validator) == false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
# If all went well:
|
21
31
|
Database.redeem_voucher recognizable.id, self.code, self.amount
|
22
32
|
end
|
23
33
|
end
|
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.3.
|
4
|
+
version: 0.3.7
|
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-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -181,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: '0'
|
182
182
|
segments:
|
183
183
|
- 0
|
184
|
-
hash:
|
184
|
+
hash: 111551344428763194
|
185
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
186
|
none: false
|
187
187
|
requirements:
|
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
190
|
version: '0'
|
191
191
|
segments:
|
192
192
|
- 0
|
193
|
-
hash:
|
193
|
+
hash: 111551344428763194
|
194
194
|
requirements: []
|
195
195
|
rubyforge_project:
|
196
196
|
rubygems_version: 1.8.23
|