paradocs 1.0.22 → 1.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/paradocs/struct.rb +4 -4
- data/lib/paradocs/version.rb +1 -1
- data/paradocs.gemspec +3 -3
- data/spec/struct_spec.rb +37 -9
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46df9e6a68b9d5574d7923e38646fbaeedc20a61
|
4
|
+
data.tar.gz: 96ac7dda4da79eb1aa56c13adf003f1f9b6c0585
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b24241e65b44f94a431e47780f8e9932ff3b0f2da288d57ae483d7663f9c9a9286467799d3b35fd8ee8730cc9a57faf475c9cc25aa51d38690ac37af61e2c2e5
|
7
|
+
data.tar.gz: be37a51df5961b6e1d73f3c9c126a2a112d8cc6482451459ec0efd11af4a8a3a715f47e8427a01f3d5137e9e5164ca205fe575d9c8d5a49a2ea805bdcde89996
|
data/README.md
CHANGED
@@ -6,9 +6,13 @@ Declaratively define data schemas in your Ruby objects, and use them to whitelis
|
|
6
6
|
|
7
7
|
Useful for building self-documeting APIs, search or form objects. Or possibly as an alternative to Rails' _strong parameters_ (it has no dependencies on Rails and can be used stand-alone).
|
8
8
|
## Installation
|
9
|
+
```sh
|
10
|
+
$ gem install paradocs
|
11
|
+
```
|
9
12
|
|
13
|
+
Or with Bundler in your Gemfile.
|
10
14
|
```rb
|
11
|
-
gem 'paradocs'
|
15
|
+
gem 'paradocs'
|
12
16
|
```
|
13
17
|
|
14
18
|
## Getting Started
|
data/lib/paradocs/struct.rb
CHANGED
@@ -18,8 +18,8 @@ module Paradocs
|
|
18
18
|
base.extend ClassMethods
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize(attrs = {})
|
22
|
-
@_results = self.class.schema.resolve(attrs)
|
21
|
+
def initialize(attrs = {}, environment = {})
|
22
|
+
@_results = self.class.schema.resolve(attrs, environment)
|
23
23
|
@_graph = self.class.build(@_results.output)
|
24
24
|
end
|
25
25
|
|
@@ -48,8 +48,8 @@ module Paradocs
|
|
48
48
|
attr_reader :_graph, :_results
|
49
49
|
|
50
50
|
module ClassMethods
|
51
|
-
def new!(attrs = {})
|
52
|
-
st = new(attrs)
|
51
|
+
def new!(attrs = {}, environment = {})
|
52
|
+
st = new(attrs, environment)
|
53
53
|
raise InvalidStructError.new(st) unless st.valid?
|
54
54
|
st
|
55
55
|
end
|
data/lib/paradocs/version.rb
CHANGED
data/paradocs.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'paradocs/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "paradocs"
|
8
8
|
spec.version = Paradocs::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
9
|
+
spec.authors = ["Maxim Tkachenko", "Ismael Celis"]
|
10
|
+
spec.email = ["tkachenko.maxim.w@gmail.com", "ismaelct@gmail.com"]
|
11
11
|
spec.description = %q{Flexible DSL for declaring allowed parameters focused on DRY validation that gives you opportunity to generate API documentation on-the-fly.}
|
12
12
|
spec.summary = %q{A huge add-on for original gem mostly focused on retrieving the more metadata from declared schemas as possible.}
|
13
13
|
spec.homepage = "https://github.com/mtkachenk0/paradocs"
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 2.1"
|
22
|
-
spec.add_development_dependency "rake", "
|
22
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
23
23
|
spec.add_development_dependency "rspec", '3.4.0'
|
24
24
|
spec.add_development_dependency "pry", "~> 0"
|
25
25
|
end
|
data/spec/struct_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'paradocs/struct'
|
3
3
|
|
4
4
|
describe Paradocs::Struct do
|
5
|
-
it
|
5
|
+
it 'works' do
|
6
6
|
friend_class = Class.new do
|
7
7
|
include Paradocs::Struct
|
8
8
|
|
@@ -53,7 +53,7 @@ describe Paradocs::Struct do
|
|
53
53
|
expect(invalid_instance.friends[1].errors['$.name']).not_to be_nil
|
54
54
|
end
|
55
55
|
|
56
|
-
it
|
56
|
+
it 'is inmutable by default' do
|
57
57
|
klass = Class.new do
|
58
58
|
include Paradocs::Struct
|
59
59
|
|
@@ -66,7 +66,7 @@ describe Paradocs::Struct do
|
|
66
66
|
|
67
67
|
instance = klass.new
|
68
68
|
expect {
|
69
|
-
instance.title =
|
69
|
+
instance.title = 'foo'
|
70
70
|
}.to raise_error NoMethodError
|
71
71
|
|
72
72
|
expect {
|
@@ -74,7 +74,7 @@ describe Paradocs::Struct do
|
|
74
74
|
}.to raise_error RuntimeError
|
75
75
|
end
|
76
76
|
|
77
|
-
it
|
77
|
+
it 'works with anonymous nested schemas' do
|
78
78
|
klass = Class.new do
|
79
79
|
include Paradocs::Struct
|
80
80
|
|
@@ -125,7 +125,7 @@ describe Paradocs::Struct do
|
|
125
125
|
expect(user.friends.first.salutation).to eq 'my age is 43'
|
126
126
|
end
|
127
127
|
|
128
|
-
it
|
128
|
+
it 'wraps regular schemas in structs' do
|
129
129
|
friend_schema = Paradocs::Schema.new do
|
130
130
|
field(:name)
|
131
131
|
end
|
@@ -147,7 +147,7 @@ describe Paradocs::Struct do
|
|
147
147
|
expect(instance.friends.first.name).to eq 'Ismael'
|
148
148
|
end
|
149
149
|
|
150
|
-
it
|
150
|
+
it '#to_h' do
|
151
151
|
klass = Class.new do
|
152
152
|
include Paradocs::Struct
|
153
153
|
|
@@ -185,7 +185,7 @@ describe Paradocs::Struct do
|
|
185
185
|
expect(new_instance.to_h[:title]).to eq 'foo'
|
186
186
|
end
|
187
187
|
|
188
|
-
it
|
188
|
+
it 'works with inheritance' do
|
189
189
|
klass = Class.new do
|
190
190
|
include Paradocs::Struct
|
191
191
|
|
@@ -218,7 +218,7 @@ describe Paradocs::Struct do
|
|
218
218
|
expect(instance.friends.size).to eq 2
|
219
219
|
end
|
220
220
|
|
221
|
-
it
|
221
|
+
it 'implements deep struct equality' do
|
222
222
|
klass = Class.new do
|
223
223
|
include Paradocs::Struct
|
224
224
|
|
@@ -268,7 +268,7 @@ describe Paradocs::Struct do
|
|
268
268
|
expect(s1 == s4).to be false
|
269
269
|
end
|
270
270
|
|
271
|
-
it
|
271
|
+
it '#merge returns a new instance' do
|
272
272
|
klass = Class.new do
|
273
273
|
include Paradocs::Struct
|
274
274
|
|
@@ -301,6 +301,20 @@ describe Paradocs::Struct do
|
|
301
301
|
expect(copy.friends.first.name).to eq 'jane'
|
302
302
|
end
|
303
303
|
|
304
|
+
it 'passes the environment to the schema' do
|
305
|
+
klass = Class.new do
|
306
|
+
include Paradocs::Struct
|
307
|
+
|
308
|
+
schema do
|
309
|
+
field(:age).type(:integer)
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
new_instance = klass.new({}, { key: :value })
|
314
|
+
|
315
|
+
expect(new_instance.send(:_results).environment).to eq({ key: :value })
|
316
|
+
end
|
317
|
+
|
304
318
|
describe '.new!' do
|
305
319
|
it 'raises a useful exception if invalid data' do
|
306
320
|
klass = Class.new do
|
@@ -320,5 +334,19 @@ describe Paradocs::Struct do
|
|
320
334
|
valid = klass.new!(title: 'foo')
|
321
335
|
expect(valid.title).to eq 'foo'
|
322
336
|
end
|
337
|
+
|
338
|
+
it 'passes the environment to the schema' do
|
339
|
+
klass = Class.new do
|
340
|
+
include Paradocs::Struct
|
341
|
+
|
342
|
+
schema do
|
343
|
+
field(:title).type(:string).present
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
new_instance = klass.new!({ title: 'test' }, { key: :value })
|
348
|
+
|
349
|
+
expect(new_instance.send(:_results).environment).to eq({ key: :value })
|
350
|
+
end
|
323
351
|
end
|
324
352
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paradocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Ismael Celis
|
8
7
|
- Maxim Tkachenko
|
8
|
+
- Ismael Celis
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-
|
12
|
+
date: 2020-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -29,16 +29,16 @@ dependencies:
|
|
29
29
|
name: rake
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
34
|
+
version: 12.3.3
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version:
|
41
|
+
version: 12.3.3
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rspec
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,8 +70,8 @@ dependencies:
|
|
70
70
|
description: Flexible DSL for declaring allowed parameters focused on DRY validation
|
71
71
|
that gives you opportunity to generate API documentation on-the-fly.
|
72
72
|
email:
|
73
|
-
- ismaelct@gmail.com
|
74
73
|
- tkachenko.maxim.w@gmail.com
|
74
|
+
- ismaelct@gmail.com
|
75
75
|
executables:
|
76
76
|
- console
|
77
77
|
extensions: []
|