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 +4 -4
- data/README.md +4 -0
- data/lib/keyword_init.rb +1 -1
- data/lib/keyword_init/version.rb +1 -1
- data/spec/keyword_init_spec.rb +40 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95b96172166acc2c7721716a263919776973ccd5
|
4
|
+
data.tar.gz: ce9102d08be56c16f3113a4d8da24ad662fdcf1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/lib/keyword_init/version.rb
CHANGED
data/spec/keyword_init_spec.rb
CHANGED
@@ -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
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
38
|
+
describe TestKlassWithPublicSetters do
|
39
|
+
it_behaves_like "works"
|
40
|
+
end
|
20
41
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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.
|
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-
|
11
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|