despecable 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 290a992d2845a837ff7ce19c2fab3dccb6777fcd
|
4
|
+
data.tar.gz: 4e6bda047e215fc133e20ad56c02ebc417719798
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c59f54e988d690ce171d1cfada645fa3790d4e3435cab086e16d3d8988aee03ca315446b87b82d02cd4763e1b3702e6ecd6db134de645d35963134d2352957fc
|
7
|
+
data.tar.gz: cc348e49a9cea4d797f788e0d9e1b5abbeb7ff3c778e552622a3cc9508b6a93862d3d3fe23805d8845d2e6ab9913aabc5c90871b37e5aa902d07a388b1d485b4
|
@@ -1,15 +1,15 @@
|
|
1
1
|
class Despecable::DespecableError < StandardError
|
2
|
-
|
3
|
-
|
4
|
-
end
|
2
|
+
attr_accessor :parameters
|
3
|
+
protected :parameters=
|
5
4
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
return exception(msg)
|
5
|
+
def initialize(*args, parameters: [])
|
6
|
+
@parameters = [*parameters].map(&:to_s)
|
7
|
+
super(*args)
|
10
8
|
end
|
11
9
|
|
12
|
-
def
|
13
|
-
|
10
|
+
def exception(*args)
|
11
|
+
ex = super
|
12
|
+
ex.parameters = @parameters
|
13
|
+
return ex
|
14
14
|
end
|
15
15
|
end
|
data/lib/despecable/me.rb
CHANGED
@@ -7,7 +7,7 @@ module Despecable
|
|
7
7
|
# pass in request.query_parameters (GET) and/or request.request_parameters (POST)
|
8
8
|
# for supplied_params to correctly get only the user-supplied parameters.
|
9
9
|
def initialize(params, supplied_params = nil)
|
10
|
-
@supplied_params = (supplied_params || params).
|
10
|
+
@supplied_params = (supplied_params || params).dup
|
11
11
|
@params = params
|
12
12
|
@specd = []
|
13
13
|
end
|
@@ -27,7 +27,8 @@ module Despecable
|
|
27
27
|
def despecably_strict
|
28
28
|
if !unspecd.empty?
|
29
29
|
list = unspecd.map{|x| "'#{x}'"}.join(", ")
|
30
|
-
|
30
|
+
error = Despecable::UnrecognizedParameterError.new("Unrecognized parameters supplied: #{list}", parameters: unspecd)
|
31
|
+
raise error
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -9,72 +9,72 @@ module Despecable
|
|
9
9
|
value.to_s.split(",")
|
10
10
|
end
|
11
11
|
|
12
|
-
def read(value, type, options)
|
13
|
-
value = public_send(type, value) unless value.nil?
|
14
|
-
validate_param(value, options)
|
12
|
+
def read(name, value, type, options)
|
13
|
+
value = public_send(type, name, value) unless value.nil?
|
14
|
+
validate_param(name, value, options)
|
15
15
|
return value
|
16
16
|
end
|
17
17
|
|
18
|
-
def validate_param(value, options)
|
19
|
-
validate_param_presence(value) if options[:required]
|
20
|
-
validate_param_value(value, options[:in]) if options.key?(:in) && !value.nil?
|
18
|
+
def validate_param(name, value, options)
|
19
|
+
validate_param_presence(name, value) if options[:required]
|
20
|
+
validate_param_value(name, value, options[:in]) if options.key?(:in) && !value.nil?
|
21
21
|
end
|
22
22
|
|
23
|
-
def validate_param_presence(value)
|
24
|
-
raise Despecable::MissingParameterError if value.nil?
|
23
|
+
def validate_param_presence(name, value)
|
24
|
+
raise Despecable::MissingParameterError.new("Missing required parameter: #{name}", parameters: name) if value.nil?
|
25
25
|
end
|
26
26
|
|
27
|
-
def validate_param_value(value, allowed_values)
|
28
|
-
raise Despecable::IncorrectParameterError
|
27
|
+
def validate_param_value(name, value, allowed_values)
|
28
|
+
raise Despecable::IncorrectParameterError.new("Unacceptable value for parameter: #{name}", parameters: name) if !allowed_values.include?(value)
|
29
29
|
end
|
30
30
|
|
31
|
-
def integer(value)
|
31
|
+
def integer(name, value)
|
32
32
|
Integer(value)
|
33
33
|
rescue ArgumentError
|
34
34
|
raise unless /^invalid value for Integer/ =~ $!.message
|
35
|
-
raise Despecable::InvalidParameterError
|
35
|
+
raise Despecable::InvalidParameterError.new("Integer type required for parameter: #{name}", parameters: name)
|
36
36
|
end
|
37
37
|
|
38
|
-
def float(value)
|
38
|
+
def float(name, value)
|
39
39
|
Float(value)
|
40
40
|
rescue ArgumentError
|
41
41
|
raise unless /^invalid value for Float/ =~ $!.message
|
42
|
-
raise Despecable::InvalidParameterError
|
42
|
+
raise Despecable::InvalidParameterError.new("Float type required for parameter: #{name}", parameters: name)
|
43
43
|
end
|
44
44
|
|
45
|
-
def string(value)
|
45
|
+
def string(name, value)
|
46
46
|
# This is really a no-op.
|
47
47
|
value.to_s
|
48
48
|
end
|
49
49
|
|
50
|
-
def boolean(value)
|
50
|
+
def boolean(name, value)
|
51
51
|
case value.to_s
|
52
52
|
when "true", "1" then true
|
53
53
|
when "false", "0", nil then false
|
54
|
-
else raise Despecable::InvalidParameterError
|
54
|
+
else raise Despecable::InvalidParameterError.new("Boolean type (1/0 or true/false) required for parameter: #{name}", parameters: name)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
def date(value)
|
58
|
+
def date(name, value)
|
59
59
|
Date.rfc3339(value + "T00:00:00+00:00")
|
60
60
|
rescue ArgumentError
|
61
61
|
raise unless $!.message == "invalid date"
|
62
|
-
raise Despecable::InvalidParameterError
|
62
|
+
raise Despecable::InvalidParameterError.new("Date type (e.g. '2012-12-31') required for parameter: #{name}", parameters: name)
|
63
63
|
end
|
64
64
|
|
65
|
-
def datetime(value)
|
65
|
+
def datetime(name, value)
|
66
66
|
DateTime.rfc3339(value)
|
67
67
|
rescue ArgumentError
|
68
68
|
raise unless $!.message == "invalid date"
|
69
|
-
raise Despecable::InvalidParameterError
|
69
|
+
raise Despecable::InvalidParameterError.new("Rfc3339 datetime type (e.g. '2009-06-19T00:00:00-04:00') required for parameter: #{name}", parameters: name)
|
70
70
|
end
|
71
71
|
|
72
|
-
def file(value)
|
73
|
-
raise Despecable::InvalidParameterError
|
72
|
+
def file(name, value)
|
73
|
+
raise Despecable::InvalidParameterError.new("File upload type required for parameter: #{name}" , parameters: name) if !(value.respond_to?(:original_filename) && value.original_filename.present?)
|
74
74
|
return value
|
75
75
|
end
|
76
76
|
|
77
|
-
def any(value)
|
77
|
+
def any(name, value)
|
78
78
|
value
|
79
79
|
end
|
80
80
|
end
|
data/lib/despecable/spectator.rb
CHANGED
@@ -48,17 +48,15 @@ module Despecable
|
|
48
48
|
params[name] = options[:default]
|
49
49
|
elsif options[:array]
|
50
50
|
values = @spectacles.arrayify(params[name])
|
51
|
-
params[name] = values.map{|val| @spectacles.read(val, type, options)}
|
51
|
+
params[name] = values.map{|val| @spectacles.read(name, val, type, options)}
|
52
52
|
elsif options[:arrayable] && @spectacles.arrayable?(params[name])
|
53
53
|
# TODO: deprecate arrayable in favor of array
|
54
54
|
values = @spectacles.arrayify(params[name])
|
55
|
-
params[name] = values.map{|val| @spectacles.read(val, type, options)}
|
55
|
+
params[name] = values.map{|val| @spectacles.read(name, val, type, options)}
|
56
56
|
else
|
57
|
-
value = @spectacles.read(params[name], type, options)
|
57
|
+
value = @spectacles.read(name, params[name], type, options)
|
58
58
|
params[name] = value if params.key?(name)
|
59
59
|
end
|
60
|
-
rescue ::Despecable::DespecableError
|
61
|
-
::Kernel.raise $!.insert_name_here(name)
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: despecable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Schwartz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|