validation_contract 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +6 -0
- data/README.md +43 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/validation_contract/version.rb +3 -0
- data/lib/validation_contract.rb +49 -0
- data/validation_contract-0.1.5.gem +0 -0
- data/validation_contract.gemspec +25 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 44d2eaed753fd4a8c1d3f6d44c2e7c3e38fac28b
|
4
|
+
data.tar.gz: bfd889fa4e7b390b779a212ab5c65a06226a607d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 915034aae5c4134b46f3f09ff53477efb108f11fd841baf11b082cb5653e8af53cf23d97776f9d5829eba613d81210858121dfdee0c99e2e31b3ac9869d454fd
|
7
|
+
data.tar.gz: '097801b3aea138464ee925867593cf568bb38e81b0ca02f3e7a149c88bfbd184b3f36c37c30712907a9beb89acbc93a882363d20b6c2656dc3aea2ec2ce35a81'
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# ValidationContract
|
2
|
+
|
3
|
+
Validations of the day day for your rails project
|
4
|
+
|
5
|
+
With this gem you will have several validations that are common on day day and that will make life much easier for dev. Validations can be returned in a simple and standardized way.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'validation_contract'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
gem install validation_contract
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
require 'validation_contract'
|
26
|
+
|
27
|
+
validation_contract = ValidationContract.new
|
28
|
+
|
29
|
+
Verifying an invalid email, the return will be an array with message and its validation inside, this will occur for all the desired validations.
|
30
|
+
|
31
|
+
validation_contract.is_email('teste.com', 'This email is invalid') => "{message: 'This email is invalid'}"
|
32
|
+
|
33
|
+
By checking a valid email, nothing will be added in the return, leaving only the validations that are with incorrect values.
|
34
|
+
|
35
|
+
validation_contract.is_email('teste@teste.com', 'This email is invalid') => "nil"
|
36
|
+
|
37
|
+
Suggestion for the validations. Perform all the necessary validations and then before executing the desired process use the following:
|
38
|
+
|
39
|
+
if !validation_contract.is_valid
|
40
|
+
return validation_contract.errros
|
41
|
+
end
|
42
|
+
|
43
|
+
This will check if there is any invalid field, if there is an arry returned with all the validations. This type of validation is very good for APIs that are being used for a form with many fields, so you return to the FRONT all errors at one time.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "validation_contract"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
class ValidationContract
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
@errors = []
|
5
|
+
end
|
6
|
+
|
7
|
+
def is_required value, message
|
8
|
+
if !value || value.length() <= 0
|
9
|
+
@errors.push({message: message})
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def has_min_len value, min, message
|
14
|
+
if !value || value.length() < min
|
15
|
+
@errors.push({message: message})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def has_max_len value, max, message
|
20
|
+
if !value || value.length() > max
|
21
|
+
@errors.push({message: message})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def is_fixed_len value, len, message
|
26
|
+
if value.length() != len
|
27
|
+
@errors.push({message: message})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def is_email value, message
|
32
|
+
if !value.match(/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i)
|
33
|
+
@errors.push({message: message})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def erros
|
38
|
+
return @errors
|
39
|
+
end
|
40
|
+
|
41
|
+
def clear
|
42
|
+
return @errors = []
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_valid
|
46
|
+
return @errors.length == 0
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
Binary file
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "validation_contract/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "validation_contract"
|
8
|
+
spec.version = ValidationContract::VERSION
|
9
|
+
spec.authors = ["grassiricardo"]
|
10
|
+
spec.email = ["grassiricardorg@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Validations of the day day for your rails project.}
|
13
|
+
spec.description = %q{With this gem you will have several validations that are common on day day and that will make life much easier for dev. Validations can be returned in a simple and standardized way..}
|
14
|
+
spec.homepage = ""
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validation_contract
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- grassiricardo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: With this gem you will have several validations that are common on day
|
42
|
+
day and that will make life much easier for dev. Validations can be returned in
|
43
|
+
a simple and standardized way..
|
44
|
+
email:
|
45
|
+
- grassiricardorg@gmail.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/validation_contract.rb
|
57
|
+
- lib/validation_contract/version.rb
|
58
|
+
- validation_contract-0.1.5.gem
|
59
|
+
- validation_contract.gemspec
|
60
|
+
homepage: ''
|
61
|
+
licenses: []
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.6.13
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Validations of the day day for your rails project.
|
83
|
+
test_files: []
|