low_type 1.1.3 → 1.1.5
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/lib/factories/proxy_factory.rb +4 -2
- data/lib/low_type.rb +3 -1
- data/lib/types/complex_type.rb +11 -0
- data/lib/types/complex_types.rb +2 -1
- data/lib/types/status.rb +51 -0
- data/lib/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e13a3035e27d89496ce05f13f70ae7427f14ea0983296e0b2e87638c151da090
|
|
4
|
+
data.tar.gz: 5481efe2424490d9e7b1f572702c7e1ed4ed5438da8dc4b76eaed673aefe2ba7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86cca4540d30f7fd2b9b3ae756d671f81a1545a8db7bdf3f9df5d540a1199476068edfda2f6a8e2a07ca7f265edfe6cdb87310eb3b143aadb820f2c193166b3b
|
|
7
|
+
data.tar.gz: 5ef5ab81b49b67b8f536de461e501b5c2e2d23dab7f742af69160f9ce055ae8c39ddeed540f72611547236722b7cb4f19fadb383f6751daa620c1e09ce1db5a4
|
|
@@ -25,13 +25,15 @@ module LowType
|
|
|
25
25
|
def param_proxies(method_node:, file:)
|
|
26
26
|
return [] if method_node.parameters.nil?
|
|
27
27
|
|
|
28
|
+
params_without_block = method_node.parameters.slice.delete_suffix(', &block')
|
|
29
|
+
|
|
28
30
|
# Not a security risk because the code comes from a trusted source; the file that did the include. Does the file trust itself?
|
|
29
|
-
ruby_method = eval("-> (#{
|
|
31
|
+
ruby_method = eval("-> (#{params_without_block}) {}", binding, __FILE__, __LINE__) # rubocop:disable Security/Eval
|
|
30
32
|
|
|
31
33
|
# Not a security risk because the code comes from a trusted source; the file that did the include. Does the file trust itself?
|
|
32
34
|
# Local variable names are prefixed with __lt or __rb where necessary to avoid being overridden by method parameters.
|
|
33
35
|
typed_method = <<~RUBY
|
|
34
|
-
-> (#{
|
|
36
|
+
-> (#{params_without_block}, __rb_method:, __lt_file:) {
|
|
35
37
|
param_proxies_for_type_expressions(ruby_method: __rb_method, file: __lt_file, method_binding: binding)
|
|
36
38
|
}
|
|
37
39
|
RUBY
|
data/lib/low_type.rb
CHANGED
|
@@ -11,7 +11,7 @@ require_relative 'types/complex_types'
|
|
|
11
11
|
|
|
12
12
|
module LowType
|
|
13
13
|
# We do as much as possible on class load rather than on instantiation to be thread-safe and efficient.
|
|
14
|
-
def self.included(klass)
|
|
14
|
+
def self.included(klass) # rubocop:disable Metrics/AbcSize
|
|
15
15
|
require_relative 'syntax/union_types' if LowType.config.union_type_expressions
|
|
16
16
|
|
|
17
17
|
class << klass
|
|
@@ -21,6 +21,8 @@ module LowType
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
file_path = FileQuery.file_path(klass:)
|
|
24
|
+
return unless File.exist?(file_path)
|
|
25
|
+
|
|
24
26
|
parser = FileParser.new(klass:, file_path:)
|
|
25
27
|
|
|
26
28
|
klass.extend TypeAccessors
|
data/lib/types/complex_types.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative '../factories/type_factory'
|
|
4
|
+
require_relative 'status'
|
|
4
5
|
|
|
5
6
|
module LowType
|
|
6
7
|
COMPLEX_TYPES = [
|
|
@@ -8,7 +9,7 @@ module LowType
|
|
|
8
9
|
Headers = TypeFactory.complex_type(Hash),
|
|
9
10
|
HTML = TypeFactory.complex_type(String),
|
|
10
11
|
JSON = TypeFactory.complex_type(String),
|
|
11
|
-
Status
|
|
12
|
+
Status,
|
|
12
13
|
Tuple = TypeFactory.complex_type(Array),
|
|
13
14
|
XML = TypeFactory.complex_type(String)
|
|
14
15
|
].freeze
|
data/lib/types/status.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'complex_type'
|
|
4
|
+
require_relative 'error_types'
|
|
5
|
+
|
|
6
|
+
module LowType
|
|
7
|
+
# Status is an Integer for type checking, but an instance of StatusCode for advanced functionality.
|
|
8
|
+
class Status < Integer
|
|
9
|
+
extend ComplexType
|
|
10
|
+
|
|
11
|
+
class StatusCode
|
|
12
|
+
attr_reader :status_code
|
|
13
|
+
|
|
14
|
+
STATUS_CODES = [
|
|
15
|
+
# Info.
|
|
16
|
+
100, 101, 102, 103,
|
|
17
|
+
# Success.
|
|
18
|
+
200, 201, 202, 203, 204, 205, 206, 207, 208, 226,
|
|
19
|
+
# Redirect.
|
|
20
|
+
300, 301, 302, 303, 304, 305, 306, 307, 308,
|
|
21
|
+
# Client Error.
|
|
22
|
+
400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414,
|
|
23
|
+
415, 416, 417, 418, 421, 422, 423, 424, 425, 426, 428, 429, 431, 451,
|
|
24
|
+
# Server Error.
|
|
25
|
+
500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511
|
|
26
|
+
].freeze
|
|
27
|
+
|
|
28
|
+
def initialize(status_code)
|
|
29
|
+
raise AllowedTypeError unless STATUS_CODES.include?(status_code)
|
|
30
|
+
|
|
31
|
+
@status_code = status_code
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def ==(other)
|
|
35
|
+
other.class == self.class && other.status_code == @status_code
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def eql?(other)
|
|
39
|
+
self == other
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def hash
|
|
43
|
+
[self.class, @status_code].hash
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.[](status_code)
|
|
48
|
+
@status_code = StatusCode.new(status_code)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: low_type
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- maedi
|
|
@@ -42,8 +42,10 @@ files:
|
|
|
42
42
|
- lib/queries/type_query.rb
|
|
43
43
|
- lib/syntax/syntax.rb
|
|
44
44
|
- lib/syntax/union_types.rb
|
|
45
|
+
- lib/types/complex_type.rb
|
|
45
46
|
- lib/types/complex_types.rb
|
|
46
47
|
- lib/types/error_types.rb
|
|
48
|
+
- lib/types/status.rb
|
|
47
49
|
- lib/version.rb
|
|
48
50
|
homepage: https://codeberg.org/low_ruby/low_type
|
|
49
51
|
licenses: []
|