credit_card_validations 5.0.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '03328c061e5430470ceb2f0d4af1359d58aa272c370c16eb3484574c39e97e63'
4
- data.tar.gz: e9b394824f0faeba5cade67212f126c4589bd4ba825de1cb1f2f079f9d6cad72
3
+ metadata.gz: c955ab578ccc68fa1525166a326408c8f7ceedb16dfd197b4cee363453f4148c
4
+ data.tar.gz: f66d2c0969e1aac24c04463633e4466c997527b4d9b3a11f36914d207eea08dc
5
5
  SHA512:
6
- metadata.gz: 7a51d59395f02c3cfb2d3b5ab68bf628f97eb71f711871ea6e8994372f54b7fa366be11869ac7b7568acae37399f0424446028a1272ad7c6823d7ee489a5df05
7
- data.tar.gz: 34b9d7bef2e7969c0dfd88bdc0310831a1875abf14e434affdd603f7eed0f11067dc1dab9a9bce8c793f5792e0091abd5f7b7f8e70420f4f1705d1dff064eceb
6
+ metadata.gz: 96231d43a74789045abf1df806f085d649fb9400c749f2334eaa08771fcc2e369831ae65a74698484fe2b8a531241e8effa4dc6d5258f29523af33319dae435c
7
+ data.tar.gz: 4926b30dce4ca818b0ab18e7711ba96b8145a461703c3659c3eff1368fa860760febb476d1086b7f7addce5608ee501986c30a2dcb13cdab68f26a78a98e18d7
@@ -19,12 +19,11 @@ jobs:
19
19
  env:
20
20
  RAILS_VERSION: ${{ matrix.rails }}
21
21
  steps:
22
- - uses: actions/checkout@v2
23
- - uses: actions/setup-ruby@v1
22
+ - uses: actions/checkout@v3
23
+ - uses: ruby/setup-ruby@v1
24
24
  with:
25
25
  ruby-version: ${{ matrix.ruby-version }}
26
+ bundler-cache: true
26
27
  - name: Run tests
27
28
  run: |
28
- gem install bundler -v '< 2'
29
- bundle install
30
29
  bundle exec rake
data/Changelog.md CHANGED
@@ -1,3 +1,18 @@
1
+ # 6.0.0
2
+ * changes to discover branch
3
+ * allows to configure usage of own yaml brands file
4
+
5
+ # 5.0.0
6
+ * rails 7 support
7
+ * drop rails support < 5.2
8
+
9
+ # 4.1.0
10
+ * changes to disover and maesto rules
11
+
12
+ # 4.0.0
13
+ * support rails 6
14
+ * test against ruby 3.0, drop ruby 2.1 support
15
+
1
16
  # 3.5.1
2
17
  * Bump activemodel and activesupport versions
3
18
 
data/README.md CHANGED
@@ -146,6 +146,18 @@ require 'credit_card_validations/plugins/laser'
146
146
  require 'credit_card_validations/plugins/diners_us'
