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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 741920ad4c93079821b5dd2f4031fadaf6e4c3b7
4
- data.tar.gz: b64f94cc5b3295a3a9decc367fd00fd46bd0ee36
3
+ metadata.gz: 70ccaaebd426057c1b1b16f3496d7c8176fc64d1
4
+ data.tar.gz: a7506caaa5c5c2e7b84046897fa77a5793b870af
5
5
  SHA512:
6
- metadata.gz: 1716c91a5cebe7bd125542c3a3004fed51fef824d865351609332b18f234a1adbe99420e91045d5f5144dbf44d69bde670a84d578bd433137611af7c4daea12a
7
- data.tar.gz: 71b93072383a3ec4ad127057a4db3f99b0f1b21b6d50d0d8dda5776e21b43943de82c15f8a3e94668152339112fda1952e08fc1bd905439dd08d409012232737
6
+ metadata.gz: d9eced89d306d84bd02fcd30f0ba87d9de23ec0743ab0e3e1965f230b2de50a284fb7fbb4e7151a4394f7547b1c6f438a2c92d5568f4d8c82fd204a86dcfef9f
7
+ data.tar.gz: 744fadbba1b5a6e6caa64a90f50a786baf36f0e0b74fd314d12b48469fcd221d470e3d4ddc58200ac5cbacac5ef78e59ab0f18942156821ac7e968e57240a4cd
data/.rubocop.yml CHANGED
@@ -28,6 +28,10 @@ Style/Alias:
28
28
  Style/AsciiComments:
29
29
  Enabled: false
30
30
 
31
+ Style/BlockDelimiters:
32
+ Exclude:
33
+ - spec/**/*_spec.rb
34
+
31
35
  Style/CaseEquality:
32
36
  Enabled: false
33
37
 
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: bundle exec rspec
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
@@ -1,3 +1,11 @@
1
+ ## v0.6.0 2016-10-09
2
+
3
+ ### Added
4
+
5
+ * Support for private and protected readers in the `reader:` option (@jmgarnier)
6
+
7
+ [Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-initializer/compare/v0.5.0..v0.6.0)
8
+
1
9
  ## v0.5.0 2016-08-21
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.5.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
- readers = @signature.select { |item| item.settings[:reader] != false }
80
- .map(&:name)
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
- mixin.send :attr_reader, *readers if readers.any?
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)
@@ -1,22 +1,87 @@
1
1
  describe "reader" do
2
- subject do
3
- class Test::Foo
4
- extend Dry::Initializer::Mixin
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
- param :foo, reader: false
7
- option :bar, reader: false
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
- Test::Foo.new 1, bar: 2
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
- it "skips attr_reader" do
14
- expect(subject).not_to respond_to :foo
15
- expect(subject).not_to respond_to :bar
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
- it "keeps assigning variables" do
19
- expect(subject.instance_variable_get(:@foo)).to eql 1
20
- expect(subject.instance_variable_get(:@bar)).to eql 2
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.5.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-21 00:00:00.000000000 Z
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