delegate_it 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/delegate_it/main.rb +2 -2
- data/lib/delegate_it/version.rb +1 -1
- data/spec/delegate_it/main_spec.rb +33 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b54e8408c7b5f3f998ddb38bc4cab1e3ed41a323
|
4
|
+
data.tar.gz: 2a48cdc1da2cd8ea2c496a01e2e38c3f3c62ba13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee70d3a7896a7896a7f563a771d297873d6e4d6cb00ebfa140c7e44b33a6cc2c5bcca8eb0cfb39a59475fce13adfa1c70dcc089bbf123b66e1137eb24879f353
|
7
|
+
data.tar.gz: 4ddf92873d71eea10a6a24f9cb56f626a7dca6091a0d3190dbf0f2cd4f8a34a63a21466a4996a44369bb6ad81a85c036132577ac3e53004ba93004b0937f5640
|
data/lib/delegate_it/main.rb
CHANGED
@@ -11,7 +11,7 @@ module DelegateIt
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def method_missing(method, *)
|
14
|
+
def method_missing(method, *args)
|
15
15
|
setting = @@delegated_settings.select do |s|
|
16
16
|
s.name == method
|
17
17
|
end.first
|
@@ -26,7 +26,7 @@ module DelegateIt
|
|
26
26
|
if setting.options[:allow_nil] && !receiver
|
27
27
|
nil
|
28
28
|
else
|
29
|
-
receiver.send(method)
|
29
|
+
receiver.send(method, *args)
|
30
30
|
end
|
31
31
|
else
|
32
32
|
super
|
data/lib/delegate_it/version.rb
CHANGED
@@ -3,17 +3,33 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
class Dummy
|
5
5
|
include DelegateIt
|
6
|
-
delegate :name, to: :name_delegate
|
6
|
+
delegate :name, :surname, to: :name_delegate
|
7
7
|
delegate :hello, to: :no_exist, allow_nil: true
|
8
8
|
delegate :there, to: :there_delegate, allow_nil: true
|
9
|
+
delegate :one, to: :args_delegate
|
10
|
+
delegate :print, to: :args_delegate
|
9
11
|
|
10
12
|
def name_delegate
|
11
|
-
Struct.new(:name).new('name_val')
|
13
|
+
Struct.new(:name, :surname).new('name_val', 'surname_val')
|
12
14
|
end
|
13
15
|
|
14
16
|
def there_delegate
|
15
17
|
Struct.new(:there).new('there_val')
|
16
18
|
end
|
19
|
+
|
20
|
+
def args_delegate
|
21
|
+
dynamic_class = Class.new do
|
22
|
+
def one count
|
23
|
+
('one '* count).strip
|
24
|
+
end
|
25
|
+
|
26
|
+
def print(word, count)
|
27
|
+
((word+' ') * count).strip
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
dynamic_class.new
|
32
|
+
end
|
17
33
|
end
|
18
34
|
|
19
35
|
describe 'DelegateIt' do
|
@@ -22,8 +38,21 @@ describe 'DelegateIt' do
|
|
22
38
|
end
|
23
39
|
|
24
40
|
describe "standard delegation" do
|
25
|
-
|
26
|
-
|
41
|
+
context "without parameters" do
|
42
|
+
it "works" do
|
43
|
+
expect(subject.name).to eq 'name_val'
|
44
|
+
expect(subject.surname).to eq 'surname_val'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with parameters" do
|
49
|
+
it "works with one" do
|
50
|
+
expect(subject.one(3)).to eq 'one one one'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "works with more params" do
|
54
|
+
expect(subject.print('more', 3)).to eq 'more more more'
|
55
|
+
end
|
27
56
|
end
|
28
57
|
end
|
29
58
|
|