tap 0.18.0 → 0.19.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.
@@ -1,56 +0,0 @@
1
- module Tap
2
- class Schema
3
- module Utils
4
- module_function
5
-
6
- def instantiate(data, app)
7
- case data
8
- when Hash then data[:class].instantiate(data, app)
9
- when Array then data.shift.parse!(data, app)
10
- else raise "cannot instantiate: #{data.inspect}"
11
- end
12
- end
13
-
14
- def resolved?(data)
15
- case data
16
- when Hash then data[:class].respond_to?(:instantiate)
17
- when Array then data[0].respond_to?(:parse!)
18
- else false
19
- end
20
- end
21
-
22
- def resolve(data)
23
- return data if resolved?(data)
24
-
25
- case data
26
- when Hash
27
- unless resolved?(data)
28
- data = symbolize(data)
29
- data[:class] = yield(data[:id]) || data[:id]
30
- end
31
- when Array
32
- data[0] = yield(data[0]) || data[0]
33
- end
34
-
35
- data
36
- end
37
-
38
- # Symbolizes the keys of hash. Returns non-hash values directly and
39
- # raises an error in the event of a symbolize conflict.
40
- def symbolize(hash)
41
- result = {}
42
- hash.each_pair do |key, value|
43
- key = key.to_sym || key
44
-
45
- if result.has_key?(key)
46
- raise "symbolize conflict: #{hash.inspect} (#{key.inspect})"
47
- end
48
-
49
- result[key] = value
50
- end
51
- result
52
- end
53
-
54
- end
55
- end
56
- end