typero 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/typero.rb +3 -1
- data/lib/typero/schema.rb +4 -2
- data/lib/typero/type.rb +0 -13
- data/lib/typero/type/array.rb +4 -6
- data/lib/typero/type/email.rb +4 -4
- data/lib/typero/type/float.rb +5 -6
- data/lib/typero/type/integer.rb +9 -0
- data/lib/typero/type/label.rb +1 -1
- data/lib/typero/type/url.rb +1 -1
- data/lib/typero/version.rb +1 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4f7aa7434411123ed8aad1528410d815ce2018f
|
4
|
+
data.tar.gz: e703cabe488d967b68b31f322756b8734f8a6858
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99ab71faf7c55e56ac49231533bd0ae1132d07839b9b251dbb282127fc86825231b960e21fa023bec28eec511c4ef9e7e2e52f71c68eaa491c33bd3af256c5fe
|
7
|
+
data.tar.gz: 395435ca418457cc9833b2b3774af250b1667f377ff38fb608c639c6439889cc56415f5433fb348d0d9d041792860b0d96827252aeedef75527baa4b9c138bde
|
data/lib/typero.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'fast_blank'
|
2
|
+
|
1
3
|
require_relative './typero/instance'
|
2
4
|
require_relative './typero/schema'
|
3
5
|
require_relative './typero/type'
|
@@ -66,7 +68,7 @@ module Typero
|
|
66
68
|
def validate(*args)
|
67
69
|
validate!(*args)
|
68
70
|
true
|
69
|
-
rescue
|
71
|
+
rescue TypeError
|
70
72
|
false
|
71
73
|
end
|
72
74
|
|
data/lib/typero/schema.rb
CHANGED
@@ -51,8 +51,10 @@ module Typero
|
|
51
51
|
rescue
|
52
52
|
errors[field] = $!.message
|
53
53
|
end
|
54
|
-
|
55
|
-
|
54
|
+
else
|
55
|
+
Typero.validate!(value, type, check_hash) { |msg|
|
56
|
+
errors[field] = "#{field.to_s.capitalize}: #{msg}"
|
57
|
+
}
|
56
58
|
end
|
57
59
|
end
|
58
60
|
errors.keys.length > 0 ? errors : nil
|
data/lib/typero/type.rb
CHANGED
@@ -10,16 +10,6 @@ module Typero
|
|
10
10
|
|
11
11
|
### SAFE TO OVERLOAD: START
|
12
12
|
|
13
|
-
# default min implementation
|
14
|
-
def min(value, length)
|
15
|
-
raise TypeError, "Min #{@type} lenght for #{@name} is #{length}, you have #{value.to_s.length}" if value.to_s.length < length
|
16
|
-
end
|
17
|
-
|
18
|
-
# default max implementation
|
19
|
-
def max(value, length)
|
20
|
-
raise TypeError, "Max #{@type} length for #{@name} is #{length}, you have #{value.to_s.length}" if value.to_s.length > length
|
21
|
-
end
|
22
|
-
|
23
13
|
# if value is not blank, it is sent to set method
|
24
14
|
def set(value)
|
25
15
|
value
|
@@ -82,9 +72,6 @@ module Typero
|
|
82
72
|
raise TypeError, @opts[:uniq].class == TrueClass ? "Field #{@name} is uniqe and allready exists" : @opts[:uniq] if filter.first
|
83
73
|
end
|
84
74
|
|
85
|
-
min(value, @opts[:min]) if @opts[:min]
|
86
|
-
max(value, @opts[:max]) if @opts[:max]
|
87
|
-
|
88
75
|
validate(value)
|
89
76
|
elsif @opts[:req]
|
90
77
|
msg = @opts[:req].class == TrueClass ? "is required" : @opts[:req]
|
data/lib/typero/type/array.rb
CHANGED
@@ -13,12 +13,10 @@ module Typero
|
|
13
13
|
value
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
raise TypeError, "Min array lenght is #{
|
18
|
-
|
19
|
-
|
20
|
-
def max(value, length)
|
21
|
-
raise TypeError, "Max array lenght is #{length} elements" if value.length > length
|
16
|
+
def validate(list)
|
17
|
+
raise TypeError, "Min array lenght is #{@opts[:min]} elements" if @opts[:min] && @opts[:min] < list.length
|
18
|
+
raise TypeError, "Max array lenght is #{@opts[:max]} elements" if @opts[:max] && @opts[:max] < list.length
|
19
|
+
true
|
22
20
|
end
|
23
21
|
end
|
24
22
|
end
|
data/lib/typero/type/email.rb
CHANGED
@@ -5,10 +5,10 @@ module Typero
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def validate(value)
|
8
|
-
raise TypeError, 'not having at least 8 characters' unless value.to_s.length > 7
|
9
|
-
raise TypeError, 'missing @' unless value.include?('@')
|
10
|
-
raise TypeError, 'in wrong domain' unless value =~ /\.\w{2,4}$/
|
11
|
-
raise TypeError, 'in wrong format' unless value =~ /^[\w\-\.]+\@[\w\-\.]+$/i
|
8
|
+
raise TypeError, 'is not having at least 8 characters' unless value.to_s.length > 7
|
9
|
+
raise TypeError, 'is missing @' unless value.include?('@')
|
10
|
+
raise TypeError, 'is in wrong domain' unless value =~ /\.\w{2,4}$/
|
11
|
+
raise TypeError, 'is in wrong format' unless value =~ /^[\w\-\.]+\@[\w\-\.]+$/i
|
12
12
|
true
|
13
13
|
end
|
14
14
|
end
|
data/lib/typero/type/float.rb
CHANGED
@@ -4,12 +4,11 @@ module Typero
|
|
4
4
|
value.to_f
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
raise TypeError, "Max #{@type} length for #{@name} is #{length}, you have #{value}" if value.to_f > length
|
7
|
+
def validate(input)
|
8
|
+
value = set(input)
|
9
|
+
raise TypeError, "min lenght is #{@opts[:min]}" if @opts[:min] && value < @opts[:min]
|
10
|
+
raise TypeError, "max lenght is #{@opts[:max]}" if @opts[:max] && value > @opts[:max]
|
11
|
+
true
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
data/lib/typero/type/integer.rb
CHANGED
@@ -3,6 +3,15 @@ module Typero
|
|
3
3
|
def set(value)
|
4
4
|
value.to_i
|
5
5
|
end
|
6
|
+
|
7
|
+
def validate(input)
|
8
|
+
value = set(input)
|
9
|
+
|
10
|
+
raise TypeError, "min lenght is #{@opts[:min]}, you have #{value}" if @opts[:min] && value < @opts[:min]
|
11
|
+
raise TypeError, "max lenght is #{@opts[:max]}, you have #{value}" if @opts[:max] && value > @opts[:max]
|
12
|
+
|
13
|
+
true
|
14
|
+
end
|
6
15
|
end
|
7
16
|
end
|
8
17
|
|
data/lib/typero/type/label.rb
CHANGED
data/lib/typero/type/url.rb
CHANGED
data/lib/typero/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dino Reic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
12
|
-
dependencies:
|
11
|
+
date: 2016-09-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fast_blank
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: active_support/core_ext/string
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: Simple and fast ruby type system. Enforce types as Array, Email, Boolean
|
14
42
|
for ruby class instances
|
15
43
|
email: reic.dino@gmail.com
|