gate 0.3.0 → 0.4.0
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/README.md +1 -0
- data/lib/gate/coercer/any.rb +7 -0
- data/lib/gate/coercer.rb +13 -4
- data/lib/gate/version.rb +1 -1
- data/lib/gate.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a99614096253f58fc609869e6b95d28a8643fbc2
|
4
|
+
data.tar.gz: 0cec6ed9368095959790395fbc670ae2bb16e79f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c4148b37275f4fd92cf3303f407dbdc408506bd075e68447eb92d73a6359d5df91dc7c7fe19fce9887b90d9ab9cca53c3cb7997372a7c5394573087f360cd03
|
7
|
+
data.tar.gz: cac664ec646262b832f802997938583a6b0d348cd7e8c96d7d1eea7c9daeb938790a64edabe2b9bc00bf04a48e5a0ef7cd9da4e21881ca99cf047863b74ec80f
|
data/README.md
CHANGED
data/lib/gate/coercer.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
module Gate
|
2
2
|
class Coercer
|
3
3
|
def initialize(engine, type, allow_nil: false)
|
4
|
-
unless
|
4
|
+
unless coercible?(type)
|
5
5
|
fail CoercionError, "Doesn't know how to coerce into #{type}"
|
6
6
|
end
|
7
7
|
|
8
8
|
@engine = engine
|
9
9
|
@type = type
|
10
10
|
@allow_nil = allow_nil
|
11
|
-
@coercion_method = Axiom::Types.const_get(type).coercion_method
|
12
11
|
end
|
13
12
|
|
14
13
|
def coerce(input)
|
@@ -23,15 +22,25 @@ module Gate
|
|
23
22
|
|
24
23
|
private
|
25
24
|
|
26
|
-
attr_reader :engine, :type
|
25
|
+
attr_reader :engine, :type
|
26
|
+
|
27
|
+
def coercible?(type)
|
28
|
+
type == :Any or Axiom::Types.const_defined?(type)
|
29
|
+
end
|
27
30
|
|
28
31
|
def detect_input_type(input)
|
29
32
|
case input
|
30
|
-
when TrueClass, FalseClass, Array, Hash
|
33
|
+
when TrueClass, FalseClass, Array, Hash, Any
|
31
34
|
input.class
|
32
35
|
else
|
33
36
|
String
|
34
37
|
end
|
35
38
|
end
|
39
|
+
|
40
|
+
def coercion_method
|
41
|
+
return :to_any if type == :Any
|
42
|
+
|
43
|
+
Axiom::Types.const_get(type).coercion_method
|
44
|
+
end
|
36
45
|
end
|
37
46
|
end
|
data/lib/gate/version.rb
CHANGED
data/lib/gate.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Dudulski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coercible
|
@@ -129,6 +129,7 @@ files:
|
|
129
129
|
- gate.gemspec
|
130
130
|
- lib/gate.rb
|
131
131
|
- lib/gate/coercer.rb
|
132
|
+
- lib/gate/coercer/any.rb
|
132
133
|
- lib/gate/configuration.rb
|
133
134
|
- lib/gate/guard.rb
|
134
135
|
- lib/gate/result.rb
|
@@ -153,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
154
|
version: '0'
|
154
155
|
requirements: []
|
155
156
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.4.5
|
157
|
+
rubygems_version: 2.4.5.1
|
157
158
|
signing_key:
|
158
159
|
specification_version: 4
|
159
160
|
summary: Handling user input with ease
|