dry-initializer 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.travis.yml +7 -4
- data/CHANGELOG.md +8 -0
- data/dry-initializer.gemspec +2 -1
- data/lib/dry/initializer/builder.rb +12 -3
- data/spec/dry/reader_spec.rb +77 -12
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70ccaaebd426057c1b1b16f3496d7c8176fc64d1
|
4
|
+
data.tar.gz: a7506caaa5c5c2e7b84046897fa77a5793b870af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9eced89d306d84bd02fcd30f0ba87d9de23ec0743ab0e3e1965f230b2de50a284fb7fbb4e7151a4394f7547b1c6f438a2c92d5568f4d8c82fd204a86dcfef9f
|
7
|
+
data.tar.gz: 744fadbba1b5a6e6caa64a90f50a786baf36f0e0b74fd314d12b48469fcd221d470e3d4ddc58200ac5cbacac5ef78e59ab0f18942156821ac7e968e57240a4cd
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
---
|
2
|
+
sudo: false
|
2
3
|
language: ruby
|
3
|
-
before_install: gem install bundler -v 1.11.2
|
4
4
|
cache: bundler
|
5
|
-
script:
|
5
|
+
script:
|
6
|
+
- bundle exec rspec
|
7
|
+
- bundle exec rubocop
|
6
8
|
rvm:
|
7
9
|
- '2.2'
|
8
10
|
- '2.3.0'
|
9
|
-
- rbx-2
|
11
|
+
# - rbx-2
|
10
12
|
- ruby-head
|
11
|
-
- jruby-9
|
13
|
+
- jruby-9.1.0.0
|
12
14
|
- jruby-head
|
15
|
+
before_install: gem install bundler -v 1.12.5
|
13
16
|
matrix:
|
14
17
|
allow_failures:
|
15
18
|
- rvm: ruby-head
|
data/CHANGELOG.md
CHANGED
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.
|
3
|
+
gem.version = "0.6.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"
|
@@ -16,4 +16,5 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.add_development_dependency "rspec", "~> 3.0"
|
17
17
|
gem.add_development_dependency "rake", "~> 10.0"
|
18
18
|
gem.add_development_dependency "dry-types", "~> 0.5", "> 0.5.1"
|
19
|
+
gem.add_development_dependency "rubocop", "~> 0.42"
|
19
20
|
end
|
@@ -76,10 +76,19 @@ module Dry::Initializer
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def define_readers(mixin)
|
79
|
-
|
80
|
-
|
79
|
+
define_reader(
|
80
|
+
mixin,
|
81
|
+
:attr_reader,
|
82
|
+
->(item) { item.settings[:reader] != false }
|
83
|
+
)
|
84
|
+
define_reader mixin, :private
|
85
|
+
define_reader mixin, :protected
|
86
|
+
end
|
81
87
|
|
82
|
-
|
88
|
+
def define_reader(mixin, method, filter_lambda = nil)
|
89
|
+
filter_lambda ||= ->(item) { item.settings[:reader] == method }
|
90
|
+
readers = @signature.select(&filter_lambda).map(&:name)
|
91
|
+
mixin.send method, *readers if readers.any?
|
83
92
|
end
|
84
93
|
|
85
94
|
def reload_initializer(mixin)
|
data/spec/dry/reader_spec.rb
CHANGED
@@ -1,22 +1,87 @@
|
|
1
1
|
describe "reader" do
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
shared_examples "it has no public attr_reader" do
|
3
|
+
it "does not define a public attr_reader" do
|
4
|
+
expect(subject).not_to respond_to :foo
|
5
|
+
expect(subject).not_to respond_to :bar
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
context "with reader: :public or no reader: option" do
|
10
|
+
subject do
|
11
|
+
class Test::Foo
|
12
|
+
extend Dry::Initializer::Mixin
|
13
|
+
|
14
|
+
param :foo
|
15
|
+
param :foo2, reader: :public
|
16
|
+
option :bar
|
17
|
+
option :bar2, reader: :public
|
18
|
+
end
|
19
|
+
|
20
|
+
Test::Foo.new 1, 2, bar: 3, bar2: 4
|
21
|
+
end
|
5
22
|
|
6
|
-
|
7
|
-
|
23
|
+
it "defines a public attr_reader by default" do
|
24
|
+
expect(subject).to respond_to(:foo, :foo2)
|
25
|
+
expect(subject).to respond_to :bar
|
26
|
+
expect(subject).to respond_to :bar2
|
8
27
|
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with reader: false" do
|
31
|
+
subject do
|
32
|
+
class Test::Foo
|
33
|
+
extend Dry::Initializer::Mixin
|
34
|
+
|
35
|
+
param :foo, reader: false
|
36
|
+
option :bar, reader: false
|
37
|
+
end
|
38
|
+
|
39
|
+
Test::Foo.new 1, bar: 2
|
40
|
+
end
|
41
|
+
|
42
|
+
it_behaves_like "it has no public attr_reader"
|
9
43
|
|
10
|
-
|
44
|
+
it "keeps assigning variables" do
|
45
|
+
expect(subject.instance_variable_get(:@foo)).to eql 1
|
46
|
+
expect(subject.instance_variable_get(:@bar)).to eql 2
|
47
|
+
end
|
11
48
|
end
|
12
49
|
|
13
|
-
|
14
|
-
|
15
|
-
|
50
|
+
context "with reader: :private" do
|
51
|
+
subject do
|
52
|
+
class Test::Foo
|
53
|
+
extend Dry::Initializer::Mixin
|
54
|
+
|
55
|
+
param :foo, reader: :private
|
56
|
+
option :bar, reader: :private
|
57
|
+
end
|
58
|
+
|
59
|
+
Test::Foo.new 1, bar: 2
|
60
|
+
end
|
61
|
+
|
62
|
+
it_behaves_like "it has no public attr_reader"
|
63
|
+
|
64
|
+
it "adds a private attr_reader" do
|
65
|
+
expect(subject.send(:foo)).to eql 1
|
66
|
+
expect(subject.send(:bar)).to eql 2
|
67
|
+
end
|
16
68
|
end
|
17
69
|
|
18
|
-
|
19
|
-
|
20
|
-
|
70
|
+
context "with reader: :protected" do
|
71
|
+
subject do
|
72
|
+
class Test::Foo
|
73
|
+
extend Dry::Initializer::Mixin
|
74
|
+
|
75
|
+
param :foo, reader: :protected
|
76
|
+
option :bar, reader: :protected
|
77
|
+
end
|
78
|
+
|
79
|
+
Test::Foo.new 1, bar: 2
|
80
|
+
end
|
81
|
+
|
82
|
+
it "adds a protected attr_reader" do
|
83
|
+
protected_instance_methods = subject.class.protected_instance_methods
|
84
|
+
expect(protected_instance_methods).to match_array([:foo, :bar])
|
85
|
+
end
|
21
86
|
end
|
22
87
|
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.
|
4
|
+
version: 0.6.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-08
|
12
|
+
date: 2016-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -59,6 +59,20 @@ dependencies:
|
|
59
59
|
- - ">"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.5.1
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rubocop
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.42'
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.42'
|
62
76
|
description:
|
63
77
|
email:
|
64
78
|
- hashtable@yandex.ru
|