parametric 0.2.1 → 0.2.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 +15 -0
- data/lib/parametric/dsl.rb +7 -2
- data/lib/parametric/version.rb +1 -1
- data/spec/dsl_spec.rb +16 -0
- metadata +3 -5
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc68b025c47e3c4d8d4053107aa5d80f935e34b465c1b3f5cf1140aa042305d1
|
4
|
+
data.tar.gz: 47018cceddad3f64631402abcfb2bfdddb96ef8ba373e51ae08686daecb3e4fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c703ec9dcae0d876b994b39933b8f2aa81db05b50a421ce527c409c09c9e75bad21c238e8b9bb25fc29428bd88cf5d21b775ca04547c4ee2acdad8eaf4d52bd8
|
7
|
+
data.tar.gz: 2e442e6403b10f68f25609873fe47c68bf247e13f716dcb2b960bfc3d4d52e0567794e28f8f1df2970ac28378ed8a391aa21d2cc51952a1e33755199f4b5c8b9
|
data/README.md
CHANGED
@@ -567,6 +567,21 @@ class CreateUserForm
|
|
567
567
|
end
|
568
568
|
```
|
569
569
|
|
570
|
+
Form schemas can also be defined by passing another form or schema instance. This can be useful when building form classes in runtime.
|
571
|
+
|
572
|
+
```ruby
|
573
|
+
UserSchema = Parametric::Schema.new do
|
574
|
+
field(:name).type(:string).present
|
575
|
+
field(:age).type(:integer)
|
576
|
+
end
|
577
|
+
|
578
|
+
class CreateUserForm
|
579
|
+
include Parametric::DSL
|
580
|
+
# copy from UserSchema
|
581
|
+
schema UserSchema
|
582
|
+
end
|
583
|
+
```
|
584
|
+
|
570
585
|
### Form object inheritance
|
571
586
|
|
572
587
|
Sub classes of classes using the DSL will inherit schemas defined on the parent class.
|
data/lib/parametric/dsl.rb
CHANGED
@@ -48,9 +48,14 @@ module Parametric
|
|
48
48
|
options = args.last.is_a?(Hash) ? args.last : {}
|
49
49
|
key = args.first.is_a?(Symbol) ? args.first : DEFAULT_SCHEMA_NAME
|
50
50
|
current_schema = @schemas.fetch(key) { Parametric::Schema.new }
|
51
|
-
|
51
|
+
new_schema = if block_given? || options.any?
|
52
|
+
Parametric::Schema.new(options, &block)
|
53
|
+
elsif args.first.respond_to?(:schema)
|
54
|
+
args.first
|
55
|
+
end
|
56
|
+
|
57
|
+
return current_schema unless new_schema
|
52
58
|
|
53
|
-
new_schema = Parametric::Schema.new(options, &block)
|
54
59
|
@schemas[key] = current_schema ? current_schema.merge(new_schema) : new_schema
|
55
60
|
after_define_schema(@schemas[key])
|
56
61
|
end
|
data/lib/parametric/version.rb
CHANGED
data/spec/dsl_spec.rb
CHANGED
@@ -156,5 +156,21 @@ describe "classes including DSL module" do
|
|
156
156
|
expect(results.output).to eq({age: 20})
|
157
157
|
end
|
158
158
|
end
|
159
|
+
|
160
|
+
describe "passing other schema or form in definition" do
|
161
|
+
it 'applies schema' do
|
162
|
+
a = Parametric::Schema.new do
|
163
|
+
field(:name).policy(:string)
|
164
|
+
field(:age).policy(:integer).default(40)
|
165
|
+
end
|
166
|
+
b = Class.new do
|
167
|
+
include Parametric::DSL
|
168
|
+
schema a
|
169
|
+
end
|
170
|
+
|
171
|
+
results = b.schema.resolve(name: 'Neil')
|
172
|
+
expect(results.output).to eq({name: 'Neil', age: 40})
|
173
|
+
end
|
174
|
+
end
|
159
175
|
end
|
160
176
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parametric
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ismael Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,7 +72,6 @@ email:
|
|
72
72
|
- ismaelct@gmail.com
|
73
73
|
executables:
|
74
74
|
- console
|
75
|
-
- setup
|
76
75
|
extensions: []
|
77
76
|
extra_rdoc_files: []
|
78
77
|
files:
|
@@ -84,7 +83,6 @@ files:
|
|
84
83
|
- README.md
|
85
84
|
- Rakefile
|
86
85
|
- bin/console
|
87
|
-
- bin/setup
|
88
86
|
- lib/parametric.rb
|
89
87
|
- lib/parametric/block_validator.rb
|
90
88
|
- lib/parametric/context.rb
|
@@ -128,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
126
|
version: '0'
|
129
127
|
requirements: []
|
130
128
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.7.
|
129
|
+
rubygems_version: 2.7.7
|
132
130
|
signing_key:
|
133
131
|
specification_version: 4
|
134
132
|
summary: DSL for declaring allowed parameters with options, regexp patern and default
|