paradocs 1.1.1 → 1.1.2
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 -11
- data/docs/changelog.md +3 -0
- data/docs/documentation_generation.md +2 -2
- data/lib/paradocs/extensions/structure.rb +5 -10
- data/lib/paradocs/version.rb +1 -1
- data/spec/subschema_spec.rb +0 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dc965cce0c862cdc35b68bbf6be48418885c69b
|
4
|
+
data.tar.gz: a0763156554745078e092b79be02d4103b906b77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6664235a1e30f28196a1e58c1826ec7ff22f33b10db0275998ea21eed1dbfb7f17d76de8b9d75f3a57ba0621bf309874a3d0bb2ba099b2527228bfe777ffb68c
|
7
|
+
data.tar.gz: 6d2658f064f28a80f148f7ababe14bb5dafdd65a46a84a3c9786cb9413d65bc6480cc4bef8c7d8cf6b8e7e52cb7f2868d53e0df40c7e1cbb265909b9f4b34876
|
data/README.md
CHANGED
@@ -37,14 +37,4 @@ form.errors # => {}
|
|
37
37
|
```
|
38
38
|
|
39
39
|
## Learn more
|
40
|
-
|
41
|
-
- [Built In Policies](https://github.com/mtkachenk0/paradocs/wiki/Policies#built-in-policies)
|
42
|
-
- [Type Policies](https://github.com/mtkachenk0/paradocs/wiki/Policies#type-coercions)
|
43
|
-
- [Presence Policies](https://github.com/mtkachenk0/paradocs/wiki/Policies#presence-policies)
|
44
|
-
- [Custom Policies](https://github.com/mtkachenk0/paradocs/wiki/Policies#custom-policies)
|
45
|
-
- [Schema](https://github.com/mtkachenk0/paradocs/wiki/schema)
|
46
|
-
- [Expanding fields dynamically](https://github.com/mtkachenk0/paradocs/wiki/schema#expanding-fields-dynamically)
|
47
|
-
- [Multiple schema definitions](https://github.com/mtkachenk0/paradocs/wiki/schema#multiple-schema-definitions)
|
48
|
-
- [Documentation Generation](https://github.com/mtkachenk0/paradocs/wiki/Documentation-Generation)
|
49
|
-
- [What if my fields are conditional?!](https://github.com/mtkachenk0/paradocs/wiki/subschema)
|
50
|
-
- [For those who need more: RTFM](https://github.com/mtkachenk0/paradocs/wiki)
|
40
|
+
Please read the [documentation](https://paradocs.readthedocs.io/en/latest)
|
data/docs/changelog.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.1.2
|
4
|
+
- Regenerate structures each time without saving them into instance attributes.
|
5
|
+
|
3
6
|
## 1.1.1
|
4
7
|
- Fixed bug with missing `errors` meta key in `Structure#all_nested` and `Structure#all_flatten` methods.
|
5
8
|
- Fixed bug with absent `nested_name` meta key in `#Structure#all_nested` method.
|
@@ -188,7 +188,7 @@ all_nested[:subschema] # =>
|
|
188
188
|
required: true,
|
189
189
|
present: true,
|
190
190
|
json_path: "$.data",
|
191
|
-
|
191
|
+
nested_name: "data",
|
192
192
|
structure: {
|
193
193
|
"role" => {type: :string, options: ["admin", "user"], default: "user", json_path: "$.data.role", mutates_schema: true, nested_name: "data.role"},
|
194
194
|
"test_field" => {required: true, present: true, json_path: "$.data.test_field", nested_name: "data.test_field"},
|
@@ -209,7 +209,7 @@ all_nested[:test_subschema] # =>
|
|
209
209
|
required: true,
|
210
210
|
present: true,
|
211
211
|
json_path: "$.data",
|
212
|
-
|
212
|
+
nested_name: "data",
|
213
213
|
structure: {
|
214
214
|
"role" => {type: :string, options: ["admin", "user"], default: "user", json_path: "$.data.role", mutates_schema: true, nested_name: "data.role"},
|
215
215
|
"test1" => {required: true, present: true, json_path: "$.data.test1", nested_name: "data.test1"},
|
@@ -14,12 +14,8 @@ module Paradocs
|
|
14
14
|
@root = root
|
15
15
|
end
|
16
16
|
|
17
|
-
def flush!
|
18
|
-
@nested, @all_nested, @flatten, @all_flatten = [nil] * 4
|
19
|
-
end
|
20
|
-
|
21
17
|
def nested(&block)
|
22
|
-
|
18
|
+
schema.fields.each_with_object({errors => [], subschemes => {}}) do |(_, field), result|
|
23
19
|
meta, sc = collect_meta(field, root)
|
24
20
|
if sc
|
25
21
|
meta[:structure] = self.class.new(sc, ignore_transparent, meta[:json_path]).nested(&block)
|
@@ -39,7 +35,7 @@ module Paradocs
|
|
39
35
|
end
|
40
36
|
|
41
37
|
def all_nested(&block)
|
42
|
-
|
38
|
+
all_flatten(&block).each_with_object({}) do |(name, struct), obj|
|
43
39
|
obj[name] = {}
|
44
40
|
# sort the flatten struct to have iterated 1lvl keys before 2lvl and so on...
|
45
41
|
struct.sort_by { |k, v| k.to_s.count(".") }.each do |key, value|
|
@@ -61,13 +57,12 @@ module Paradocs
|
|
61
57
|
end
|
62
58
|
|
63
59
|
def all_flatten(schema_structure=nil, &block)
|
64
|
-
return @all_flatten if @all_flatten
|
65
60
|
schema_structure ||= flatten(&block)
|
66
61
|
if schema_structure[subschemes].empty?
|
67
62
|
schema_structure.delete(subschemes) # don't include redundant key
|
68
|
-
return
|
63
|
+
return {DEFAULT => schema_structure}
|
69
64
|
end
|
70
|
-
|
65
|
+
schema_structure[subschemes].each_with_object({}) do |(name, subschema), result|
|
71
66
|
if subschema[subschemes].empty?
|
72
67
|
result[name] = schema_structure.merge(subschema)
|
73
68
|
result[name][errors] += schema_structure[errors]
|
@@ -83,7 +78,7 @@ module Paradocs
|
|
83
78
|
end
|
84
79
|
|
85
80
|
def flatten(&block)
|
86
|
-
|
81
|
+
schema.fields.each_with_object({errors => [], subschemes => {}}) do |(_, field), obj|
|
87
82
|
meta, sc = collect_meta(field, root)
|
88
83
|
humanized_name = meta.delete(:nested_name)
|
89
84
|
obj[humanized_name] = meta unless ignore_transparent && field.transparent?
|
data/lib/paradocs/version.rb
CHANGED
data/spec/subschema_spec.rb
CHANGED
@@ -72,7 +72,6 @@ describe "schemes with subschemes" do
|
|
72
72
|
expect(result.errors).to eq({"$.fail_field"=>["is required"]})
|
73
73
|
expect(result.output).to eq({error: :here, fail_field: nil})
|
74
74
|
expect(schema.structure.nested).to eq(structure)
|
75
|
-
schema.structure.flush!
|
76
75
|
expect(schema.structure(ignore_transparent: false).nested).to eq(structure.merge(
|
77
76
|
error: {transparent: true, mutates_schema: true, json_path: "$.error", nested_name: "error"}
|
78
77
|
))
|
@@ -80,9 +79,7 @@ describe "schemes with subschemes" do
|
|
80
79
|
result = schema.resolve({})
|
81
80
|
expect(result.errors).to eq({"$.success_field"=>["is required"]})
|
82
81
|
expect(result.output).to eq({success_field: nil})
|
83
|
-
schema.structure.flush!
|
84
82
|
expect(schema.structure.nested).to eq(structure)
|
85
|
-
schema.structure.flush!
|
86
83
|
expect(schema.structure(ignore_transparent: false).nested).to eq(structure.merge(
|
87
84
|
error: {transparent: true, mutates_schema: true, json_path: "$.error", nested_name: "error"}
|
88
85
|
))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paradocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxim Tkachenko
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-09-
|
12
|
+
date: 2020-09-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|