smart_init 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/smart_init/main.rb +0 -3
- data/lib/smart_init/version.rb +1 -1
- data/test/test_smart_init.rb +13 -0
- 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: 1446b96b76289a0090e6db9d241ecb6e7b5de6db
|
4
|
+
data.tar.gz: 94a722499a830e6c2801672bab387f5398d99572
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7d717a769b6ef64d4f40a45de80641c5118f913707abcec203bb715bb455a05aba094984dcafeb08e4d36bfdb87b6274aa88a241f6265fb16ceb23c68a8adfc
|
7
|
+
data.tar.gz: 63c1b848ab85ddcf6f3f8e3ad38258771a23e5c163f41530ffcf7378b45ae76b5ded98753d4fedee3a3c33157e31376b678a2083706fe71c207c6949f66c6158
|
data/lib/smart_init/main.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
module SmartInit
|
2
|
-
@@_init_attributes = []
|
3
|
-
|
4
2
|
def is_callable
|
5
3
|
define_singleton_method :call do |*parameters|
|
6
4
|
new(*parameters).call
|
@@ -8,7 +6,6 @@ module SmartInit
|
|
8
6
|
end
|
9
7
|
|
10
8
|
def initialize_with *attributes
|
11
|
-
@_init_attributes = attributes
|
12
9
|
define_method :initialize do |*parameters|
|
13
10
|
if attributes.count != parameters.count
|
14
11
|
raise ArgumentError, "wrong number of arguments (given #{parameters.count}, expected #{attributes.count})"
|
data/lib/smart_init/version.rb
CHANGED
data/test/test_smart_init.rb
CHANGED
@@ -11,6 +11,15 @@ class TestClass
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
class TestNoInit
|
15
|
+
extend SmartInit
|
16
|
+
is_callable
|
17
|
+
|
18
|
+
def call
|
19
|
+
'result'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
14
23
|
class SmartInitTest < Test::Unit::TestCase
|
15
24
|
def test_number_of_attributes
|
16
25
|
assert_nothing_raised do
|
@@ -43,6 +52,10 @@ class SmartInitTest < Test::Unit::TestCase
|
|
43
52
|
assert_equal TestClass.call("a", "b"), ["a", "b"]
|
44
53
|
end
|
45
54
|
|
55
|
+
def test_is_callable_no_initializers
|
56
|
+
assert_equal TestNoInit.call, 'result'
|
57
|
+
end
|
58
|
+
|
46
59
|
private
|
47
60
|
|
48
61
|
def test_object
|