dry-initializer 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +3 -3
- data/dry-initializer.gemspec +1 -1
- data/lib/dry/initializer.rb +2 -2
- data/spec/dry/container_spec.rb +38 -14
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f262a2ae5fa55ff9bc86dee062ec773868b4671
|
4
|
+
data.tar.gz: a89671bbf85a6b4da055a639b7125a44456fe249
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d09cbdfa72b94010534ce22a4d252c8158267b94e46a88a0d588bed2070c0256701be42c701290b51eabdfbced55135012c216e7fecf9386caf3cbd5c1e2fa9
|
7
|
+
data.tar.gz: a360f864906d84a652f62355082f6ad605ac569ef0d3c0db4a07203f3d34e359b5736b40279a9561a371221ce1dcdc47e063256d86e0e7760b5f607199b69d62
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -84,12 +84,12 @@ Instead of extending a class with the `Dry::Initializer::Mixin`, you can include
|
|
84
84
|
require 'dry-initializer'
|
85
85
|
|
86
86
|
class User
|
87
|
-
# notice
|
88
|
-
include Dry::Initializer.define
|
87
|
+
# notice `-> do .. end` syntax
|
88
|
+
include Dry::Initializer.define -> do
|
89
89
|
param :name, type: String
|
90
90
|
param :role, default: proc { 'customer' }
|
91
91
|
option :admin, default: proc { false }
|
92
|
-
|
92
|
+
end
|
93
93
|
end
|
94
94
|
```
|
95
95
|
|
data/dry-initializer.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "dry-initializer"
|
3
|
-
gem.version = "0.1.
|
3
|
+
gem.version = "0.1.1"
|
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"
|
data/lib/dry/initializer.rb
CHANGED
@@ -11,10 +11,10 @@ module Dry
|
|
11
11
|
require_relative "initializer/builder"
|
12
12
|
require_relative "initializer/mixin"
|
13
13
|
|
14
|
-
def self.define(&block)
|
14
|
+
def self.define(proc = nil, &block)
|
15
15
|
Module.new do |container|
|
16
16
|
container.extend Dry::Initializer::Mixin
|
17
|
-
container.
|
17
|
+
container.instance_exec(&(proc || block))
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/spec/dry/container_spec.rb
CHANGED
@@ -1,21 +1,45 @@
|
|
1
1
|
describe "base example" do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
2
|
+
context 'using block syntax' do
|
3
|
+
before do
|
4
|
+
class Test::Foo
|
5
|
+
include Dry::Initializer.define {
|
6
|
+
param :foo
|
7
|
+
param :bar
|
8
|
+
option :baz
|
9
|
+
option :qux
|
10
|
+
}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "instantiates attributes" do
|
15
|
+
subject = Test::Foo.new(1, 2, baz: 3, qux: 4)
|
16
|
+
|
17
|
+
expect(subject.foo).to eql 1
|
18
|
+
expect(subject.bar).to eql 2
|
19
|
+
expect(subject.baz).to eql 3
|
20
|
+
expect(subject.qux).to eql 4
|
10
21
|
end
|
11
22
|
end
|
12
23
|
|
13
|
-
|
14
|
-
|
24
|
+
context 'using lambda syntax' do
|
25
|
+
before do
|
26
|
+
class Test::Foo
|
27
|
+
include Dry::Initializer.define -> do
|
28
|
+
param :foo
|
29
|
+
param :bar
|
30
|
+
option :baz
|
31
|
+
option :qux
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "instantiates attributes" do
|
37
|
+
subject = Test::Foo.new(1, 2, baz: 3, qux: 4)
|
15
38
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
39
|
+
expect(subject.foo).to eql 1
|
40
|
+
expect(subject.bar).to eql 2
|
41
|
+
expect(subject.baz).to eql 3
|
42
|
+
expect(subject.qux).to eql 4
|
43
|
+
end
|
20
44
|
end
|
21
45
|
end
|
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.1.
|
4
|
+
version: 0.1.1
|
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-04-
|
12
|
+
date: 2016-04-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
requirements: []
|
132
132
|
rubyforge_project:
|
133
|
-
rubygems_version: 2.
|
133
|
+
rubygems_version: 2.5.1
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: DSL for declaring params and options of the initializer
|