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 +4 -4
- data/.travis.yml +0 -1
- data/Gemfile.lock +14 -14
- data/lib/immutable-struct.rb +13 -3
- data/spec/immutable_struct_spec.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfa246553af45d507992e2fbdc6ba2e5306159cc
|
4
|
+
data.tar.gz: 03989eeb4d23aeb1a0fd1c38745191b9275af538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15e9a7c7a40de80ca4b5204b1e3e37e7c60916af8138ed48fd532deb03924d5f50307f39f7cc0f681e13484fa5c077d307faaa506f9949f78d56680a529f824f
|
7
|
+
data.tar.gz: 239e4695f40c61705bdff234e3eeabe1ad6ad98278dd5542ddc157f2e70b4870c90ccd1f70b7c9a95783195eec5964677f818760e53947bbe566bc7280421295
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
immutable-struct (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 (
|
11
|
-
rspec (3.
|
12
|
-
rspec-core (~> 3.
|
13
|
-
rspec-expectations (~> 3.
|
14
|
-
rspec-mocks (~> 3.
|
15
|
-
rspec-core (3.
|
16
|
-
rspec-support (~> 3.
|
17
|
-
rspec-expectations (3.
|
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.
|
20
|
-
rspec-mocks (3.
|
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.
|
23
|
-
rspec-support (3.
|
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.
|
35
|
+
1.14.6
|
data/lib/immutable-struct.rb
CHANGED
@@ -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.
|
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?
|
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
|
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, :
|
196
|
-
klass_2 = ImmutableStruct.new(:foo, :
|
197
|
-
@k1_a = klass_1.new(foo: 'foo',
|
198
|
-
@k1_b = klass_1.new(foo: 'xxx',
|
199
|
-
@k1_c = klass_1.new(foo: 'foo',
|
200
|
-
@k2_a = klass_2.new(foo: 'foo',
|
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.
|
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:
|
13
|
+
date: 2017-05-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|