soul_validations 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/soul_validations.rb +44 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 73ab3489a378f6621e1cac9c95cf412ecc1e981730c973e7371e5f374b7ad736
4
+ data.tar.gz: 6323191191030ede6737e3647de2f647760532ce26c1f89f302600e8864a1a96
5
+ SHA512:
6
+ metadata.gz: 69d3ffb90b9e7dafe2a266c9490dfe7d0feb3e51fecd995fac20214b47be1d39ad3f7b476a36bf084153d26e26a3e667b1a80019609c06dd5505d945348d8fae
7
+ data.tar.gz: 1f16eb6a3b9791054efd1db3805ecaa00114f1d3362b0e7a4833afa8eae87d7f9826e3e792aca8292e288b42432d6fcb52a0cf20b71bbbe727660964309613de
@@ -0,0 +1,44 @@
1
+ class SoulValidations
2
+
3
+ VALID_CLASSES = [
4
+ NilClass,
5
+ String,
6
+ FalseClass,
7
+ TrueClass,
8
+ Integer,
9
+ Float,
10
+ Array,
11
+ Hash,
12
+ ]
13
+
14
+ def self.required value, strict_mode: true
15
+ return {} unless VALID_CLASSES.include? value.class
16
+ return {} if strict_mode == false && value.nil? == false
17
+ return { nil: 'This value is nil' } if strict_mode == false && value.nil?
18
+ errors = {}
19
+
20
+ if value.nil?
21
+ errors[:nil] = 'This value is nil'
22
+ elsif value.is_a?(String) && value.length == 0
23
+ errors[:string] = 'This is an empty string'
24
+ elsif value.is_a?(FalseClass)
25
+ errors[:boolean] = 'This is a false value'
26
+ elsif value.is_a?(Integer) && value === 0
27
+ errors[:integer] = 'This is zero value'
28
+ elsif value.is_a?(Float) && value === 0.0
29
+ errors[:float] = 'This is a zero value'
30
+ elsif value.is_a?(Array) && value.empty?
31
+ errors[:array] = 'This is an empty array'
32
+ elsif value.is_a?(Hash) && value.empty?
33
+ errors[:hash] = 'This is an empty hash'
34
+ end
35
+
36
+ errors
37
+ end
38
+
39
+ def self.required? value, strict_mode: true
40
+ response = required value, strict_mode: strict_mode
41
+ response.empty?
42
+ end
43
+
44
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soul_validations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rowend
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Another validation library
14
+ email: rowend@rowend.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/soul_validations.rb
20
+ homepage: https://github.com/rowend/soul_validations
21
+ licenses:
22
+ - Nonstandard
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.7.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Validations
44
+ test_files: []