parametric 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac256ff264b098720b8104c163e3f63e34b1caf4bd72bfa037451f4748b4982a
4
- data.tar.gz: 9e4f467c327b68fdc24b9da3068f784c75df95b9e642d804eaf5d1e743ad635c
3
+ metadata.gz: dc68b025c47e3c4d8d4053107aa5d80f935e34b465c1b3f5cf1140aa042305d1
4
+ data.tar.gz: 47018cceddad3f64631402abcfb2bfdddb96ef8ba373e51ae08686daecb3e4fa
5
5
  SHA512:
6
- metadata.gz: 91b8cea04a00f942e1fd6f1fd20a70b60903e3b959c434d489ad0431154700f176f7905ebe19957d11b9741617da22dac24dc9d05b8ee6abb90914537ea268c5
7
- data.tar.gz: b2e705e5a45f5b795f19a4c222684375109389cfd8407e1875aea8da9ab82e52a66621a7906d9045d792d9c7ff4d8bd76d5af39ef02488fc63ff7c290fc2c9ba
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.
@@ -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
- return current_schema unless options.any? || block_given?
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
@@ -1,3 +1,3 @@
1
1
  module Parametric
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
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.1
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-08-08 00:00:00.000000000 Z
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.6
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
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here