babl-json 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/babl.rb +2 -2
- data/lib/babl/builder.rb +2 -0
- data/lib/babl/builder/chain_builder.rb +1 -2
- data/lib/babl/builder/template_base.rb +3 -4
- data/lib/babl/nodes.rb +15 -0
- data/lib/babl/nodes/create_pin.rb +1 -2
- data/lib/babl/nodes/dep.rb +1 -2
- data/lib/babl/nodes/each.rb +2 -2
- data/lib/babl/nodes/fixed_array.rb +2 -3
- data/lib/babl/nodes/goto_pin.rb +1 -2
- data/lib/babl/nodes/internal_value.rb +1 -1
- data/lib/babl/nodes/merge.rb +14 -35
- data/lib/babl/nodes/nav.rb +1 -1
- data/lib/babl/nodes/object.rb +5 -4
- data/lib/babl/nodes/parent.rb +1 -2
- data/lib/babl/nodes/static.rb +2 -3
- data/lib/babl/nodes/switch.rb +2 -3
- data/lib/babl/nodes/terminal_value.rb +17 -12
- data/lib/babl/nodes/typed.rb +2 -2
- data/lib/babl/nodes/with.rb +1 -2
- data/lib/babl/operators.rb +21 -0
- data/lib/babl/operators/array.rb +1 -2
- data/lib/babl/operators/dep.rb +1 -1
- data/lib/babl/operators/each.rb +1 -1
- data/lib/babl/operators/enter.rb +1 -0
- data/lib/babl/operators/merge.rb +1 -2
- data/lib/babl/operators/nav.rb +1 -1
- data/lib/babl/operators/object.rb +1 -2
- data/lib/babl/operators/parent.rb +1 -1
- data/lib/babl/operators/partial.rb +1 -1
- data/lib/babl/operators/pin.rb +2 -3
- data/lib/babl/operators/static.rb +3 -3
- data/lib/babl/operators/switch.rb +1 -3
- data/lib/babl/operators/typed.rb +1 -1
- data/lib/babl/operators/with.rb +1 -2
- data/lib/babl/rendering.rb +3 -0
- data/lib/babl/rendering/compiled_template.rb +2 -2
- data/lib/babl/schema.rb +7 -0
- data/lib/babl/schema/any_of.rb +43 -38
- data/lib/babl/schema/dyn_array.rb +1 -1
- data/lib/babl/schema/fixed_array.rb +1 -1
- data/lib/babl/schema/object.rb +1 -1
- data/lib/babl/schema/static.rb +1 -1
- data/lib/babl/schema/typed.rb +1 -1
- data/lib/babl/template.rb +2 -23
- data/lib/babl/utils.rb +3 -0
- data/lib/babl/version.rb +1 -1
- metadata +9 -63
- data/.gitignore +0 -3
- data/.rubocop.yml +0 -201
- data/.ruby-version +0 -1
- data/.travis.yml +0 -4
- data/CHANGELOG.md +0 -36
- data/Gemfile +0 -5
- data/LICENSE +0 -7
- data/README.md +0 -89
- data/babl.gemspec +0 -24
- data/logo-babl.png +0 -0
- data/spec/operators/array_spec.rb +0 -37
- data/spec/operators/call_spec.rb +0 -64
- data/spec/operators/continue_spec.rb +0 -25
- data/spec/operators/default_spec.rb +0 -15
- data/spec/operators/dep_spec.rb +0 -15
- data/spec/operators/each_spec.rb +0 -42
- data/spec/operators/enter_spec.rb +0 -28
- data/spec/operators/extends_spec.rb +0 -30
- data/spec/operators/merge_spec.rb +0 -124
- data/spec/operators/nav_spec.rb +0 -71
- data/spec/operators/null_spec.rb +0 -15
- data/spec/operators/nullable_spec.rb +0 -29
- data/spec/operators/object_spec.rb +0 -30
- data/spec/operators/parent_spec.rb +0 -50
- data/spec/operators/partial_spec.rb +0 -36
- data/spec/operators/pin_spec.rb +0 -172
- data/spec/operators/source_spec.rb +0 -33
- data/spec/operators/static_spec.rb +0 -27
- data/spec/operators/switch_spec.rb +0 -151
- data/spec/operators/typed_spec.rb +0 -84
- data/spec/operators/with_spec.rb +0 -31
- data/spec/spec_helper.rb +0 -2
- data/spec/spec_helper/operator_testing.rb +0 -46
- data/spec/spec_helper/schema_utils.rb +0 -53
- data/spec/utils/value_spec.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89d572b099ed6dd5b4f7a8d330d62b82f2c614a9
|
4
|
+
data.tar.gz: a5a54bfc4ea3d28cba05a5285f401faa5708546c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80a16645c833210146dd440920895f9d0a53bbea5a06b213ec5c50d396dcf059f3378bbb5da6b23771a035e99abe833c55125a731f92b7d22664216e1883105e
|
7
|
+
data.tar.gz: 14926b91b5690491bd9ae7d69123950167bfe823bda592ad6ac72e9dccf009dee817ad74f6176cd7bdee85f343bee10928059a804b65ea4701c547d241683c89
|
data/lib/babl.rb
CHANGED
data/lib/babl/builder.rb
ADDED
@@ -1,7 +1,6 @@
|
|
1
|
-
require 'babl/nodes
|
2
|
-
require 'babl/builder
|
3
|
-
require 'babl/rendering
|
4
|
-
require 'babl/rendering/noop_preloader'
|
1
|
+
require 'babl/nodes'
|
2
|
+
require 'babl/builder'
|
3
|
+
require 'babl/rendering'
|
5
4
|
|
6
5
|
module Babl
|
7
6
|
module Builder
|
data/lib/babl/nodes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'babl/nodes/create_pin'
|
2
|
+
require 'babl/nodes/dep'
|
3
|
+
require 'babl/nodes/each'
|
4
|
+
require 'babl/nodes/fixed_array'
|
5
|
+
require 'babl/nodes/goto_pin'
|
6
|
+
require 'babl/nodes/internal_value'
|
7
|
+
require 'babl/nodes/merge'
|
8
|
+
require 'babl/nodes/nav'
|
9
|
+
require 'babl/nodes/object'
|
10
|
+
require 'babl/nodes/parent'
|
11
|
+
require 'babl/nodes/static'
|
12
|
+
require 'babl/nodes/switch'
|
13
|
+
require 'babl/nodes/terminal_value'
|
14
|
+
require 'babl/nodes/typed'
|
15
|
+
require 'babl/nodes/with'
|
data/lib/babl/nodes/dep.rb
CHANGED
data/lib/babl/nodes/each.rb
CHANGED
data/lib/babl/nodes/goto_pin.rb
CHANGED
data/lib/babl/nodes/merge.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'babl/utils/hash'
|
2
1
|
require 'babl/errors'
|
3
|
-
require 'babl/utils
|
2
|
+
require 'babl/utils'
|
3
|
+
require 'babl/schema'
|
4
4
|
|
5
5
|
module Babl
|
6
6
|
module Nodes
|
@@ -28,12 +28,19 @@ module Babl
|
|
28
28
|
|
29
29
|
# Merge two documentations together
|
30
30
|
def merge_doc(doc1, doc2)
|
31
|
-
doc1 = Schema::Object::EMPTY if Schema::Static::NULL == doc1
|
32
|
-
doc2 = Schema::Object::EMPTY if Schema::Static::NULL == doc2
|
33
|
-
|
34
31
|
case
|
35
|
-
when Schema::
|
36
|
-
|
32
|
+
when Schema::Static::NULL == doc1
|
33
|
+
merge_doc(Schema::Object::EMPTY, doc2)
|
34
|
+
when Schema::Static::NULL == doc2
|
35
|
+
merge_doc(doc1, Schema::Object::EMPTY)
|
36
|
+
when Schema::AnyOf === doc1
|
37
|
+
Schema::AnyOf.canonicalized(doc1.choices.map { |c|
|
38
|
+
merge_doc(c, doc2)
|
39
|
+
})
|
40
|
+
when Schema::AnyOf === doc2
|
41
|
+
Schema::AnyOf.canonicalized(doc2.choices.map { |c|
|
42
|
+
merge_doc(doc1, c)
|
43
|
+
})
|
37
44
|
when Schema::Object === doc1 && Schema::Object === doc2
|
38
45
|
merge_object(doc1, doc2)
|
39
46
|
when Schema::Object === doc1 && Schema::Anything === doc2
|
@@ -45,34 +52,6 @@ module Babl
|
|
45
52
|
end
|
46
53
|
end
|
47
54
|
|
48
|
-
# Merge two documention when Schema::AnyOf is involved either
|
49
|
-
# on left, right or both sides.
|
50
|
-
def merge_extended(doc1, doc2)
|
51
|
-
# Ensure doc1 & doc2 are both Schema::AnyOf
|
52
|
-
choices1 = Schema::AnyOf === doc1 ? doc1.choices : [doc1]
|
53
|
-
choices2 = Schema::AnyOf === doc2 ? doc2.choices : [doc2]
|
54
|
-
|
55
|
-
# Generate all possible combinations
|
56
|
-
all_docs = choices1.product(choices2)
|
57
|
-
.map { |choice1, choice2| merge_doc(choice1, choice2) }
|
58
|
-
|
59
|
-
# Analyze each property accross all combination to
|
60
|
-
# generate a Schema::Object::Property filled with
|
61
|
-
# accurate information.
|
62
|
-
final_properties = all_docs.flat_map(&:properties)
|
63
|
-
.group_by(&:name)
|
64
|
-
.map do |name, properties|
|
65
|
-
Schema::Object::Property.new(
|
66
|
-
name,
|
67
|
-
Schema::AnyOf.canonicalized(properties.map(&:value)),
|
68
|
-
properties.size == all_docs.size && properties.all?(&:required)
|
69
|
-
)
|
70
|
-
end
|
71
|
-
|
72
|
-
# Generate the final Schema::Object
|
73
|
-
Schema::Object.new(final_properties, all_docs.any?(&:additional))
|
74
|
-
end
|
75
|
-
|
76
55
|
# Merge two Schema::Object
|
77
56
|
def merge_object(doc1, doc2)
|
78
57
|
additional = doc1.additional || doc2.additional
|
data/lib/babl/nodes/nav.rb
CHANGED
data/lib/babl/nodes/object.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
require 'babl/
|
2
|
-
require 'babl/
|
3
|
-
require 'babl/utils/value'
|
1
|
+
require 'babl/schema'
|
2
|
+
require 'babl/utils'
|
4
3
|
|
5
4
|
module Babl
|
6
5
|
module Nodes
|
@@ -19,7 +18,9 @@ module Babl
|
|
19
18
|
end
|
20
19
|
|
21
20
|
def render(ctx)
|
22
|
-
|
21
|
+
out = {}
|
22
|
+
nodes.each { |k, v| out[k] = v.render(ctx) }
|
23
|
+
out
|
23
24
|
end
|
24
25
|
end
|
25
26
|
end
|
data/lib/babl/nodes/parent.rb
CHANGED
data/lib/babl/nodes/static.rb
CHANGED
data/lib/babl/nodes/switch.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'babl/schema/anything'
|
1
|
+
require 'babl/schema'
|
3
2
|
require 'babl/errors'
|
3
|
+
require 'singleton'
|
4
4
|
|
5
5
|
module Babl
|
6
6
|
module Nodes
|
@@ -28,12 +28,12 @@ module Babl
|
|
28
28
|
raise Errors::RenderingError, "#{e.message}\n" + ctx.formatted_stack(e.babl_stack), e.backtrace
|
29
29
|
end
|
30
30
|
|
31
|
-
def render_object(obj, stack =
|
31
|
+
def render_object(obj, stack = nil)
|
32
32
|
case obj
|
33
|
-
when String, Numeric, NilClass, TrueClass, FalseClass then obj
|
34
|
-
when Hash then render_hash(obj, stack)
|
35
|
-
when Array then render_array(obj, stack)
|
36
|
-
else raise TerminalValueError.new("Only primitives can be serialized: #{obj}", stack)
|
33
|
+
when ::String, ::Numeric, ::NilClass, ::TrueClass, ::FalseClass then obj
|
34
|
+
when ::Hash then render_hash(obj, stack || [])
|
35
|
+
when ::Array then render_array(obj, stack || [])
|
36
|
+
else raise TerminalValueError.new("Only primitives can be serialized: #{obj}", stack || [])
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -49,18 +49,23 @@ module Babl
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def render_hash(hash, stack)
|
52
|
-
|
52
|
+
out = {}
|
53
|
+
hash.each { |k, v|
|
53
54
|
key = render_key(k, stack)
|
54
55
|
stack.push key
|
55
|
-
out =
|
56
|
+
out[key] = render_object(v, stack)
|
56
57
|
stack.pop
|
57
|
-
|
58
|
-
|
58
|
+
}
|
59
|
+
out
|
59
60
|
end
|
60
61
|
|
61
62
|
def render_key(key, stack)
|
62
63
|
case key
|
63
|
-
when Symbol
|
64
|
+
when ::Symbol then key
|
65
|
+
when ::String then key.to_sym
|
66
|
+
when ::TrueClass then :true
|
67
|
+
when ::FalseClass then :false
|
68
|
+
when ::Numeric, ::NilClass then :"#{key}"
|
64
69
|
else raise TerminalValueError.new("Invalid key for JSON object: #{key}", stack)
|
65
70
|
end
|
66
71
|
end
|
data/lib/babl/nodes/typed.rb
CHANGED
data/lib/babl/nodes/with.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'babl/operators/array'
|
2
|
+
require 'babl/operators/call'
|
3
|
+
require 'babl/operators/continue'
|
4
|
+
require 'babl/operators/default'
|
5
|
+
require 'babl/operators/dep'
|
6
|
+
require 'babl/operators/each'
|
7
|
+
require 'babl/operators/enter'
|
8
|
+
require 'babl/operators/extends'
|
9
|
+
require 'babl/operators/merge'
|
10
|
+
require 'babl/operators/nav'
|
11
|
+
require 'babl/operators/null'
|
12
|
+
require 'babl/operators/nullable'
|
13
|
+
require 'babl/operators/object'
|
14
|
+
require 'babl/operators/parent'
|
15
|
+
require 'babl/operators/partial'
|
16
|
+
require 'babl/operators/pin'
|
17
|
+
require 'babl/operators/source'
|
18
|
+
require 'babl/operators/static'
|
19
|
+
require 'babl/operators/switch'
|
20
|
+
require 'babl/operators/typed'
|
21
|
+
require 'babl/operators/with'
|
data/lib/babl/operators/array.rb
CHANGED
data/lib/babl/operators/dep.rb
CHANGED
data/lib/babl/operators/each.rb
CHANGED
data/lib/babl/operators/enter.rb
CHANGED
data/lib/babl/operators/merge.rb
CHANGED
data/lib/babl/operators/nav.rb
CHANGED
data/lib/babl/operators/pin.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require 'babl/nodes
|
2
|
-
require 'babl/nodes/terminal_value'
|
1
|
+
require 'babl/nodes'
|
3
2
|
require 'babl/errors'
|
4
3
|
|
5
4
|
module Babl
|
@@ -9,7 +8,8 @@ module Babl
|
|
9
8
|
# Create a static JSON value
|
10
9
|
def static(val)
|
11
10
|
case val
|
12
|
-
when String, Numeric, NilClass, TrueClass, FalseClass
|
11
|
+
when ::String, ::Numeric, ::NilClass, ::TrueClass, ::FalseClass
|
12
|
+
construct_terminal { Nodes::Static.new(val) }
|
13
13
|
else call(Nodes::TerminalValue.instance.render_object(val))
|
14
14
|
end
|
15
15
|
rescue Errors::RenderingError => exception
|
data/lib/babl/operators/typed.rb
CHANGED