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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee6898266d56d163225dc8e36a560df58c775ad5
4
- data.tar.gz: 0a54cd4233764e3709894e827a199cb4c6b250a2
3
+ metadata.gz: 1239ae7e3a06bdc1d99dd88f89c9f3b83d433ab3
4
+ data.tar.gz: 7038285d83163e6ecb8fb3867a82493cf3cc4de2
5
5
  SHA512:
6
- metadata.gz: 235118a7fc7df08713a74f8e08ff6fd603f574e73ad1e28af21c25cdd449fa85e5d2a38274efc8c12dd8ae7e87ba1e72eace08ef9a604a9503c6c0192be53edf
7
- data.tar.gz: 820253eeb35ff0c77c0572a9b4132c0c3eb7df7e6e70a6631abb2ebf99823a2834489df12ff3bc06acf5e1f079856228e90ff65516c2601dca782520b9fffbb3
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?
@@ -1,3 +1,3 @@
1
1
  module Superstructure
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superstructure
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Finnie