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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7d86e04a313435b96cb103dc1f28a9427d7e799
4
- data.tar.gz: b4b2556846b6e0ebee4b61808a28afc0c367290e
3
+ metadata.gz: 8f262a2ae5fa55ff9bc86dee062ec773868b4671
4
+ data.tar.gz: a89671bbf85a6b4da055a639b7125a44456fe249
5
5
  SHA512:
6
- metadata.gz: 1d0e559d62195cab0d72796b00a65ad0a6e777dc16076b3a692b4145f5366d9a9574d1eb52187ac19a222e71922bf4479fc49ceffbd7fd1d6a35e57e395ca864
7
- data.tar.gz: 3e64a46b03f6956ce80de18fb5f99b7aed2eb61817617d106719222c6b2405073b6b217db4ac79d51765d2d9b5c5f99eb02624d082be8b259890f3751dc86b93
6
+ metadata.gz: 0d09cbdfa72b94010534ce22a4d252c8158267b94e46a88a0d588bed2070c0256701be42c701290b51eabdfbced55135012c216e7fecf9386caf3cbd5c1e2fa9
7
+ data.tar.gz: a360f864906d84a652f62355082f6ad605ac569ef0d3c0db4a07203f3d34e359b5736b40279a9561a371221ce1dcdc47e063256d86e0e7760b5f607199b69d62
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v0.1.1 2016-04-28
2
+
3
+ ### Added
4
+
5
+ * `include Dry::Initializer.define -> do .. end` syntax (flash-gordon)
6
+
1
7
  ## v0.1.0 2016-04-26
2
8
 
3
9
  Class DSL splitted to mixin and container versions (thanks to @AMHOL for the idea).
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 `{}` syntax for the block, not `do..end`
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "dry-initializer"
3
- gem.version = "0.1.0"
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"
@@ -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.instance_eval(&block)
17
+ container.instance_exec(&(proc || block))
18
18
  end
19
19
  end
20
20
  end
@@ -1,21 +1,45 @@
1
1
  describe "base example" do
2
- before do
3
- class Test::Foo
4
- include Dry::Initializer.define {
5
- param :foo
6
- param :bar
7
- option :baz
8
- option :qux
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
- it "instantiates attributes" do
14
- subject = Test::Foo.new(1, 2, baz: 3, qux: 4)
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
- expect(subject.foo).to eql 1
17
- expect(subject.bar).to eql 2
18
- expect(subject.baz).to eql 3
19
- expect(subject.qux).to eql 4
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.0
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-25 00:00:00.000000000 Z
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.4.8
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