constructable 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/constructable.gemspec +1 -1
- data/lib/constructable/core_ext.rb +10 -2
- data/test/constructable/test_constructor.rb +27 -5
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/constructable.gemspec
CHANGED
@@ -40,9 +40,17 @@ module Constructable
|
|
40
40
|
when Class
|
41
41
|
@constructor.redefine_new(self)
|
42
42
|
when Module
|
43
|
-
|
44
|
-
|
43
|
+
redefine_new_logic = proc do |base|
|
44
|
+
|
45
|
+
base.instance_variable_set(:@constructor, @constructor)
|
46
|
+
if Class == base.class
|
47
|
+
@constructor.redefine_new(base)
|
48
|
+
elsif Module == base.class
|
49
|
+
base.define_singleton_method :included, &redefine_new_logic
|
50
|
+
end
|
45
51
|
end
|
52
|
+
|
53
|
+
define_singleton_method :included, &redefine_new_logic
|
46
54
|
end
|
47
55
|
return nil
|
48
56
|
end
|
@@ -69,6 +69,7 @@ describe 'Constructor' do
|
|
69
69
|
instance.integer = 5
|
70
70
|
assert_equal 1, instance.integer
|
71
71
|
end
|
72
|
+
|
72
73
|
end
|
73
74
|
|
74
75
|
describe 'allows to super to the generated method' do
|
@@ -124,17 +125,38 @@ describe 'Constructor' do
|
|
124
125
|
|
125
126
|
describe 'module support' do
|
126
127
|
before do
|
127
|
-
|
128
|
+
@foo = Module.new do
|
128
129
|
constructable [:foo, readable: true]
|
129
130
|
end
|
130
131
|
end
|
131
132
|
|
132
133
|
it 'allows cosntructing classes after including the module' do
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
bar =
|
134
|
+
@bar = Class.new
|
135
|
+
@bar.send :include, @foo
|
136
|
+
|
137
|
+
bar = @bar.new(foo: 'foo')
|
137
138
|
assert_equal 'foo', bar.foo
|
138
139
|
end
|
140
|
+
|
141
|
+
describe 'shared setup' do
|
142
|
+
|
143
|
+
before do
|
144
|
+
@bar = Module.new
|
145
|
+
@bar.send :include, @foo
|
146
|
+
|
147
|
+
@baz = Class.new
|
148
|
+
@baz.send :include, @bar
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'works for multiple inclusion' do
|
152
|
+
baz = @baz.new(foo: 'foo')
|
153
|
+
assert_equal 'foo', baz.foo
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'always sets the @constructor ivar' do
|
157
|
+
assert_equal @foo.instance_variable_get(:@constructor), @baz.instance_variable_get(:@constructor)
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
139
161
|
end
|
140
162
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: constructable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Manuel Korfmann
|
@@ -103,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
103
103
|
requirements:
|
104
104
|
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
hash:
|
106
|
+
hash: 2398714721687136545
|
107
107
|
segments:
|
108
108
|
- 0
|
109
109
|
version: "0"
|