superstructure 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/superstructure/value_obj.rb +4 -0
- data/lib/superstructure/version.rb +1 -1
- data/spec/value_obj_spec.rb +28 -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: 1239ae7e3a06bdc1d99dd88f89c9f3b83d433ab3
|
4
|
+
data.tar.gz: 7038285d83163e6ecb8fb3867a82493cf3cc4de2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb73936a4277e49e7401313ade7fad7a1c55353dae25f29713317722029fdbcde58d0404cd09dc249a4c37663f7872081e14399e3aa1b864c69b706daae9195a
|
7
|
+
data.tar.gz: 32c5999efc5fa7005bc4a30ccdfd532f8cde1b950dfac85e6fd78402ac6505d0cb2ecc43986e4e7d1996895d7a0cdc7ce5e397a17bdc8a257b60882fa5e1c5a4
|
@@ -3,6 +3,10 @@ module Superstructure
|
|
3
3
|
class << self
|
4
4
|
def new *arguments, superclass: Object, &blk
|
5
5
|
Class.new(superclass) do
|
6
|
+
define_singleton_method(:with_added_fields) do |*fields|
|
7
|
+
ValueObj.new(*(arguments + fields), superclass: superclass, &blk)
|
8
|
+
end
|
9
|
+
|
6
10
|
define_method(:initialize) do |opts={}|
|
7
11
|
attribute_parser = AttributeParser.new(arguments, opts)
|
8
12
|
if attribute_parser.error?
|
data/spec/value_obj_spec.rb
CHANGED
@@ -172,4 +172,32 @@ RSpec.describe Superstructure::ValueObj do
|
|
172
172
|
end.not_to change { Symbol.all_symbols.size }
|
173
173
|
end
|
174
174
|
end
|
175
|
+
|
176
|
+
describe "creating another structure with additional fields" do
|
177
|
+
it 'walks along the happy path joyously' do
|
178
|
+
Kitten = Superstructure::ValueObj.new(:breed)
|
179
|
+
Yolokitten = Kitten.with_added_fields(:rainbows)
|
180
|
+
yolokitten = Yolokitten.new(breed: 'tabby', rainbows: ['ROY', 'G', 'BIV'])
|
181
|
+
expect(yolokitten.rainbows).to eq ['ROY', 'G', 'BIV']
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'stays classy' do
|
185
|
+
class Actor
|
186
|
+
def act
|
187
|
+
"Once upon a time!"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
Superstar = Superstructure::ValueObj.new(:catch_phrase, superclass: Actor) do
|
192
|
+
def sing
|
193
|
+
"Wahoo wahoo"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
Hyperstar = Superstar.with_added_fields(:hype)
|
197
|
+
|
198
|
+
biebs = Hyperstar.new(catch_phrase: "I'm sorry", hype: "Totally")
|
199
|
+
expect(biebs.act).to eq("Once upon a time!")
|
200
|
+
expect(biebs.sing).to eq("Wahoo wahoo")
|
201
|
+
end
|
202
|
+
end
|
175
203
|
end
|