credit_card_support 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.txt ADDED
@@ -0,0 +1,13 @@
1
+ 1.0.2
2
+
3
+ Readme improvement.
4
+
5
+
6
+ 1.0.1
7
+
8
+ Redid validator loading - its automatically loaded if ActiveModel is loaded.
9
+
10
+
11
+ 1.0.0
12
+
13
+ Initial.
data/README.md CHANGED
@@ -12,18 +12,18 @@ Basic usage
12
12
  -----------
13
13
 
14
14
  ```ruby
15
- credit_card = CreditCardSupport.Instrument.new(
15
+ credit_card = CreditCardSupport::Instrument.new(
16
16
  number: '4222222222222',
17
- expire_year: 13,
18
- expire_month: 11,
19
- holder_name: 'A B' # optional!
20
- verification: '1234' # optional!
17
+ expiry_year: 13,
18
+ expiry_month: 11,
19
+ holder_name: 'A B', # optional
20
+ verification: '1234' # optional
21
21
  )
22
22
 
23
- credit_card.expired? # returns false
24
- credit_card.expire_date # Date (last day of the month for expire month)
25
- credit_card.issuer # VISA
26
- credit_card.is_testcard? # true
23
+ credit_card.is_expired? # returns false
24
+ credit_card.expiration_date # Date (last day of the month for expire month)
25
+ credit_card.issuer # :visa
26
+ credit_card.is_testcard? # true
27
27
  ```
28
28
 
29
29
  For better understanding read the source and RSpec.
@@ -39,13 +39,13 @@ Validations support
39
39
  ```ruby
40
40
  class CreditCard < ActiveRecord::Base
41
41
 
42
- attr_accessable :number, :expiry_year, :expiry_month
42
+ attr_accessible :number, :expiry_year, :expiry_month
43
43
 
44
44
  validates :number, credit_card: {
45
45
  expiry_year: :expiry_year, # default: :expiry_year
46
46
  expiry_month: :expiry_month, # default: :expiry_month
47
47
  allowed_issuers: [:visa, :mastercard], # default: all known issuers
48
- allow_testcards: !Rails.env.production? # default: False
48
+ allow_testcards: true # default: False
49
49
  }
50
50
 
51
51
  end
@@ -53,6 +53,8 @@ end
53
53
 
54
54
  ##### Only ActiveModel
55
55
 
56
+ ###### Rails 3
57
+
56
58
  ```ruby
57
59
  class CreditCard
58
60
  extend ActiveModel::Naming
@@ -61,13 +63,34 @@ class CreditCard
61
63
  include ActiveModel::Conversion
62
64
 
63
65
  attr_accessor :number, :expiry_year, :expiry_month
64
- attr_accessable :number, :expiry_year, :expiry_month
66
+
67
+ def initialize(opts={})
68
+ opts.each {|key, value| send(:"#{key}=", value) }
69
+ end
70
+
71
+ validates :number, credit_card: {
72
+ expiry_year: :expiry_year, # default: :expiry_year
73
+ expiry_month: :expiry_month, # default: :expiry_month
74
+ allowed_issuers: [:visa, :mastercard], # default: all known issuers
75
+ allow_testcards: true # default: False
76
+ }
77
+
78
+ end
79
+ ```
80
+
81
+ ###### Rails 4
82
+
83
+ ```ruby
84
+ class CreditCard
85
+ include ActiveModel::Model
86
+
87
+ attr_accessor :number, :expiry_year, :expiry_month
65
88
 
66
89
  validates :number, credit_card: {
67
90
  expiry_year: :expiry_year, # default: :expiry_year
68
91
  expiry_month: :expiry_month, # default: :expiry_month
69
92
  allowed_issuers: [:visa, :mastercard], # default: all known issuers
70
- allow_testcards: !Rails.env.production? # default: False
93
+ allow_testcards: true # default: False
71
94
  }
72
95
 
73
96
  end
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module CreditCardSupport
2
4
 
3
5
  # Usage:
@@ -2,7 +2,7 @@ module CreditCardSupport
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- PATCH = 1
5
+ PATCH = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: credit_card_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
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: 2012-09-21 00:00:00.000000000 Z
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Detects issuer from a number, has ActiveModel validations and translations
15
15
  support.
@@ -21,6 +21,7 @@ files:
21
21
  - Gemfile
22
22
  - README.md
23
23
  - LICENSE.txt
24
+ - HISTORY.txt
24
25
  - lib/credit_card_support/credit_card_validator.rb
25
26
  - lib/credit_card_support/instrument.rb
26
27
  - lib/credit_card_support/locale/en.yml