immutable-struct 2.2.2 → 2.2.3

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: a9c0a785dd4e418fdae0fe7dfd89f3ceef53077b
4
- data.tar.gz: 4411b12c43b62e461b86489e55cf2d7996e45172
3
+ metadata.gz: dfa246553af45d507992e2fbdc6ba2e5306159cc
4
+ data.tar.gz: 03989eeb4d23aeb1a0fd1c38745191b9275af538
5
5
  SHA512:
6
- metadata.gz: 7c5c10d71cea0da0ae00f11d349a19e3f06557f1cfe80195c9f1131681a3e860ed68c5581a9df8971fe26c0a4b3793f6e75568adf5440eeb8a713121fc48b4c4
7
- data.tar.gz: fe3d852d289626c1314e323b6610558470ad330feadd5b39509141261d80fa5c4a596f61a860ca3d9ffc8752c51f40c3c41c3c66437b774c57bf5bdd43769606
6
+ metadata.gz: 15e9a7c7a40de80ca4b5204b1e3e37e7c60916af8138ed48fd532deb03924d5f50307f39f7cc0f681e13484fa5c077d307faaa506f9949f78d56680a529f824f
7
+ data.tar.gz: 239e4695f40c61705bdff234e3eeabe1ad6ad98278dd5542ddc157f2e70b4870c90ccd1f70b7c9a95783195eec5964677f818760e53947bbe566bc7280421295
@@ -6,5 +6,4 @@ rvm:
6
6
  - 2.0.0
7
7
  - 2.1.0
8
8
  - 2.2.2
9
- - rbx-2
10
9
  - ruby-head
@@ -1,26 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- immutable-struct (2.2.2)
4
+ immutable-struct (2.2.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.2.5)
10
- rake (10.5.0)
11
- rspec (3.4.0)
12
- rspec-core (~> 3.4.0)
13
- rspec-expectations (~> 3.4.0)
14
- rspec-mocks (~> 3.4.0)
15
- rspec-core (3.4.2)
16
- rspec-support (~> 3.4.0)
17
- rspec-expectations (3.4.0)
10
+ rake (11.2.2)
11
+ rspec (3.5.0)
12
+ rspec-core (~> 3.5.0)
13
+ rspec-expectations (~> 3.5.0)
14
+ rspec-mocks (~> 3.5.0)
15
+ rspec-core (3.5.3)
16
+ rspec-support (~> 3.5.0)
17
+ rspec-expectations (3.5.0)
18
18
  diff-lcs (>= 1.2.0, < 2.0)
19
- rspec-support (~> 3.4.0)
20
- rspec-mocks (3.4.1)
19
+ rspec-support (~> 3.5.0)
20
+ rspec-mocks (3.5.0)
21
21
  diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.4.0)
23
- rspec-support (3.4.1)
22
+ rspec-support (~> 3.5.0)
23
+ rspec-support (3.5.0)
24
24
 
25
25
  PLATFORMS
26
26
  ruby
@@ -32,4 +32,4 @@ DEPENDENCIES
32
32
  rspec
33
33
 
34
34
  BUNDLED WITH
35
- 1.10.6
35
+ 1.14.6
@@ -6,7 +6,7 @@
6
6
  # will be evaluated as if it were inside a class definition, allowing you
7
7
  # to add methods, include or extend modules, or do whatever else you want.
8
8
  class ImmutableStruct
9
- VERSION='2.2.2' #:nodoc:
9
+ VERSION='2.2.3' #:nodoc:
10
10
  # Create a new class with the given read-only attributes.
11
11
  #
12
12
  # attributes:: list of symbols or strings that can be used to create attributes.
@@ -88,7 +88,12 @@ class ImmutableStruct
88
88
 
89
89
  define_method(:==) do |other|
90
90
  return false unless other.is_a?(klass)
91
- attributes.all? { |attribute| self.send(attribute) == other.send(attribute) }
91
+ attributes.all? do |attribute|
92
+ if attribute.kind_of?(Array) and attribute.size == 1
93
+ attribute = attribute[0].to_s
94
+ end
95
+ self.send(attribute) == other.send(attribute)
96
+ end
92
97
  end
93
98
 
94
99
  define_method(:merge) do |new_attrs|
@@ -99,7 +104,12 @@ class ImmutableStruct
99
104
  alias_method :eql?, :==
100
105
 
101
106
  define_method(:hash) do
102
- attribute_values = attributes.map { |attr| self.send(attr) }
107
+ attribute_values = attributes.map do |attribute|
108
+ if attribute.kind_of?(Array) and attribute.size == 1
109
+ attribute = attribute[0].to_s
110
+ end
111
+ self.send(attribute)
112
+ end
103
113
  (attribute_values + [self.class]).hash
104
114
  end
105
115
  end
@@ -192,12 +192,12 @@ describe ImmutableStruct do
192
192
  describe "equality" do
193
193
 
194
194
  before do
195
- klass_1 = ImmutableStruct.new(:foo, :bar)
196
- klass_2 = ImmutableStruct.new(:foo, :bar)
197
- @k1_a = klass_1.new(foo: 'foo', bar: 'bar')
198
- @k1_b = klass_1.new(foo: 'xxx', bar: 'yyy')
199
- @k1_c = klass_1.new(foo: 'foo', bar: 'bar')
200
- @k2_a = klass_2.new(foo: 'foo', bar: 'bar')
195
+ klass_1 = ImmutableStruct.new(:foo, [:bars])
196
+ klass_2 = ImmutableStruct.new(:foo, [:bars])
197
+ @k1_a = klass_1.new(foo: 'foo', bars: ['bar', 'baz'])
198
+ @k1_b = klass_1.new(foo: 'xxx', bars: ['yyy'])
199
+ @k1_c = klass_1.new(foo: 'foo', bars: ['bar', 'baz'])
200
+ @k2_a = klass_2.new(foo: 'foo', bars: ['bar'])
201
201
  end
202
202
 
203
203
  describe "==" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immutable-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stitch Fix Engineering
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-02-22 00:00:00.000000000 Z
13
+ date: 2017-05-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler