mini_defender 0.1.6 → 0.1.8

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: c249768a094c4518199ffd28c11b23cedc2795f2fd7b314066dd1ab8735ad64a
4
- data.tar.gz: 03db289c1919edc2d6cfffd6db6f5ae70011a679edb1af8ae5ee7b915faa06b2
3
+ metadata.gz: 47b6afaf1b24a5e5c1eb02e7cdeaea106dffadcd5d74aab23abdc37aa202ad60
4
+ data.tar.gz: afb0f175e312dfe5f9d6f70bd580724bf9494dee46ec67f770c2b5f3f2ddbf6a
5
5
  SHA512:
6
- metadata.gz: bcb1491ce3eaef31ea2e713afd7651a5dd397ace80467eeab303086cda2ab1f23e8e044ace47f999ea49c62a31318650387044e4ae28c5e5d2204563c2746c33
7
- data.tar.gz: 6bacb39daaf34e5e5d2685bb6e93629a8d390dc5dc0f7776495a4a1b003cb3e4939d9c67b2a3ccbe481758f24617707776b5768dc5b34b20d14995e1c33e67f4
6
+ metadata.gz: eb1cbaa6543c2b698ced1eaec693b0ef01f887c2e6c2f4754769fba8a56d2682d514286787318fe35235d88c800ebcbeffc8f1edc6fc093ecd7ded77c65ef464
7
+ data.tar.gz: eb521e27acab3793b1ab1ab2c0da613bc7d9674db35df10bf29b631dac1a62acb130d837603af8fc3651ca7fc483887446de4aaa9a36c6560dbd76d6e3880d67
@@ -7,6 +7,10 @@ class MiniDefender::Rules::CreditCard < MiniDefender::Rules::Luhn
7
7
  'credit_card'
8
8
  end
9
9
 
10
+ def passes?(attribute, value, validator)
11
+ super(attribute, value, validator) && value.length >= 8 && value.length <= 19
12
+ end
13
+
10
14
  def message(attribute, value, validator)
11
15
  'The value must be a proper credit/debit card number.'
12
16
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MiniDefender::Rules::ExpiryMonth < MiniDefender::Rule
4
+ def self.signature
5
+ 'expiry_month'
6
+ end
7
+
8
+ def coerce(value)
9
+ value.to_s.rjust(2, '0')
10
+ end
11
+
12
+ def passes?(attribute, value, validator)
13
+ return false unless value.to_s.match?(/^\d{1,2}$/)
14
+
15
+ value = value.to_i
16
+ value >= 1 && value <= 12
17
+ end
18
+
19
+ def message(attribute, value, validator)
20
+ 'Invalid expiry month.'
21
+ end
22
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MiniDefender::Rules::ExpiryYear < MiniDefender::Rule
4
+ def self.signature
5
+ 'expiry_year'
6
+ end
7
+
8
+ def coerce(value)
9
+ value = value.to_i
10
+ value += century if value < 100
11
+ value.to_s
12
+ end
13
+
14
+ def passes?(attribute, value, validator)
15
+ return false unless value.to_s.match?(/^(\d{2}|\d{4})$/)
16
+
17
+ value = value.to_i
18
+ value += century if value < 100
19
+ value >= 1900
20
+ end
21
+
22
+ def message(attribute, value, validator)
23
+ 'Invalid expiry year.'
24
+ end
25
+
26
+ private
27
+
28
+ # @param [Integer]
29
+ def century
30
+ year = Time.now.year
31
+ year - (year % 100)
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MiniDefender
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.8"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_defender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ali Alhoshaiyan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-29 00:00:00.000000000 Z
11
+ date: 2022-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -122,6 +122,8 @@ files:
122
122
  - lib/mini_defender/rules/excluded_without.rb
123
123
  - lib/mini_defender/rules/exists.rb
124
124
  - lib/mini_defender/rules/expiry_date.rb
125
+ - lib/mini_defender/rules/expiry_month.rb
126
+ - lib/mini_defender/rules/expiry_year.rb
125
127
  - lib/mini_defender/rules/file.rb
126
128
  - lib/mini_defender/rules/filled.rb
127
129
  - lib/mini_defender/rules/greater_than.rb