recognition 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
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. Your model might have the following attributes:
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
- acts_as_voucher code_length: 14
93
+ acts_as_voucher code_length: 14
90
94
  end
91
95
 
92
96
  Then, you may do:
@@ -8,7 +8,7 @@ module Recognition
8
8
  def set_defaults
9
9
  line = "t.boolean :reusable"
10
10
  gsub_file Dir.glob("db/migrate/*_create_vouchers.rb").first, /(#{Regexp.escape(line)})/mi do |match|
11
- "#{match}, default: fals"
11
+ "#{match}, default: false"
12
12
  end
13
13
  end
14
14
 
@@ -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
@@ -1,4 +1,4 @@
1
1
  module Recognition
2
2
  # Current Version
3
- VERSION = "0.3.6"
3
+ VERSION = "0.3.7"
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.3.6
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-20 00:00:00.000000000 Z
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: 3949866912608946474
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: 3949866912608946474
193
+ hash: 111551344428763194
194
194
  requirements: []
195
195
  rubyforge_project:
196
196
  rubygems_version: 1.8.23