validaty 0.0.2 → 0.0.3
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 +39 -1
- data/lib/validators/url_validator.rb +28 -0
- data/lib/validaty/version.rb +1 -1
- data/lib/validaty.rb +1 -0
- metadata +4 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd38ce500188e65588670a3a621fbf20d43394084096647dd9d10f4d4ac5fa59
|
4
|
+
data.tar.gz: 15fc45c052db20824ec3512e45fd88cff47508711b57ddc9e9faddc790a46142
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1f7117aeff6951aeff8f5f6975071c4aff263a42e28f43ab64d1166001336cc3e6a8dd3ea6d4572f320fa50cf9f683c49d5c9100146cc638ee3830432340376
|
7
|
+
data.tar.gz: 8fb94c2f5d212f59635c90d0ef42712977e5075801744d992845c9796430078a6c681af0749b71c91c0af79e86cac724193a0836550a687642e2713bc38bd236
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Validaty has basic validations for Rails application
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ru
|
10
|
-
gem "validaty", "~> 0.0.
|
10
|
+
gem "validaty", "~> 0.0.3"
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -31,6 +31,7 @@ create_table "pixes", force: :cascade do |t|
|
|
31
31
|
t.uuid "public_id", null: false
|
32
32
|
t.integer "kind"
|
33
33
|
t.string "key", null: false
|
34
|
+
t.string "url", null: false
|
34
35
|
t.boolean "accepted", null: false, default: false
|
35
36
|
t.date "schedule_date", null: false
|
36
37
|
t.datetime "created_at", null: false
|
@@ -53,9 +54,46 @@ class Pix < ApplicationRecord
|
|
53
54
|
validates :key, uuid: true, if: :evp?
|
54
55
|
validates :accepted, boolean: true
|
55
56
|
validates :schedule_date, date: true
|
57
|
+
|
58
|
+
validates :url, presence: true, url: true
|
59
|
+
# OR
|
60
|
+
validates :url, presence: true, url: {domain: "domain.com"}
|
61
|
+
# OR
|
62
|
+
validates :url, presence: true, url: {starts_with: "https://domain.com/path"}
|
56
63
|
end
|
57
64
|
```
|
58
65
|
|
66
|
+
## Translations
|
67
|
+
|
68
|
+
If you using url validation with options `:domain` or `:starts_with`, you must add in your locales:
|
69
|
+
|
70
|
+
```yaml
|
71
|
+
pt-BR:
|
72
|
+
...
|
73
|
+
errors:
|
74
|
+
messages:
|
75
|
+
domain: "precisa ser do domínio %{domain}"
|
76
|
+
starts_with: "precisa começar com %{start}"
|
77
|
+
```
|
78
|
+
|
79
|
+
## Troubleshooting
|
80
|
+
|
81
|
+
If you need use CPF or CNPJ validation you need add 2 acronym to `config/initializers/inflections.rb`
|
82
|
+
|
83
|
+
```rb
|
84
|
+
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
85
|
+
inflect.acronym "CPF"
|
86
|
+
inflect.acronym "CNPJ"
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
If you can't add inflections in your application, the suggestion is create an initializer `config/initializers/validaty.rb` with this content:
|
91
|
+
|
92
|
+
```rb
|
93
|
+
CnpjValidator = CNPJValidator
|
94
|
+
CpfValidator = CPFValidator
|
95
|
+
```
|
96
|
+
|
59
97
|
## Contributing
|
60
98
|
|
61
99
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/validaty.
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
3
|
+
class UrlValidator < Validaty::AllowBlankBase
|
4
|
+
def validate_each(resource, attribute, value)
|
5
|
+
if options[:domain].present? && URI.parse(value).host != options[:domain]
|
6
|
+
resource.errors.add(attribute, :domain, domain: options[:domain])
|
7
|
+
end
|
8
|
+
|
9
|
+
if options[:starts_with].present? && !value.starts_with?(options[:starts_with])
|
10
|
+
resource.errors.add(attribute, :starts_with, start: options[:starts_with])
|
11
|
+
end
|
12
|
+
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def valid_value?(url)
|
19
|
+
uri = URI.parse(url)
|
20
|
+
uri.host.present?
|
21
|
+
rescue URI::InvalidURIError
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
def default_message_error
|
26
|
+
:invalid
|
27
|
+
end
|
28
|
+
end
|
data/lib/validaty/version.rb
CHANGED
data/lib/validaty.rb
CHANGED
@@ -8,6 +8,7 @@ require_relative "validators/cpf_validator"
|
|
8
8
|
require_relative "validators/date_validator"
|
9
9
|
require_relative "validators/email_validator"
|
10
10
|
require_relative "validators/phone_validator"
|
11
|
+
require_relative "validators/url_validator"
|
11
12
|
require_relative "validators/uuid_validator"
|
12
13
|
|
13
14
|
module Validaty
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validaty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lavenda Software
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-07 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: cpf_cnpj
|
@@ -38,7 +37,6 @@ dependencies:
|
|
38
37
|
- - ">="
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: '0'
|
41
|
-
description:
|
42
40
|
email:
|
43
41
|
- lavenda@lavenda.com.br
|
44
42
|
executables: []
|
@@ -58,6 +56,7 @@ files:
|
|
58
56
|
- lib/validators/date_validator.rb
|
59
57
|
- lib/validators/email_validator.rb
|
60
58
|
- lib/validators/phone_validator.rb
|
59
|
+
- lib/validators/url_validator.rb
|
61
60
|
- lib/validators/uuid_validator.rb
|
62
61
|
- lib/validaty.rb
|
63
62
|
- lib/validaty/allow_blank_base.rb
|
@@ -73,7 +72,6 @@ metadata:
|
|
73
72
|
homepage_uri: https://github.com/LavendaSoftware/validaty
|
74
73
|
source_code_uri: https://github.com/LavendaSoftware/validaty/blob/main/README.md
|
75
74
|
changelog_uri: https://github.com/LavendaSoftware/validaty/commits/main
|
76
|
-
post_install_message:
|
77
75
|
rdoc_options: []
|
78
76
|
require_paths:
|
79
77
|
- lib
|
@@ -88,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
86
|
- !ruby/object:Gem::Version
|
89
87
|
version: '0'
|
90
88
|
requirements: []
|
91
|
-
rubygems_version: 3.
|
92
|
-
signing_key:
|
89
|
+
rubygems_version: 3.6.4
|
93
90
|
specification_version: 4
|
94
91
|
summary: Validaty has basic validations for Rails application
|
95
92
|
test_files: []
|