keyword_init 1.1.0 → 1.2.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: 4ce5471a2dcfaadd622edfee5299883840cc3bfa
4
- data.tar.gz: 34c81e38eb6c20b85c6d6541818592e53623f3f2
3
+ metadata.gz: 95b96172166acc2c7721716a263919776973ccd5
4
+ data.tar.gz: ce9102d08be56c16f3113a4d8da24ad662fdcf1f
5
5
  SHA512:
6
- metadata.gz: f9c5e5902f67657b963df8cfd1577c5af1e215574b794770095af7e472474d5ce3173bb9d443eda8824d865c02f8b0bc33164d42ef82b7669773598cf802b978
7
- data.tar.gz: d989acdf4418cef590549e5f6079fa57148c2bf1eabe8c8736ae645ca5762c6be4ecae7bb18e7a6b40ab4c498363811f386389e851d4ddbd439ff6cd2bbe74c8
6
+ metadata.gz: 97608aa77ba8b6e4b08a10c40b836093547d837c5a66028b48fc5ee1a7b57c497d88f44eae17e56b179db03f19d38dd69c0332dd274c283ead65de1474878637
7
+ data.tar.gz: 51f502be344480e61ee8ebfec97070e788cf5b81eac9a37d4999e476b4296ee1f633796208dbedee3e88a3b3c1c3971c866e432210f1f43dc94c9a720398df4f
data/README.md CHANGED
@@ -21,6 +21,10 @@ Or install it yourself as:
21
21
 
22
22
  $ gem install keyword_init
23
23
 
24
+ ## Changelog
25
+
26
+ v1.2.0 => now works with private setters
27
+
24
28
  ## Usage
25
29
 
26
30
  You can have the basic keyword initialization in your class, by including the `KeywordInit` module in your class. This will include the `initialize` method in the class.
data/lib/keyword_init.rb CHANGED
@@ -4,7 +4,7 @@ module KeywordInit
4
4
  def initialize(properties = {})
5
5
  properties.each do |k, v|
6
6
  normal_setter = "#{k}="
7
- send normal_setter, v if respond_to? normal_setter
7
+ send normal_setter, v if respond_to? normal_setter, true
8
8
  end
9
9
  end
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module KeywordInit
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -1,7 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
+ RSpec.shared_examples "works" do
4
+ let(:expected_data) { {:attrib => 1, :writeonly => 2, :readonly => nil} }
5
+
6
+ context 'initialize method' do
7
+ it 'accepts keyword parameters' do
8
+ expect { described_class.new :attrib => 1, :writeonly => 2, :readonly => 3 }.not_to raise_error
9
+ end
10
+
11
+ it 'executes the setter of each recognised keyword' do
12
+ expect_any_instance_of(described_class).to receive(:attrib=).with(1)
13
+ expect_any_instance_of(described_class).to receive(:writeonly=).with(2)
14
+ described_class.new :attrib => 1, :writeonly => 2, :readonly => 3
15
+ end
16
+
17
+ it 'sets the correct values' do
18
+ a = described_class.new :attrib => 1, :writeonly => 2, :readonly => 3
19
+ expect(a.my_data).to eq expected_data
20
+ end
21
+ end
22
+ end
23
+
24
+
3
25
  RSpec.describe KeywordInit do
4
- class TestKlass
26
+ class TestKlassWithPublicSetters
5
27
  include KeywordInit
6
28
 
7
29
  attr_accessor :attrib
@@ -9,19 +31,27 @@ RSpec.describe KeywordInit do
9
31
  attr_reader :readonly
10
32
 
11
33
  def my_data
12
- {:attrib => attrib, :writeonly => writeonly, :readonly => readonly}
34
+ {:attrib => @attrib, :writeonly => @writeonly, :readonly => @readonly}
13
35
  end
14
36
  end
15
37
 
16
- context 'initialize method' do
17
- it 'accepts keyword parameters' do
18
- expect { TestKlass.new :attrib => 1, :writeonly => 2, :readonly => 3 }.not_to raise_error
19
- end
38
+ describe TestKlassWithPublicSetters do
39
+ it_behaves_like "works"
40
+ end
20
41
 
21
- it 'executes the setter of each recognised keyword' do
22
- expect_any_instance_of(TestKlass).to receive(:attrib=).with(1)
23
- expect_any_instance_of(TestKlass).to receive(:writeonly=).with(2)
24
- TestKlass.new :attrib => 1, :writeonly => 2, :readonly => 3
42
+ class TestKlassWithPublicSetters
43
+ include KeywordInit
44
+
45
+ attr_accessor :attrib
46
+ attr_writer :writeonly
47
+ attr_reader :readonly
48
+
49
+ def my_data
50
+ {:attrib => @attrib, :writeonly => @writeonly, :readonly => @readonly}
25
51
  end
26
52
  end
53
+
54
+ describe TestKlassWithPublicSetters do
55
+ it_behaves_like "works"
56
+ end
27
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keyword_init
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-21 00:00:00.000000000 Z
11
+ date: 2014-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler