typero 0.8.0 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/lib/adapters/sequel.rb +10 -27
  4. data/lib/typero.rb +3 -0
  5. data/lib/typero/params.rb +57 -12
  6. data/lib/typero/schema.rb +165 -0
  7. data/lib/typero/type/type.rb +68 -10
  8. data/lib/typero/type/types/boolean_type.rb +26 -0
  9. data/lib/typero/type/types/currency_type.rb +21 -0
  10. data/lib/typero/type/types/date_type.rb +38 -0
  11. data/lib/typero/type/types/datetime_type.rb +19 -0
  12. data/lib/typero/type/types/email_type.rb +20 -0
  13. data/lib/typero/type/types/float_type.rb +24 -0
  14. data/lib/typero/type/types/hash_type.rb +31 -0
  15. data/lib/typero/type/types/{image.rb → image_type.rb} +4 -10
  16. data/lib/typero/type/types/integer_type.rb +16 -0
  17. data/lib/typero/type/types/label_type.rb +20 -0
  18. data/lib/typero/type/types/locale_type.rb +13 -0
  19. data/lib/typero/type/types/model_type.rb +23 -0
  20. data/lib/typero/type/types/{oib.rb → oib_type.rb} +7 -10
  21. data/lib/typero/type/types/point_type.rb +25 -0
  22. data/lib/typero/type/types/string_type.rb +23 -0
  23. data/lib/typero/type/types/{text.rb → text_type.rb} +3 -5
  24. data/lib/typero/type/types/time_type.rb +5 -0
  25. data/lib/typero/type/types/timezone_type.rb +15 -0
  26. data/lib/typero/type/types/url_type.rb +13 -0
  27. data/lib/typero/typero.rb +72 -141
  28. metadata +26 -21
  29. data/lib/typero/type/types/boolean.rb +0 -16
  30. data/lib/typero/type/types/currency.rb +0 -19
  31. data/lib/typero/type/types/date.rb +0 -10
  32. data/lib/typero/type/types/datetime.rb +0 -10
  33. data/lib/typero/type/types/email.rb +0 -21
  34. data/lib/typero/type/types/float.rb +0 -21
  35. data/lib/typero/type/types/hash.rb +0 -22
  36. data/lib/typero/type/types/integer.rb +0 -21
  37. data/lib/typero/type/types/label.rb +0 -15
  38. data/lib/typero/type/types/point.rb +0 -29
  39. data/lib/typero/type/types/string.rb +0 -23
  40. data/lib/typero/type/types/url.rb +0 -18
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-25 00:00:00.000000000 Z
11
+ date: 2021-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fast_blank
@@ -35,28 +35,33 @@ files:
35
35
  - "./lib/adapters/sequel.rb"
36
36
  - "./lib/typero.rb"
37
37
  - "./lib/typero/params.rb"
38
+ - "./lib/typero/schema.rb"
38
39
  - "./lib/typero/type/type.rb"
39
- - "./lib/typero/type/types/boolean.rb"
40
- - "./lib/typero/type/types/currency.rb"
41
- - "./lib/typero/type/types/date.rb"
42
- - "./lib/typero/type/types/datetime.rb"
43
- - "./lib/typero/type/types/email.rb"
44
- - "./lib/typero/type/types/float.rb"
45
- - "./lib/typero/type/types/hash.rb"
46
- - "./lib/typero/type/types/image.rb"
47
- - "./lib/typero/type/types/integer.rb"
48
- - "./lib/typero/type/types/label.rb"
49
- - "./lib/typero/type/types/oib.rb"
50
- - "./lib/typero/type/types/point.rb"
51
- - "./lib/typero/type/types/string.rb"
52
- - "./lib/typero/type/types/text.rb"
53
- - "./lib/typero/type/types/url.rb"
40
+ - "./lib/typero/type/types/boolean_type.rb"
41
+ - "./lib/typero/type/types/currency_type.rb"
42
+ - "./lib/typero/type/types/date_type.rb"
43
+ - "./lib/typero/type/types/datetime_type.rb"
44
+ - "./lib/typero/type/types/email_type.rb"
45
+ - "./lib/typero/type/types/float_type.rb"
46
+ - "./lib/typero/type/types/hash_type.rb"
47
+ - "./lib/typero/type/types/image_type.rb"
48
+ - "./lib/typero/type/types/integer_type.rb"
49
+ - "./lib/typero/type/types/label_type.rb"
50
+ - "./lib/typero/type/types/locale_type.rb"
51
+ - "./lib/typero/type/types/model_type.rb"
52
+ - "./lib/typero/type/types/oib_type.rb"
53
+ - "./lib/typero/type/types/point_type.rb"
54
+ - "./lib/typero/type/types/string_type.rb"
55
+ - "./lib/typero/type/types/text_type.rb"
56
+ - "./lib/typero/type/types/time_type.rb"
57
+ - "./lib/typero/type/types/timezone_type.rb"
58
+ - "./lib/typero/type/types/url_type.rb"
54
59
  - "./lib/typero/typero.rb"
