immutable-struct 2.2.0 → 2.2.1
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 +4 -4
- data/.gitignore +0 -1
- data/Gemfile.lock +35 -0
- data/lib/immutable-struct.rb +3 -2
- data/spec/immutable_struct_spec.rb +14 -5
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08fb6160fb58ba3ab29f75f41a166a0a93332410
|
4
|
+
data.tar.gz: f9f956a1e7da833ff74758111f12f4c5742fa5dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 376b0a0c7b46858f974bd18563abdf5e20bf429847ea22cbfe0c88e310f446cfc79a4a5b24fc9cbf1371c86721c043cd4fa351177e7c3e8bd7c0e3a681207ffe
|
7
|
+
data.tar.gz: 2226048c79444ae2c8da4d4e7b83b8f07e87c4b024bd154e03eae7115537d9f55ad4a3a5e1b48b476af067a0bb4b289de7d294f53f208b642af5891bdb7322ee
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
immutable-struct (2.2.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
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.1)
|
16
|
+
rspec-support (~> 3.4.0)
|
17
|
+
rspec-expectations (3.4.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.4.0)
|
20
|
+
rspec-mocks (3.4.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.4.0)
|
23
|
+
rspec-support (3.4.1)
|
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.10.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.1' #: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.
|
@@ -65,7 +65,8 @@ class ImmutableStruct
|
|
65
65
|
instance_variable_set("@#{ivar_name}", (attrs[ivar_name.to_s] || attrs[ivar_name.to_sym]).to_a)
|
66
66
|
else
|
67
67
|
ivar_name = attribute.to_s.gsub(/\?$/,'')
|
68
|
-
|
68
|
+
attr_value = attrs[ivar_name.to_s].nil? ? attrs[ivar_name.to_sym] : attrs[ivar_name.to_s]
|
69
|
+
instance_variable_set("@#{ivar_name}", attr_value)
|
69
70
|
end
|
70
71
|
end
|
71
72
|
end
|
@@ -23,11 +23,21 @@ describe ImmutableStruct do
|
|
23
23
|
it { should_not respond_to(:baz?) }
|
24
24
|
|
25
25
|
context "instances can be created with a hash" do
|
26
|
-
subject { @klass.new(foo: "FOO", bar: 42, baz: [:a,:b,:c]) }
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
context 'with symbol keys' do
|
28
|
+
subject { @klass.new(foo: "FOO", bar: 42, baz: [:a,:b,:c]) }
|
29
|
+
|
30
|
+
it { subject.foo.should == "FOO" }
|
31
|
+
it { subject.bar.should == 42 }
|
32
|
+
it { subject.baz.should == [:a,:b,:c] }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with string keys" do
|
36
|
+
subject { ImmutableStruct.new(:foo) }
|
37
|
+
|
38
|
+
it { subject.new('foo' => true).foo.should == true }
|
39
|
+
it { subject.new('foo' => false).foo.should == false }
|
40
|
+
end
|
31
41
|
end
|
32
42
|
end
|
33
43
|
|
@@ -50,7 +60,6 @@ describe ImmutableStruct do
|
|
50
60
|
it { subject.new(foo: "true").foo?.should == true }
|
51
61
|
it { subject.new(foo: "true").foo.should == "true" }
|
52
62
|
end
|
53
|
-
|
54
63
|
end
|
55
64
|
|
56
65
|
context "allows for values that should be coerced to collections" 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.1
|
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-01-
|
13
|
+
date: 2016-01-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- CODE_OF_CONDUCT.md
|
72
72
|
- CONTRIBUTING.md
|
73
73
|
- Gemfile
|
74
|
+
- Gemfile.lock
|
74
75
|
- LICENSE.txt
|
75
76
|
- README.rdoc
|
76
77
|
- Rakefile
|
@@ -98,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
99
|
version: '0'
|
99
100
|
requirements: []
|
100
101
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.4.
|
102
|
+
rubygems_version: 2.4.5
|
102
103
|
signing_key:
|
103
104
|
specification_version: 4
|
104
105
|
summary: Easily create value objects without the pain of Ruby's Struct (or its setters)
|