immutable-struct 2.3.0 → 2.4.0
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 +5 -5
- data/.circleci/config.yml +64 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +3 -4
- data/README.rdoc +12 -2
- data/build-matrix.json +4 -0
- data/immutable-struct.gemspec +2 -1
- data/lib/immutable-struct.rb +10 -1
- data/owners.json +7 -0
- data/spec/immutable_struct_spec.rb +81 -85
- data/spec/spec_helper.rb +1 -1
- metadata +22 -7
- data/Gemfile.lock +0 -35
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 79b8217337e96a8a7514ea7cfef14f75176fe8468dd552d0c523f934483d5080
|
|
4
|
+
data.tar.gz: b7517bc4e1ae43423a4483d2fa42a4913710453fc00a17cab37bc78ee6b83d33
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dba93bcdabd6fdcaaa137ad6c3b20ab379ecc64128aa19f5ae796e13ef9d04d0a66c9fa2becef11bbee15488793b7ebad3c8c42047f541b1226284ff02f78c44
|
|
7
|
+
data.tar.gz: 1478ce402dea03830755e8b28393683c7da8a308247c7db39d0856c0eb95e4e56276fc3926ab3b469bf9a4a4f07b9435951535b3e91498e6a0f1960714e5c801
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# DO NOT MODIFY - this is managed by Git Reduce in goro
|
|
2
|
+
#
|
|
3
|
+
---
|
|
4
|
+
version: 2
|
|
5
|
+
jobs:
|
|
6
|
+
ruby-2.6.1:
|
|
7
|
+
docker:
|
|
8
|
+
- image: circleci/ruby:2.6.1
|
|
9
|
+
working_directory: "~/immutable-struct"
|
|
10
|
+
steps:
|
|
11
|
+
- checkout
|
|
12
|
+
- run: bundle install --full-index
|
|
13
|
+
- run: bundle exec rspec --format RspecJunitFormatter --out /tmp/test-results/rspec.xml
|
|
14
|
+
--format=doc
|
|
15
|
+
- run:
|
|
16
|
+
name: Run Additional CI Steps
|
|
17
|
+
command: if [ -e bin/additional-ci-steps ]; then bin/additional-ci-steps;
|
|
18
|
+
fi
|
|
19
|
+
- run:
|
|
20
|
+
name: Notify Pager Duty
|
|
21
|
+
command: 'bundle exec y-notify #eng-platform'
|
|
22
|
+
when: on_fail
|
|
23
|
+
- store_test_results:
|
|
24
|
+
path: "/tmp/test-results"
|
|
25
|
+
ruby-2.5.3:
|
|
26
|
+
docker:
|
|
27
|
+
- image: circleci/ruby:2.5.3
|
|
28
|
+
working_directory: "~/immutable-struct"
|
|
29
|
+
steps:
|
|
30
|
+
- checkout
|
|
31
|
+
- run: bundle install --full-index
|
|
32
|
+
- run: bundle exec rspec --format RspecJunitFormatter --out /tmp/test-results/rspec.xml
|
|
33
|
+
--format=doc
|
|
34
|
+
- run:
|
|
35
|
+
name: Run Additional CI Steps
|
|
36
|
+
command: if [ -e bin/additional-ci-steps ]; then bin/additional-ci-steps;
|
|
37
|
+
fi
|
|
38
|
+
- run:
|
|
39
|
+
name: Notify Pager Duty
|
|
40
|
+
command: 'bundle exec y-notify #eng-platform'
|
|
41
|
+
when: on_fail
|
|
42
|
+
- store_test_results:
|
|
43
|
+
path: "/tmp/test-results"
|
|
44
|
+
workflows:
|
|
45
|
+
version: 2
|
|
46
|
+
on-commit:
|
|
47
|
+
jobs:
|
|
48
|
+
- ruby-2.6.1:
|
|
49
|
+
context: org-global
|
|
50
|
+
- ruby-2.5.3:
|
|
51
|
+
context: org-global
|
|
52
|
+
scheduled:
|
|
53
|
+
triggers:
|
|
54
|
+
- schedule:
|
|
55
|
+
cron: 4 21 * * 1,2,3,4,5
|
|
56
|
+
filters:
|
|
57
|
+
branches:
|
|
58
|
+
only:
|
|
59
|
+
- master
|
|
60
|
+
jobs:
|
|
61
|
+
- ruby-2.6.1:
|
|
62
|
+
context: org-global
|
|
63
|
+
- ruby-2.5.3:
|
|
64
|
+
context: org-global
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.5.3
|
data/.travis.yml
CHANGED
data/README.rdoc
CHANGED
|
@@ -56,7 +56,17 @@ If not using bundler, just use RubyGems:
|
|
|
56
56
|
new_person.name # => "Other Dave"
|
|
57
57
|
new_person.age # => 41
|
|
58
58
|
new_person.active? # => true
|
|
59
|
-
|
|
59
|
+
|
|
60
|
+
You can coerce values into struct types by using the +from+ method.
|
|
61
|
+
This is similar to Ruby's conversion functions, e.g. Integer("1").
|
|
62
|
+
|
|
63
|
+
dave = Person.from(p)
|
|
64
|
+
dave.equal?(p) # => true (object equality)
|
|
65
|
+
|
|
66
|
+
daveish = Person.from(dave.to_h)
|
|
67
|
+
daveish.equal?(dave) # => false
|
|
68
|
+
daveish == dave # => true
|
|
69
|
+
|
|
60
70
|
You can treat the interior of the block as a normal class definition with the exception of setting constants.
|
|
61
71
|
Use +const_set+ to scope constants as-expected.
|
|
62
72
|
|
|
@@ -66,7 +76,7 @@ Use +const_set+ to scope constants as-expected.
|
|
|
66
76
|
end
|
|
67
77
|
Point::ZERO # => 0
|
|
68
78
|
::ONE_HUNDRED # => 100
|
|
69
|
-
::ZERO # => NameError: uninitialized constant ZERO
|
|
79
|
+
::ZERO # => NameError: uninitialized constant ZERO
|
|
70
80
|
|
|
71
81
|
|
|
72
82
|
== Links
|
data/build-matrix.json
ADDED
data/immutable-struct.gemspec
CHANGED
|
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
|
|
21
|
-
spec.add_development_dependency "bundler", "
|
|
21
|
+
spec.add_development_dependency "bundler", "> 1.3"
|
|
22
22
|
spec.add_development_dependency "rake"
|
|
23
23
|
spec.add_development_dependency "rspec"
|
|
24
|
+
spec.add_development_dependency('rspec_junit_formatter')
|
|
24
25
|
end
|
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.
|
|
9
|
+
VERSION='2.4.0' #: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.
|
|
@@ -72,6 +72,15 @@ class ImmutableStruct
|
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
define_singleton_method(:from) do |value|
|
|
76
|
+
case value
|
|
77
|
+
when self then value
|
|
78
|
+
when Hash then new(value)
|
|
79
|
+
else
|
|
80
|
+
raise ArgumentError, "cannot coerce #{value.class} #{value.inspect} into #{self}"
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
75
84
|
define_method(:initialize) do |*args|
|
|
76
85
|
attrs = args[0] || {}
|
|
77
86
|
attributes.each do |attribute|
|
data/owners.json
ADDED
|
@@ -13,31 +13,30 @@ describe ImmutableStruct do
|
|
|
13
13
|
end
|
|
14
14
|
subject { @klass.new }
|
|
15
15
|
|
|
16
|
-
it {
|
|
17
|
-
it {
|
|
18
|
-
it {
|
|
19
|
-
it {
|
|
20
|
-
it {
|
|
21
|
-
it {
|
|
22
|
-
it {
|
|
23
|
-
it {
|
|
24
|
-
it {
|
|
16
|
+
it { is_expected.to respond_to(:foo) }
|
|
17
|
+
it { is_expected.to respond_to(:bar) }
|
|
18
|
+
it { is_expected.to respond_to(:baz) }
|
|
19
|
+
it { is_expected.not_to respond_to(:foo=) }
|
|
20
|
+
it { is_expected.not_to respond_to(:bar=) }
|
|
21
|
+
it { is_expected.not_to respond_to(:baz=) }
|
|
22
|
+
it { is_expected.not_to respond_to(:foo?) }
|
|
23
|
+
it { is_expected.not_to respond_to(:bar?) }
|
|
24
|
+
it { is_expected.not_to respond_to(:baz?) }
|
|
25
25
|
|
|
26
26
|
context "instances can be created with a hash" do
|
|
27
|
-
|
|
28
27
|
context 'with symbol keys' do
|
|
29
28
|
subject { @klass.new(foo: "FOO", bar: 42, baz: [:a,:b,:c]) }
|
|
30
29
|
|
|
31
|
-
it { subject.foo.
|
|
32
|
-
it { subject.bar.
|
|
33
|
-
it { subject.baz.
|
|
30
|
+
it { expect(subject.foo).to eq("FOO") }
|
|
31
|
+
it { expect(subject.bar).to eq(42) }
|
|
32
|
+
it { expect(subject.baz).to eq([:a,:b,:c]) }
|
|
34
33
|
end
|
|
35
34
|
|
|
36
35
|
context "with string keys" do
|
|
37
36
|
subject { ImmutableStruct.new(:foo) }
|
|
38
37
|
|
|
39
|
-
it { subject.new('foo' => true).foo.
|
|
40
|
-
it { subject.new('foo' => false).foo.
|
|
38
|
+
it { expect(subject.new('foo' => true).foo).to eq(true) }
|
|
39
|
+
it { expect(subject.new('foo' => false).foo).to eq(false) }
|
|
41
40
|
end
|
|
42
41
|
end
|
|
43
42
|
end
|
|
@@ -46,20 +45,20 @@ describe ImmutableStruct do
|
|
|
46
45
|
subject { ImmutableStruct.new(:foo?) }
|
|
47
46
|
|
|
48
47
|
context "with boolean values" do
|
|
49
|
-
it { subject.new(foo: false).foo
|
|
50
|
-
it { subject.new(foo: false).foo.
|
|
51
|
-
it { subject.new(foo: true).foo
|
|
52
|
-
it { subject.new(foo: true).foo.
|
|
48
|
+
it { expect(subject.new(foo: false).foo?).to eq(false) }
|
|
49
|
+
it { expect(subject.new(foo: false).foo).to eq(false) }
|
|
50
|
+
it { expect(subject.new(foo: true).foo?).to eq(true) }
|
|
51
|
+
it { expect(subject.new(foo: true).foo).to eq(true) }
|
|
53
52
|
end
|
|
54
53
|
|
|
55
54
|
context "with falsey, non-boolean values" do
|
|
56
|
-
it { subject.new.foo
|
|
57
|
-
it { subject.new.foo.
|
|
55
|
+
it { expect(subject.new.foo?).to eq(false) }
|
|
56
|
+
it { expect(subject.new.foo).to eq(nil) }
|
|
58
57
|
end
|
|
59
58
|
|
|
60
59
|
context "with truthy, non-boolean values" do
|
|
61
|
-
it { subject.new(foo: "true").foo
|
|
62
|
-
it { subject.new(foo: "true").foo.
|
|
60
|
+
it { expect(subject.new(foo: "true").foo?).to eq(true) }
|
|
61
|
+
it { expect(subject.new(foo: "true").foo).to eq("true") }
|
|
63
62
|
end
|
|
64
63
|
end
|
|
65
64
|
|
|
@@ -67,8 +66,8 @@ describe ImmutableStruct do
|
|
|
67
66
|
it "can define an array value that should never be nil" do
|
|
68
67
|
klass = ImmutableStruct.new([:foo], :bar)
|
|
69
68
|
instance = klass.new
|
|
70
|
-
instance.foo.
|
|
71
|
-
instance.bar.
|
|
69
|
+
expect(instance.foo).to eq([])
|
|
70
|
+
expect(instance.bar).to eq(nil)
|
|
72
71
|
end
|
|
73
72
|
end
|
|
74
73
|
|
|
@@ -77,7 +76,7 @@ describe ImmutableStruct do
|
|
|
77
76
|
def derived; self.foo + ":" + self.bar; end
|
|
78
77
|
end
|
|
79
78
|
instance = klass.new(foo: "hello", bar: "world")
|
|
80
|
-
instance.derived.
|
|
79
|
+
expect(instance.derived).to eq("hello:world")
|
|
81
80
|
end
|
|
82
81
|
|
|
83
82
|
it "allows defining class methods" do
|
|
@@ -87,8 +86,8 @@ describe ImmutableStruct do
|
|
|
87
86
|
end
|
|
88
87
|
end
|
|
89
88
|
instance = klass.from_array(["hello","world"])
|
|
90
|
-
instance.foo.
|
|
91
|
-
instance.bar.
|
|
89
|
+
expect(instance.foo).to eq("hello")
|
|
90
|
+
expect(instance.bar).to eq("world")
|
|
92
91
|
end
|
|
93
92
|
|
|
94
93
|
it "allows module inclusion" do
|
|
@@ -97,8 +96,8 @@ describe ImmutableStruct do
|
|
|
97
96
|
end
|
|
98
97
|
instance = klass.new
|
|
99
98
|
|
|
100
|
-
instance.
|
|
101
|
-
klass.
|
|
99
|
+
expect(instance).to respond_to(:hello)
|
|
100
|
+
expect(klass).not_to respond_to(:hello)
|
|
102
101
|
end
|
|
103
102
|
|
|
104
103
|
it "allows module extension" do
|
|
@@ -107,8 +106,28 @@ describe ImmutableStruct do
|
|
|
107
106
|
end
|
|
108
107
|
instance = klass.new
|
|
109
108
|
|
|
110
|
-
instance.
|
|
111
|
-
klass.
|
|
109
|
+
expect(instance).not_to respond_to(:hello)
|
|
110
|
+
expect(klass).to respond_to(:hello)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
describe "coercion" do
|
|
115
|
+
let(:klass) { ImmutableStruct.new(:lolwat) }
|
|
116
|
+
|
|
117
|
+
it "is a noop when value is already the defined type" do
|
|
118
|
+
value = klass.new
|
|
119
|
+
new_value = klass.from(value)
|
|
120
|
+
expect(new_value).to be(value)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "initializes a new value when Hash is given" do
|
|
124
|
+
value = klass.from(lolwat: "haha")
|
|
125
|
+
expect(value.lolwat).to eq("haha")
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "errors when value cannot be coerced" do
|
|
129
|
+
expect { klass.from(Object.new) }
|
|
130
|
+
.to raise_error(ArgumentError)
|
|
112
131
|
end
|
|
113
132
|
end
|
|
114
133
|
|
|
@@ -121,16 +140,17 @@ describe ImmutableStruct do
|
|
|
121
140
|
end
|
|
122
141
|
end
|
|
123
142
|
instance = klass.new(name: "Rudy", minor: "ayup", aliases: [ "Rudyard", "Roozoola" ])
|
|
124
|
-
instance.to_h.
|
|
143
|
+
expect(instance.to_h).to eq({
|
|
125
144
|
name: "Rudy",
|
|
126
145
|
minor: "ayup",
|
|
127
146
|
minor?: true,
|
|
128
147
|
location: nil,
|
|
129
148
|
aliases: [ "Rudyard", "Roozoola"],
|
|
130
149
|
nick_name: "bob",
|
|
131
|
-
}
|
|
150
|
+
})
|
|
132
151
|
end
|
|
133
152
|
end
|
|
153
|
+
|
|
134
154
|
context "additional method that takes arguments" do
|
|
135
155
|
it "should not call the additional method" do
|
|
136
156
|
klass = ImmutableStruct.new(:name, :minor?, :location, [:aliases]) do
|
|
@@ -142,16 +162,17 @@ describe ImmutableStruct do
|
|
|
142
162
|
end
|
|
143
163
|
end
|
|
144
164
|
instance = klass.new(name: "Rudy", minor: "ayup", aliases: [ "Rudyard", "Roozoola" ])
|
|
145
|
-
instance.to_h.
|
|
165
|
+
expect(instance.to_h).to eq({
|
|
146
166
|
name: "Rudy",
|
|
147
167
|
minor: "ayup",
|
|
148
168
|
minor?: true,
|
|
149
169
|
location: nil,
|
|
150
170
|
aliases: [ "Rudyard", "Roozoola"],
|
|
151
171
|
nick_name: "bob",
|
|
152
|
-
}
|
|
172
|
+
})
|
|
153
173
|
end
|
|
154
174
|
end
|
|
175
|
+
|
|
155
176
|
context "to_hash is its alias" do
|
|
156
177
|
it "is identical" do
|
|
157
178
|
klass = ImmutableStruct.new(:name, :minor?, :location, [:aliases]) do
|
|
@@ -163,24 +184,7 @@ describe ImmutableStruct do
|
|
|
163
184
|
end
|
|
164
185
|
end
|
|
165
186
|
instance = klass.new(name: "Rudy", minor: "ayup", aliases: [ "Rudyard", "Roozoola" ])
|
|
166
|
-
instance.to_h.
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
context "no-arg method that uses to_h" do
|
|
171
|
-
it "blows up" do
|
|
172
|
-
klass = ImmutableStruct.new(:name, :minor?, :location, [:aliases]) do
|
|
173
|
-
def nick_name
|
|
174
|
-
'bob'
|
|
175
|
-
end
|
|
176
|
-
def to_json
|
|
177
|
-
to_h.to_json
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
instance = klass.new(name: "Rudy", minor: "ayup", aliases: [ "Rudyard", "Roozoola" ])
|
|
181
|
-
expect {
|
|
182
|
-
instance.to_json.should == instance.to_h.to_json
|
|
183
|
-
}.to raise_error(SystemStackError)
|
|
187
|
+
expect(instance.to_h).to eq(instance.to_hash)
|
|
184
188
|
end
|
|
185
189
|
end
|
|
186
190
|
end
|
|
@@ -191,20 +195,19 @@ describe ImmutableStruct do
|
|
|
191
195
|
instance = klass.new(food: 'hot dogs', butter: true)
|
|
192
196
|
new_instance = instance.merge(snacks: 'candy hot dogs', butter: false)
|
|
193
197
|
|
|
194
|
-
instance.food.
|
|
195
|
-
instance.butter.
|
|
196
|
-
instance.snacks.
|
|
198
|
+
expect(instance.food).to eq('hot dogs')
|
|
199
|
+
expect(instance.butter).to eq(true)
|
|
200
|
+
expect(instance.snacks).to eq(nil)
|
|
197
201
|
|
|
198
|
-
new_instance.food.
|
|
199
|
-
new_instance.snacks.
|
|
200
|
-
new_instance.butter.
|
|
202
|
+
expect(new_instance.food).to eq('hot dogs')
|
|
203
|
+
expect(new_instance.snacks).to eq('candy hot dogs')
|
|
204
|
+
expect(new_instance.butter).to eq(false)
|
|
201
205
|
|
|
202
|
-
new_instance.object_id.
|
|
206
|
+
expect(new_instance.object_id).not_to eq(instance.object_id)
|
|
203
207
|
end
|
|
204
208
|
end
|
|
205
209
|
|
|
206
210
|
describe "equality" do
|
|
207
|
-
|
|
208
211
|
before do
|
|
209
212
|
klass_1 = ImmutableStruct.new(:foo, [:bars])
|
|
210
213
|
klass_2 = ImmutableStruct.new(:foo, [:bars])
|
|
@@ -215,84 +218,77 @@ describe ImmutableStruct do
|
|
|
215
218
|
end
|
|
216
219
|
|
|
217
220
|
describe "==" do
|
|
218
|
-
|
|
219
221
|
it "should be equal to itself" do
|
|
220
|
-
(@k1_a == @k1_a).
|
|
222
|
+
expect(@k1_a == @k1_a).to be true
|
|
221
223
|
end
|
|
222
224
|
|
|
223
225
|
it "should be equal to same class with identical attribute values" do
|
|
224
|
-
(@k1_a == @k1_c).
|
|
226
|
+
expect(@k1_a == @k1_c).to be true
|
|
225
227
|
end
|
|
226
228
|
|
|
227
229
|
it 'should not be equal to same class with different attribute values' do
|
|
228
|
-
(@k1_a == @k1_b).
|
|
230
|
+
expect(@k1_a == @k1_b).to be false
|
|
229
231
|
end
|
|
230
232
|
|
|
231
233
|
it 'should not be equal to different class with identical attribute values' do
|
|
232
|
-
(@k1_a == @k3_a).
|
|
234
|
+
expect(@k1_a == @k3_a).to be false
|
|
233
235
|
end
|
|
234
|
-
|
|
235
236
|
end
|
|
236
237
|
|
|
237
238
|
describe "eql?" do
|
|
238
|
-
|
|
239
239
|
it "should be equal to itself" do
|
|
240
|
-
@k1_a.eql?(@k1_a).
|
|
240
|
+
expect(@k1_a.eql?(@k1_a)).to be true
|
|
241
241
|
end
|
|
242
242
|
|
|
243
243
|
it "should be equal to same class with identical attribute values" do
|
|
244
|
-
@k1_a.eql?(@k1_c).
|
|
244
|
+
expect(@k1_a.eql?(@k1_c)).to be true
|
|
245
245
|
end
|
|
246
246
|
|
|
247
247
|
it 'should not be equal to same class with different attribute values' do
|
|
248
|
-
@k1_a.eql?(@k1_b).
|
|
248
|
+
expect(@k1_a.eql?(@k1_b)).to be false
|
|
249
249
|
end
|
|
250
250
|
|
|
251
251
|
it 'should not be equal to different class with identical attribute values' do
|
|
252
|
-
@k1_a.eql?(@k3_a).
|
|
252
|
+
expect(@k1_a.eql?(@k3_a)).to be false
|
|
253
253
|
end
|
|
254
|
-
|
|
255
254
|
end
|
|
256
255
|
|
|
257
256
|
describe "hash" do
|
|
258
|
-
|
|
259
257
|
it "should have same hash value as itself" do
|
|
260
|
-
@k1_a.hash.eql?(@k1_a.hash).
|
|
258
|
+
expect(@k1_a.hash.eql?(@k1_a.hash)).to be true
|
|
261
259
|
end
|
|
262
260
|
|
|
263
261
|
it "should have same hash value as same class with identical attribute values" do
|
|
264
|
-
@k1_a.hash.eql?(@k1_c.hash).
|
|
262
|
+
expect(@k1_a.hash.eql?(@k1_c.hash)).to be true
|
|
265
263
|
end
|
|
266
264
|
|
|
267
265
|
it 'should not have hash value as same class with different attribute values' do
|
|
268
|
-
@k1_a.hash.eql?(@k1_b.hash).
|
|
266
|
+
expect(@k1_a.hash.eql?(@k1_b.hash)).to be false
|
|
269
267
|
end
|
|
270
268
|
|
|
271
269
|
it 'should not have hash value equal to different class with identical attribute values' do
|
|
272
|
-
@k1_a.hash.eql?(@k3_a.hash).
|
|
270
|
+
expect(@k1_a.hash.eql?(@k3_a.hash)).to be false
|
|
273
271
|
end
|
|
274
272
|
|
|
275
273
|
it 'should reject set addition if same instance is already a member' do
|
|
276
274
|
set = Set.new([@k1_a])
|
|
277
|
-
set.add?(@k1_a).
|
|
275
|
+
expect(set.add?(@k1_a)).to be nil
|
|
278
276
|
end
|
|
279
277
|
|
|
280
278
|
it 'should reject set addition if different instance, but attributes are the same' do
|
|
281
279
|
set = Set.new([@k1_a])
|
|
282
|
-
set.add?(@k1_c).
|
|
280
|
+
expect(set.add?(@k1_c)).to be nil
|
|
283
281
|
end
|
|
284
282
|
|
|
285
283
|
it 'should allow set addition if different instance and attribute values' do
|
|
286
284
|
set = Set.new([@k1_a])
|
|
287
|
-
set.add?(@k1_b).
|
|
285
|
+
expect(set.add?(@k1_b)).not_to be nil
|
|
288
286
|
end
|
|
289
287
|
|
|
290
288
|
it 'should allow set addition if different class' do
|
|
291
289
|
set = Set.new([@k1_a])
|
|
292
|
-
set.add?(@k2_a).
|
|
290
|
+
expect(set.add?(@k2_a)).not_to be nil
|
|
293
291
|
end
|
|
294
|
-
|
|
295
292
|
end
|
|
296
|
-
|
|
297
293
|
end
|
|
298
294
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
|
4
|
+
version: 2.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stitch Fix Engineering
|
|
@@ -10,20 +10,20 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2019-03-20 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: bundler
|
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
|
18
18
|
requirements:
|
|
19
|
-
- - "
|
|
19
|
+
- - ">"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
21
|
version: '1.3'
|
|
22
22
|
type: :development
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
25
|
requirements:
|
|
26
|
-
- - "
|
|
26
|
+
- - ">"
|
|
27
27
|
- !ruby/object:Gem::Version
|
|
28
28
|
version: '1.3'
|
|
29
29
|
- !ruby/object:Gem::Dependency
|
|
@@ -54,6 +54,20 @@ dependencies:
|
|
|
54
54
|
- - ">="
|
|
55
55
|
- !ruby/object:Gem::Version
|
|
56
56
|
version: '0'
|
|
57
|
+
- !ruby/object:Gem::Dependency
|
|
58
|
+
name: rspec_junit_formatter
|
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '0'
|
|
64
|
+
type: :development
|
|
65
|
+
prerelease: false
|
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
57
71
|
description: Easily create value objects without the pain of Ruby's Struct (or its
|
|
58
72
|
setters)
|
|
59
73
|
email:
|
|
@@ -64,6 +78,7 @@ executables: []
|
|
|
64
78
|
extensions: []
|
|
65
79
|
extra_rdoc_files: []
|
|
66
80
|
files:
|
|
81
|
+
- ".circleci/config.yml"
|
|
67
82
|
- ".gitignore"
|
|
68
83
|
- ".ruby-gemset"
|
|
69
84
|
- ".ruby-version"
|
|
@@ -71,12 +86,13 @@ files:
|
|
|
71
86
|
- CODE_OF_CONDUCT.md
|
|
72
87
|
- CONTRIBUTING.md
|
|
73
88
|
- Gemfile
|
|
74
|
-
- Gemfile.lock
|
|
75
89
|
- LICENSE.txt
|
|
76
90
|
- README.rdoc
|
|
77
91
|
- Rakefile
|
|
92
|
+
- build-matrix.json
|
|
78
93
|
- immutable-struct.gemspec
|
|
79
94
|
- lib/immutable-struct.rb
|
|
95
|
+
- owners.json
|
|
80
96
|
- spec/immutable_struct_spec.rb
|
|
81
97
|
- spec/spec_helper.rb
|
|
82
98
|
homepage: https://github.com/stitchfix/immutable-struct
|
|
@@ -98,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
98
114
|
- !ruby/object:Gem::Version
|
|
99
115
|
version: '0'
|
|
100
116
|
requirements: []
|
|
101
|
-
|
|
102
|
-
rubygems_version: 2.4.5
|
|
117
|
+
rubygems_version: 3.0.1
|
|
103
118
|
signing_key:
|
|
104
119
|
specification_version: 4
|
|
105
120
|
summary: Easily create value objects without the pain of Ruby's Struct (or its setters)
|
data/Gemfile.lock
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
immutable-struct (2.3.0)
|
|
5
|
-
|
|
6
|
-
GEM
|
|
7
|
-
remote: https://rubygems.org/
|
|
8
|
-
specs:
|
|
9
|
-
diff-lcs (1.2.5)
|
|
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
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
19
|
-
rspec-support (~> 3.5.0)
|
|
20
|
-
rspec-mocks (3.5.0)
|
|
21
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
22
|
-
rspec-support (~> 3.5.0)
|
|
23
|
-
rspec-support (3.5.0)
|
|
24
|
-
|
|
25
|
-
PLATFORMS
|
|
26
|
-
ruby
|
|
27
|
-
|
|
28
|
-
DEPENDENCIES
|
|
29
|
-
bundler (~> 1.3)
|
|
30
|
-
immutable-struct!
|
|
31
|
-
rake
|
|
32
|
-
rspec
|
|
33
|
-
|
|
34
|
-
BUNDLED WITH
|
|
35
|
-
1.14.6
|