55
60
  homepage: https://github.com/dux/typero
56
61
  licenses:
57
62
  - MIT
58
63
  metadata: {}
59
- post_install_message:
64
+ post_install_message:
60
65
  rdoc_options: []
61
66
  require_paths:
62
67
  - lib
@@ -71,8 +76,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
76
  - !ruby/object:Gem::Version
72
77
  version: '0'
73
78
  requirements: []
74
- rubygems_version: 3.0.6
75
- signing_key:
79
+ rubygems_version: 3.2.22
80
+ signing_key:
76
81
  specification_version: 4
77
82
  summary: Ruby type system
78
83
  test_files: []
@@ -1,16 +0,0 @@
1
- class Typero::BooleanType < Typero::Type
2
- def default
3
- false
4
- end
5
-
6
- def set
7
- @value = [true, 1, '1', 'true', 'on'].include?(@value) ? true : false
8
- end
9
-
10
- def db_field
11
- opts = {}
12
- opts[:default] = @opts[:default] || false
13
- [:boolean, opts]
14
- end
15
- end
16
-
@@ -1,19 +0,0 @@
1
- # you should not use this filed for currency calculations
2
-
3
- require_relative './float'
4
-
5
- class Typero::CurrencyType < Typero::FloatType
6
-
7
- def set
8
- @value = @value.to_f.round(2)
9
- end
10
-
11
- def db_field
12
- opts = {}
13
- opts[:precision] = 8
14
- opts[:scale] = 2
15
- [:decimal, opts]
16
- end
17
-
18
- end
19
-
@@ -1,10 +0,0 @@
1
- class Typero::DateType < Typero::Type
2
- def set
3
- @value = @value.to_s.downcase.gsub(/[^\d\-\.\s]/, '')
4
- end
5
-
6
- def db_field
7
- [:date, {}]
8
- end
9
- end
10
-
@@ -1,10 +0,0 @@
1
- class Typero::DatetimeType < Typero::Type
2
- def set
3
- @value = @value.to_s.downcase.gsub(/[^\d\-\.\s\:]/, '')
4
- end
5
-
6
- def db_field
7
- [:datetime, {}]
8
- end
9
- end
10
-
@@ -1,21 +0,0 @@
1
- class Typero::EmailType < Typero::Type
2
- error :en, :not_8_chars_error, 'is not having at least 8 characters'
3
- error :en, :missing_monkey_error, 'is missing @'
4
-
5
- def set
6
- @value = @value.downcase.gsub(/\s+/,'+')
7
- end
8
-
9
- def validate
10
- error_for(:not_8_chars_error) unless @value.to_s.length > 7
11
- error_for(:missing_monkey_error) unless @value.include?('@')
12
- end
13
-
14
- def db_field
15
- opts = {}
16
- opts[:limit] = @opts[:max] || 120
17
- opts[:null] = false if @opts[:required]
18
- [:string, opts]
19
- end
20
- end
21
-
@@ -1,21 +0,0 @@
1
- class Typero::FloatType < Typero::Type
2
- opts :min, 'Minimum value'
3
- opts :max, 'Maximun value'
4
-
5
- def set
6
- @value = @value.to_f
7
- end
8
-
9
- def validate
10
- error_for(:min_length_error, @opts[:min], @value) if @opts[:min] && value < @opts[:min]
11
- error_for(:max_length_error, @opts[:max], @value) if @opts[:max] && value > @opts[:max]
12
- end
13
-
14
- def db_field
15
- opts = {}
16
- opts[:null] = false if @opts[:required]
17
- [:float, opts]
18
- end
19
-
20
- end
21
-
@@ -1,22 +0,0 @@
1
- class Typero::HashType < Typero::Type
2
- error :en, :not_hash_type_error, 'value is not hash type'
3
-
4
- def default
5
- {}
6
- end
7
-
8
- def set
9
- @value = @value.to_h
10
- end
11
-
12
- def validate
13
- error_for(:not_hash_type_error) unless @value.is_a?(Hash)
14
- end
15
-
16
- def db_field
17
- [:jsonb, {
18
- null: false
19
- }]
20
- end
21
- end
22
-
@@ -1,21 +0,0 @@
1
- class Typero::IntegerType < Typero::Type
2
- opts :min, 'Minimum value'
3
- opts :max, 'Maximun value'
4
-
5
- def set
6
- @value = @value.to_i
7
- end
8
-
9
- def validate
10
- error_for(:min_value_error, @opts[:min], @value) if @opts[:min] && @value < @opts[:min]
11
- error_for(:max_value_error, @opts[:max], @value) if @opts[:max] && @value > @opts[:max]
12
- end
13
-
14
- def db_field
15
- opts = {}
16
- opts[:null] = false if @opts[:required]
17
- opts[:default] = @opts[:default]
18
- [:integer, opts]
19
- end
20
- end
21
-
@@ -1,15 +0,0 @@
1
- class Typero::LabelType < Typero::Type
2
- def set
3
- @value = @value.to_s.gsub(/\s+/,'-').gsub(/[^\w\-]/,'').gsub(/\-+/, '-')[0,30].downcase
4
- end
5
-
6
- def validate
7
- error_for(:unallowed_characters_error) unless @value =~ /^[\w\-]+$/
8
- end
9
-
10
- def db_field
11
- opts = {}
12
- opts[:limit] = 30
13
- [:string, opts]
14
- end
15
- end
@@ -1,29 +0,0 @@
1
- # for postgres - select st_asewkt(lon_lat) || st_astext(lon_lat)
2
- # point = @object.class.xselect("ST_AsText(#{field}) as #{field}").where(id: @object.id).first[field.to_sym]
3
-
4
- class Typero::PointType < Typero::Type
5
- def set
6
- if @value.present?
7
- if @value.include?('/@')
8
- point = @value.split('/@', 2).last.split(',')
9
- @value = [point[0], point[1]].join(',')
10
- end
11
-
12
- if !@value.include?('POINT') && @value.include?(',')
13
- point = @value.sub(/,\s*/, ' ')
14
- @value = 'SRID=4326;POINT(%s)' % point
15
- end
16
- end
17
- end
18
-
19
- def validate
20
- if @value && @value.include?(',') && !@value =~ /^SRID=4326;POINT\(/
21
- error_for(:unallowed_characters_error)
22
- end
23
- end
24
-
25
- def db_field
26
- [:geography, {}]
27
- end
28
- end
29
-
@@ -1,23 +0,0 @@
1
- class Typero::StringType < Typero::Type
2
- opts :min, 'Minimun string length'
3
- opts :max, 'Maximun string length'
4
-
5
- def set
6
- @value = @value.to_s unless @value.is_a?(String)
7
- @value = @value.downcase if @opts[:downcase]
8
- end
9
-
10
- def validate
11
- error_for(:min_length_error, @opts[:min], @value.length) if @opts[:min] && @value.length < @opts[:min]
12
- error_for(:max_length_error, @opts[:max], @value.length) if @opts[:max] && @value.length > @opts[:max]
13
- end
14
-
15
- def db_field
16
- opts = {}
17
- opts[:limit] = @opts[:max] || 255
18
- opts[:null] = false if @opts[:required]
19
- opts[:default] = @opts[:default]
20
- [:string, opts]
21
- end
22
- end
23
-
@@ -1,18 +0,0 @@
1
- class Typero::UrlType < Typero::Type
2
- error :en, :url_not_starting_error, 'URL is not starting with http'
3
-
4
- def set
5
- @value = 'http://%s' % @value unless @value.include?('://')
6
- end
7
-
8
- def validate
9
- error_for(:url_not_starting_error) unless @value =~ /^https?:\/\/./
10
- end
11
-
12
- def db_field
13
- opts = {}
14
- opts[:null] = false if @opts[:required]
15
- [:string, opts]
16
- end
17
- end
18
-