keyword_init 1.2.0 → 1.3.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 +2 -1
- data/lib/keyword_init.rb +5 -0
- data/lib/keyword_init/version.rb +1 -1
- data/spec/keyword_init_spec.rb +8 -15
- 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: 9644aac7efef035e18f3dcf43ad5845b4c657a18
|
4
|
+
data.tar.gz: d2e47fcbe57dab4d92efa1b5d8b52f6817e59cfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2142e32a648cfaf634c74a4a0a023fe589a8ebd13dbe3f888af0d13c8562737cc22b2c0c5806b0646d9414853f8327ceecd7dffde7f462c1344d1b463d7656cc
|
7
|
+
data.tar.gz: c30d597d6f4d153a5ea700d3cbe6e6638faf9e29924e6913f8379a1eba7ead2b7eb323ff6f7e4dd0ab9534ef0c833818eac1793e72bbbf8a90c84864ba21a112
|
data/README.md
CHANGED
@@ -23,6 +23,7 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
## Changelog
|
25
25
|
|
26
|
+
v1.3.0 => the work is done by a private method `_set_properties` that expects a hash of attributes. This way the work can be performed on an existing instance by calling that private method.
|
26
27
|
v1.2.0 => now works with private setters
|
27
28
|
|
28
29
|
## Usage
|
@@ -62,7 +63,7 @@ x.my_data # => {attrib: 1, writeonly: 2, readonly: nil}
|
|
62
63
|
|
63
64
|
## Contributing
|
64
65
|
|
65
|
-
1. Fork it ( https://github.com/
|
66
|
+
1. Fork it ( https://github.com/eturino/keyword_init/fork )
|
66
67
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
67
68
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
68
69
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/keyword_init.rb
CHANGED
@@ -2,6 +2,11 @@ require "keyword_init/version"
|
|
2
2
|
|
3
3
|
module KeywordInit
|
4
4
|
def initialize(properties = {})
|
5
|
+
_set_properties properties
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
def _set_properties(properties)
|
5
10
|
properties.each do |k, v|
|
6
11
|
normal_setter = "#{k}="
|
7
12
|
send normal_setter, v if respond_to? normal_setter, true
|
data/lib/keyword_init/version.rb
CHANGED
data/spec/keyword_init_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
RSpec.shared_examples "works" do
|
4
4
|
let(:expected_data) { {:attrib => 1, :writeonly => 2, :readonly => nil} }
|
5
5
|
|
6
|
-
context 'initialize method' do
|
6
|
+
context '#initialize method' do
|
7
7
|
it 'accepts keyword parameters' do
|
8
8
|
expect { described_class.new :attrib => 1, :writeonly => 2, :readonly => 3 }.not_to raise_error
|
9
9
|
end
|
@@ -19,26 +19,19 @@ RSpec.shared_examples "works" do
|
|
19
19
|
expect(a.my_data).to eq expected_data
|
20
20
|
end
|
21
21
|
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
RSpec.describe KeywordInit do
|
26
|
-
class TestKlassWithPublicSetters
|
27
|
-
include KeywordInit
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
attr_reader :readonly
|
23
|
+
context '#_set_properties method (private)' do
|
24
|
+
subject { described_class.new }
|
32
25
|
|
33
|
-
|
34
|
-
|
26
|
+
it 'sets the correct values (after creation) in the subject, in the same way of the initialize method' do
|
27
|
+
subject.send :_set_properties, :attrib => 1, :writeonly => 2, :readonly => 3
|
28
|
+
expect(subject.my_data).to eq expected_data
|
35
29
|
end
|
36
30
|
end
|
31
|
+
end
|
37
32
|
|
38
|
-
describe TestKlassWithPublicSetters do
|
39
|
-
it_behaves_like "works"
|
40
|
-
end
|
41
33
|
|
34
|
+
RSpec.describe KeywordInit do
|
42
35
|
class TestKlassWithPublicSetters
|
43
36
|
include KeywordInit
|
44
37
|
|
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.3.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-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|