147
147
  ```
148
148
 
149
+
150
+ ### Configuration
151
+
152
+ In order to override default data source you can copy [original one](https://github.com/didww/credit_card_validations/blob/master/lib/data/brands.yaml) , change it and configure during rails initializer
153
+
154
+ ```ruby
155
+ CreditCardValidations.configure do |config|
156
+ config.source = '/path/to/my_brands.yml'
157
+ end
158
+ ```
159
+
160
+
149
161
  ## Contributing
150
162
 
151
163
  1. Fork it
@@ -0,0 +1,9 @@
1
+ module CreditCardValidations
2
+ class Configuration
3
+ attr_accessor :source
4
+
5
+ def initialize
6
+ @source = nil
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module CreditCardValidations
2
- VERSION = '5.0.0'
2
+ VERSION = '6.0.0'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'credit_card_validations/version'
2
+ require 'credit_card_validations/configuration'
2
3
  require 'credit_card_validations/error'
3
4
  require 'active_model'
4
5
  require 'active_support/core_ext'
@@ -14,16 +15,36 @@ module CreditCardValidations
14
15
  autoload :Factory, 'credit_card_validations/factory'
15
16
  autoload :Mmi, 'credit_card_validations/mmi'
16
17
 
18
+ attr_accessor :configuration
19
+
20
+ def self.configuration
21
+ @configuration ||= Configuration.new
22
+ end
23
+
24
+ def self.reset
25
+ @configuration = Configuration.new
26
+ end
27
+
28
+ def self.configure
29
+ yield(configuration)
30
+ reload!
31
+ end
17
32
 
18
33
  def self.add_brand(key, rules, options = {})
19
34
  Detector.add_brand(key, rules, options)
20
35
  end
21
36
 
22
- DATA = YAML.load_file(File.join(File.dirname(__FILE__), 'data', 'brands.yaml')) || {}
37
+ def self.source
38
+ configuration.source || File.join(File.join(File.dirname(__FILE__)), 'data', 'brands.yaml')
39
+ end
40
+
41
+ def self.data
42
+ YAML.load_file(source) || {}
43
+ end
23
44
 
24
45
  def self.reload!
25
46
  Detector.brands = {}
26
- DATA.each do |key, data|
47
+ data.each do |key, data|
27
48
  add_brand(key, data.fetch(:rules), data.fetch(:options, {}))
28
49
  end
29
50
  end
data/lib/data/brands.yaml CHANGED
@@ -486,16 +486,14 @@
486
486
  - '303'
487
487
  - '304'
488
488
  - '305'
489
+ - '3095'
490
+ - '36'
489
491
  - '38'
490
492
  - '39'
491
493
  - '60110'
492
494
  - '60112'
493
495
  - '60113'
494
- - '601140'
495
- - '601141'
496
- - '601142'
497
- - '601143'
498
- - '601144'
496
+ - '60114'
499
497
  - '601174'
500
498
  - '601177'
501
499
  - '601178'
@@ -7,6 +7,39 @@ describe CreditCardValidations do
7
7
  CreditCardValidations.reload!
8
8
  end
9
9
 
10
+
11
+ describe 'configure' do
12
+
13
+ let(:number) { '6111111180456137' }
14
+
15
+ before do
16
+ expect(card_detector.valid?(:discover)).must_equal false
17
+ CreditCardValidations.configure do |config|
18
+ config.source = OVERRIDED_BRANDS_FILE
19
+ end
20
+ end
21
+
22
+ let(:card_detector) {
23
+ detector(number)
24
+ }
25
+
26
+ it 'should generate overrided discover' do
27
+ discover = CreditCardValidations::Factory.random(:discover)
28
+ expect(detector(discover).valid?('DiscoverBrand')).must_equal true
29
+ end
30
+
31
+ it 'should detect patched discover' do
32
+ expect(card_detector.valid?(:discover)).must_equal true
33
+ expect(card_detector.valid?(:visa)).must_equal false
34
+ end
35
+
36
+ after do
37
+ CreditCardValidations.reset
38
+ CreditCardValidations.reload!
39
+ end
40
+
41
+ end
42
+
10
43
  describe 'MMI' do
11
44
  it 'should detect issuer category' do
12
45
  d = detector(VALID_NUMBERS[:visa].first)
@@ -0,0 +1,19 @@
1
+ ---
2
+ :visa:
3
+ :rules:
4
+ - :length:
5
+ - 13
6
+ - 16
7
+ - 19
8
+ :prefixes:
9
+ - '4'
10
+ :options:
11
+ :brand_name: Visa
12
+ :discover:
13
+ :rules:
14
+ - :length:
15
+ - 16
16
+ :prefixes:
17
+ - '61111111'
18
+ :options:
19
+ :brand_name: DiscoverBrand
data/spec/test_helper.rb CHANGED
@@ -15,4 +15,5 @@ require 'models/credit_card'
15
15
 
16
16
  VALID_NUMBERS = YAML.load_file File.join(File.dirname(__FILE__), 'fixtures/valid_cards.yml')
17
17
  INVALID_NUMBERS = YAML.load_file File.join(File.dirname(__FILE__), 'fixtures/invalid_cards.yml')
18
+ OVERRIDED_BRANDS_FILE = File.join(File.dirname(__FILE__), 'fixtures/overrided_brands.yml')
18
19
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: credit_card_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-11 00:00:00.000000000 Z
11
+ date: 2022-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -124,6 +124,7 @@ files:
124
124
  - credit_card_validations.gemspec
125
125
  - lib/active_model/credit_card_number_validator.rb
126
126
  - lib/credit_card_validations.rb
127
+ - lib/credit_card_validations/configuration.rb
127
128
  - lib/credit_card_validations/detector.rb
128
129
  - lib/credit_card_validations/error.rb
129
130
  - lib/credit_card_validations/factory.rb
@@ -139,6 +140,7 @@ files:
139
140
  - spec/credit_card_validations_spec.rb
140
141
  - spec/factory_spec.rb
141
142
  - spec/fixtures/invalid_cards.yml
143
+ - spec/fixtures/overrided_brands.yml
142
144
  - spec/fixtures/valid_cards.yml
143
145
  - spec/models/credit_card.rb
144
146
  - spec/string_spec.rb
@@ -175,6 +177,7 @@ test_files:
175
177
  - spec/credit_card_validations_spec.rb
176
178
  - spec/factory_spec.rb
177
179
  - spec/fixtures/invalid_cards.yml
180
+ - spec/fixtures/overrided_brands.yml
178
181
  - spec/fixtures/valid_cards.yml
179
182
  - spec/models/credit_card.rb
180
183
  - spec/string_spec.rb