super_struct 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 858dfb69885a2c237749fccd4b4baea129406d45
4
- data.tar.gz: 18b2e17b26d666a68be9474cf6d3d271f264034d
3
+ metadata.gz: e828a1d5d4b44e8871df9d42113a60f4c7e2efd2
4
+ data.tar.gz: f87691e91a80444b8538b7f93eb0e66dc6f753cd
5
5
  SHA512:
6
- metadata.gz: feaf73a92d3873d7ceedd720ae5fb1ae5dfc7d4a1e4ca23a2478c51e056c00d0835e31b6465bb7d26cda91027fe69ee6fffdd42821aeef4ca102208f52de6821
7
- data.tar.gz: cfdf802e48de761ecba5854359c5cebb9b84e7aad052697d0bc58ce933a1484b2af875773a0dfcd2f70555545c211b1a78e6906a9a5266b7b254162095fde262
6
+ metadata.gz: 53a6edabef8341451c30f9d33a9b0c0855d20f4ea16518fe1ea6e3827d621ae42e5fa7350a0df9fc536abe8f0d5dc7721a7f2fe60e2c8a011c55f8d8c8aa9b22
7
+ data.tar.gz: 296fd4b9114b66769babcbbc424a9083d114b024e35c0bb7a0f0a72446af45e07c652b9e71212be5347a51e554385f65738abb57dd2f0bf0ce76a267cb021834
@@ -1,3 +1,3 @@
1
1
  module SuperStruct
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/super_struct.rb CHANGED
@@ -28,18 +28,23 @@ module SuperStruct
28
28
  self[member].deep_convert!
29
29
  end
30
30
  end
31
+ self
32
+ end
33
+
34
+ def ==(other)
35
+ other.respond_to?(:attributes) && attributes == other.attributes
31
36
  end
32
37
  end
33
38
 
34
- def self.new(array_or_hash, &block)
35
- keys = if array_or_hash.respond_to?(:has_key?)
36
- array_or_hash.keys.sort.map(&:to_sym)
39
+ def self.new(*input, &block)
40
+ keys = if input.first.respond_to?(:has_key?)
41
+ input.first.keys.sort.map(&:to_sym)
37
42
  else
38
- array_or_hash.sort.map(&:to_sym)
43
+ input.sort.map(&:to_sym)
39
44
  end
40
45
 
41
46
  Struct.new(*keys, &block).tap do |struct|
42
- struct.send(:include, InstanceMethods)
47
+ struct.send(:include, ::SuperStruct::InstanceMethods)
43
48
  end
44
49
  end
45
50
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SuperStruct do
4
- let(:constructor_input) { { foo: :bar, fiz: :bang } }
4
+ let(:constructor_input) { { foo: { fiz: :bang } } }
5
5
  let(:klass) { SuperStruct.new(constructor_input) }
6
6
  let(:input) { constructor_input }
7
7
  subject { klass.new(input) }
@@ -39,10 +39,10 @@ describe SuperStruct do
39
39
  end
40
40
 
41
41
  describe '#new' do
42
- context 'given multiple arguments as input' do
43
- subject { klass.new(:bar, :bang) }
42
+ context 'given an array as input' do
43
+ subject { ::SuperStruct.new(:foo, :biz).new(:bar, :bang) }
44
44
 
45
- it 'accepts an array as input' do
45
+ it 'uses the array as keys' do
46
46
  expect(subject.foo).to eq :bang
47
47
  end
48
48
  end
@@ -55,18 +55,18 @@ describe SuperStruct do
55
55
  end
56
56
 
57
57
  describe '#deep_convert!' do
58
- let(:input) { { foo: { fiz: :bang } } }
59
- subject { SuperStruct.from_hash(input) }
60
-
61
58
  it 'converts all hashes within itself to SuperStructs' do
62
59
  expect {
63
60
  subject.deep_convert!
64
61
  }.to change {
65
62
  subject.foo
66
63
  }.from(Hash).to(Struct)
67
- #expect(subject.foo).to be_a Hash
68
- #subject.deep_convert!
69
- #expect(subject.foo).to be_a Struct
64
+ end
65
+ end
66
+
67
+ describe '#==' do
68
+ it 'compares with attributes (not class since structs can be anonymous)' do
69
+ expect(subject).to eq klass.new(input)
70
70
  end
71
71
  end
72
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bram Swenson