defra_ruby_validators 3.0.1 → 3.1.0
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.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/config/locales/defra_ruby/validators/companies_house_number_validator/en.yml +1 -1
- data/lib/defra_ruby/validators/companies_house_number_validator.rb +4 -3
- data/lib/defra_ruby/validators/companies_house_service.rb +26 -6
- data/lib/defra_ruby/validators/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ebc819c7234646da1f7ae2f33a2560bd108e2b7165e0baca0656d135244f348a
|
|
4
|
+
data.tar.gz: dccbcfa5fa4e7cff92a616cba000f608ecfedb042e659e16210c6bc43026e5d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: de0050634d392a792b6f642a9b68ca8a5ad30fa74ce71d8393859358f27604900b89ed0ca4ab3f2e417e4f2c8595b9e2f0eb50c192f5e0469c1e813ef8d214cc
|
|
7
|
+
data.tar.gz: 73031c690a724e7948769f2dab5518c8e8b5a86ff1ea1a26cc4686e7c6997ebb89206dd3fc830c0e264edfcf8763d6e314d17705c2f65a9c208a0b3fe782b7e7
|
data/README.md
CHANGED
|
@@ -63,9 +63,10 @@ This validator checks the company registration number provided. Specifically it
|
|
|
63
63
|
If the format is valid, it then makes a call to Companies House to validate that the number
|
|
64
64
|
|
|
65
65
|
- is recognised
|
|
66
|
-
- belongs to an
|
|
66
|
+
- belongs to a company with an allowed status
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
Allowed statuses default to `active` and `voluntary-arrangement`, preserving the existing behaviour.
|
|
69
|
+
Services can override this when they need to accept other Companies House statuses.
|
|
69
70
|
|
|
70
71
|
Add it to your model or form object using
|
|
71
72
|
|
|
@@ -79,6 +80,14 @@ The company number also accepts a `company_type` option. This checks the `type`
|
|
|
79
80
|
validates :company_no, "defra_ruby/validators/companies_house_number": { company_type: "ltd" }
|
|
80
81
|
```
|
|
81
82
|
|
|
83
|
+
The allowed Companies House statuses can be changed with the `permitted_statuses` option:
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
validates :company_no, "defra_ruby/validators/companies_house_number": {
|
|
87
|
+
permitted_statuses: %i[active voluntary-arrangement liquidation]
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
82
91
|
Note: to mock the Companies House service with the `company_type` option, you will need to be running at least v2.2.0 of [defra-ruby-mocks](https://github.com/DEFRA/defra-ruby-mocks#companies-house).
|
|
83
92
|
|
|
84
93
|
### Email
|
|
@@ -7,5 +7,5 @@ en:
|
|
|
7
7
|
not_found: Companies House couldn't find a company with this number
|
|
8
8
|
inactive: Your company must be registered as an active company
|
|
9
9
|
unsupported_company_type: Your company must be registered as a limited company or a limited liability partnership
|
|
10
|
-
argument_error: Invalid permitted_types value. It must be nil, a string or an array
|
|
10
|
+
argument_error: Invalid permitted_types or permitted_statuses value. It must be nil, a string or an array.
|
|
11
11
|
error: There was an error connecting with Companies House. Hopefully this is a one off and will work if you try again.
|
|
@@ -17,7 +17,8 @@ module DefraRuby
|
|
|
17
17
|
return false unless format_is_valid?(record, attribute, value)
|
|
18
18
|
|
|
19
19
|
permitted_types = options[:permitted_types]
|
|
20
|
-
|
|
20
|
+
permitted_statuses = options[:permitted_statuses]
|
|
21
|
+
validate_with_companies_house(record, attribute, value, permitted_types, permitted_statuses)
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
private
|
|
@@ -37,8 +38,8 @@ module DefraRuby
|
|
|
37
38
|
false
|
|
38
39
|
end
|
|
39
40
|
|
|
40
|
-
def validate_with_companies_house(record, attribute, value, permitted_types)
|
|
41
|
-
case CompaniesHouseService.new(company_number: value, permitted_types:).status
|
|
41
|
+
def validate_with_companies_house(record, attribute, value, permitted_types, permitted_statuses)
|
|
42
|
+
case CompaniesHouseService.new(company_number: value, permitted_types:, permitted_statuses:).status
|
|
42
43
|
when :active
|
|
43
44
|
true
|
|
44
45
|
when :inactive
|
|
@@ -5,11 +5,18 @@ require "defra_ruby/companies_house"
|
|
|
5
5
|
module DefraRuby
|
|
6
6
|
module Validators
|
|
7
7
|
class CompaniesHouseService
|
|
8
|
-
|
|
8
|
+
DEFAULT_PERMITTED_STATUSES = %i[active voluntary-arrangement].freeze
|
|
9
|
+
ARGUMENT_ERROR_TRANSLATION_KEY = "defra_ruby.validators.CompaniesHouseNumberValidator.argument_error"
|
|
10
|
+
|
|
11
|
+
private_constant :ARGUMENT_ERROR_TRANSLATION_KEY
|
|
12
|
+
|
|
13
|
+
def initialize(company_number:, permitted_types: nil, permitted_statuses: nil)
|
|
9
14
|
@company_number = company_number
|
|
10
15
|
@permitted_types = permitted_types
|
|
16
|
+
@permitted_statuses = permitted_statuses
|
|
11
17
|
|
|
12
18
|
validate_permitted_types
|
|
19
|
+
validate_permitted_statuses
|
|
13
20
|
end
|
|
14
21
|
|
|
15
22
|
def status
|
|
@@ -27,15 +34,28 @@ module DefraRuby
|
|
|
27
34
|
end
|
|
28
35
|
|
|
29
36
|
def validate_permitted_types
|
|
30
|
-
return if @permitted_types
|
|
37
|
+
return if valid_permitted_option?(@permitted_types)
|
|
38
|
+
|
|
39
|
+
raise ArgumentError, I18n.t(ARGUMENT_ERROR_TRANSLATION_KEY)
|
|
40
|
+
end
|
|
31
41
|
|
|
32
|
-
|
|
42
|
+
def validate_permitted_statuses
|
|
43
|
+
return if valid_permitted_option?(@permitted_statuses)
|
|
33
44
|
|
|
34
|
-
raise ArgumentError, I18n.t(
|
|
45
|
+
raise ArgumentError, I18n.t(ARGUMENT_ERROR_TRANSLATION_KEY)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def valid_permitted_option?(option)
|
|
49
|
+
option.nil? || option.is_a?(String) || option.is_a?(Array)
|
|
35
50
|
end
|
|
36
51
|
|
|
37
52
|
def status_is_allowed?(companies_house_response)
|
|
38
|
-
|
|
53
|
+
normalised_permitted_statuses.include?(companies_house_response[:company_status].to_s.to_sym)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def normalised_permitted_statuses
|
|
57
|
+
@permitted_statuses ||= DEFAULT_PERMITTED_STATUSES
|
|
58
|
+
Array(@permitted_statuses).map { |status| status.to_s.to_sym }
|
|
39
59
|
end
|
|
40
60
|
|
|
41
61
|
def company_type_is_allowed?(companies_house_response)
|
|
@@ -48,7 +68,7 @@ module DefraRuby
|
|
|
48
68
|
when Array
|
|
49
69
|
@permitted_types.include?(companies_house_response[:company_type].to_s)
|
|
50
70
|
else
|
|
51
|
-
raise ArgumentError, I18n.t(
|
|
71
|
+
raise ArgumentError, I18n.t(ARGUMENT_ERROR_TRANSLATION_KEY)
|
|
52
72
|
end
|
|
53
73
|
end
|
|
54
74
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: defra_ruby_validators
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0
|
|
4
|
+
version: 3.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Defra
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-05-08 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: activemodel
|
|
@@ -190,6 +191,7 @@ licenses:
|
|
|
190
191
|
metadata:
|
|
191
192
|
allowed_push_host: https://rubygems.org
|
|
192
193
|
rubygems_mfa_required: 'true'
|
|
194
|
+
post_install_message:
|
|
193
195
|
rdoc_options: []
|
|
194
196
|
require_paths:
|
|
195
197
|
- lib
|
|
@@ -204,7 +206,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
204
206
|
- !ruby/object:Gem::Version
|
|
205
207
|
version: '0'
|
|
206
208
|
requirements: []
|
|
207
|
-
rubygems_version: 3.
|
|
209
|
+
rubygems_version: 3.4.10
|
|
210
|
+
signing_key:
|
|
208
211
|
specification_version: 4
|
|
209
212
|
summary: Defra ruby on rails validations
|
|
210
213
|
test_files: []
|