dry-initializer 0.6.0 → 0.7.0

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
  SHA1:
3
- metadata.gz: 70ccaaebd426057c1b1b16f3496d7c8176fc64d1
4
- data.tar.gz: a7506caaa5c5c2e7b84046897fa77a5793b870af
3
+ metadata.gz: 0de7dd513351b39d831351662ec6268ebf1920a9
4
+ data.tar.gz: 1435433ffc6eabba75f481e302ea4b7dcc47d37b
5
5
  SHA512:
6
- metadata.gz: d9eced89d306d84bd02fcd30f0ba87d9de23ec0743ab0e3e1965f230b2de50a284fb7fbb4e7151a4394f7547b1c6f438a2c92d5568f4d8c82fd204a86dcfef9f
7
- data.tar.gz: 744fadbba1b5a6e6caa64a90f50a786baf36f0e0b74fd314d12b48469fcd221d470e3d4ddc58200ac5cbacac5ef78e59ab0f18942156821ac7e968e57240a4cd
6
+ metadata.gz: 7ed882e91dfeed3a4dcc8ade69792beca84334d9850e700de67462cead64434fdfeed5039d188b42799b204d1cb871394e0c9c0e8a7c26ba5d02d6a2c72c08d3
7
+ data.tar.gz: a477d334fd746c41d09bfc49bdde5af80f4aa22176996518092853bf3a660f3fa4f77f30a84f495d04f54f1592b95d077a3f17473dbd759bf7e310c9ef0396bd
@@ -1,3 +1,11 @@
1
+ ## v0.7.0 2016-10-11
2
+
3
+ ### Added
4
+
5
+ * Shared settings with `#using` method (@nepalez)
6
+
7
+ [Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-initializer/compare/v0.6.0..v0.7.0)
8
+
1
9
  ## v0.6.0 2016-10-09
2
10
 
3
11
  ### Added
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "dry-initializer"
3
- gem.version = "0.6.0"
3
+ gem.version = "0.7.0"
4
4
  gem.author = ["Vladimir Kochnev (marshall-lee)", "Andrew Kozin (nepalez)"]
5
5
  gem.email = ["hashtable@yandex.ru", "andrew.kozin@gmail.com"]
6
6
  gem.homepage = "https://github.com/dryrb/dry-initializer"
@@ -1,3 +1,5 @@
1
+ require_relative "scope"
2
+
1
3
  module Dry::Initializer
2
4
  # Class-level DSL for the initializer
3
5
  module Mixin
@@ -29,6 +31,17 @@ module Dry::Initializer
29
31
  initializer_builder.call(self)
30
32
  end
31
33
 
34
+ # Declares arguments (params and options) with default settings
35
+ #
36
+ # @param [Hash] settings Shared settings
37
+ # @param [Proc] block Definitions for params and options
38
+ # @return [self]
39
+ #
40
+ def using(**settings, &block)
41
+ Scope.new(self, settings).instance_eval(&block)
42
+ self
43
+ end
44
+
32
45
  # Adds new plugin to the builder
33
46
  #
34
47
  # @param [Dry::Initializer::Plugins::Base] plugin
@@ -0,0 +1,31 @@
1
+ module Dry::Initializer
2
+ # Shared scope for several params and options
3
+ class Scope
4
+ # Defines param with shared settings
5
+ #
6
+ # @param (see Dry::Initializer::Mixin#param)
7
+ # @option (see Dry::Initializer::Mixin#param)
8
+ # @return (see Dry::Initializer::Mixin#param)
9
+ #
10
+ def param(name, **options)
11
+ @klass.param name, @options.merge(options)
12
+ end
13
+
14
+ # Defines option with shared settings
15
+ #
16
+ # @param (see Dry::Initializer::Mixin#option)
17
+ # @option (see Dry::Initializer::Mixin#option)
18
+ # @return (see Dry::Initializer::Mixin#option)
19
+ #
20
+ def option(name, **options)
21
+ @klass.option name, @options.merge(options)
22
+ end
23
+
24
+ private
25
+
26
+ def initialize(klass, **options)
27
+ @klass = klass
28
+ @options = options
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ describe "shared definition" do
2
+ subject do
3
+ class Test::Foo
4
+ extend Dry::Initializer::Mixin
5
+
6
+ using default: proc { nil } do
7
+ param :foo
8
+ option :bar
9
+ option :baz, default: proc { 0 }
10
+ end
11
+ end
12
+ end
13
+
14
+ it "is applied to params and options" do
15
+ expect(subject.new.foo).to be_nil
16
+ expect(subject.new.bar).to be_nil
17
+ end
18
+
19
+ it "can be reloaded" do
20
+ expect(subject.new.baz).to eq 0
21
+ end
22
+ end
@@ -9,7 +9,7 @@ describe "type constraint" do
9
9
 
10
10
  class Test::Foo
11
11
  extend Dry::Initializer::Mixin
12
- param :foo, type: Test::Types::Strict::String
12
+ param :foo, type: Test::Types::Strict::String, optional: true
13
13
  end
14
14
  end
15
15
 
@@ -28,6 +28,14 @@ describe "type constraint" do
28
28
  expect { subject }.not_to raise_error
29
29
  end
30
30
  end
31
+
32
+ context "if optional value not set" do
33
+ subject { Test::Foo.new }
34
+
35
+ it "completes the initialization" do
36
+ expect { subject }.not_to raise_error
37
+ end
38
+ end
31
39
  end
32
40
 
33
41
  context "by invalid constraint" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-initializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Kochnev (marshall-lee)
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-08 00:00:00.000000000 Z
12
+ date: 2016-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -119,6 +119,7 @@ files:
119
119
  - lib/dry/initializer/plugins/signature.rb
120
120
  - lib/dry/initializer/plugins/type_constraint.rb
121
121
  - lib/dry/initializer/plugins/variable_setter.rb
122
+ - lib/dry/initializer/scope.rb
122
123
  - lib/dry/initializer/signature.rb
123
124
  - spec/dry/base_spec.rb
124
125
  - spec/dry/container_spec.rb
@@ -131,6 +132,7 @@ files:
131
132
  - spec/dry/plugin_registry_spec.rb
132
133
  - spec/dry/reader_spec.rb
133
134
  - spec/dry/repetitive_definitions_spec.rb
135
+ - spec/dry/shared_definitions_spec.rb
134
136
  - spec/dry/subclassing_spec.rb
135
137
  - spec/dry/type_constraint_spec.rb
136
138
  - spec/dry/value_coercion_via_dry_types_spec.rb
@@ -171,6 +173,7 @@ test_files:
171
173
  - spec/dry/plugin_registry_spec.rb
172
174
  - spec/dry/reader_spec.rb
173
175
  - spec/dry/repetitive_definitions_spec.rb
176
+ - spec/dry/shared_definitions_spec.rb
174
177
  - spec/dry/subclassing_spec.rb
175
178
  - spec/dry/type_constraint_spec.rb
176
179
  - spec/dry/value_coercion_via_dry_types_spec.rb