hash_initialized_struct 1.2.0 → 1.3.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c4c558bba0d06f8eba89b9fc806e943f72048c6
|
4
|
+
data.tar.gz: dd7514bfb90ab42fbcc0dab354d550b7de7be98d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cff409d88d53deff8c4a5b8787ce2673e947fe2abd11b668b7b138aead4a2cf8352bd0280163989d55d5a6bb506f3129b63ad5680cbe06c441fd2e072d3e668
|
7
|
+
data.tar.gz: de20f2146adb828f785a3a2292fb0d26d09619622a5979bb98c1996eac4c5e0686eb6eb37d04e280f5d764867e8a8ef0942d23d027f0882c106e27f76cab73ab
|
data/.travis.yml
CHANGED
@@ -18,6 +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.required_ruby_version = "~> 2.0"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
25
|
spec.add_development_dependency "rspec", "~> 3.2"
|
@@ -41,11 +41,16 @@ describe "HashInitializedStruct" do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
it "provides to_hash for implicit conversions (Ruby 2+)" do
|
44
|
-
skip "Ignoring Ruby 1.9.x..." unless Kernel.respond_to?(:Hash)
|
45
44
|
point = klass.new(x: 1, y: 2)
|
46
45
|
expect(point.to_h).to eq Hash(point) # to_h == to_hash
|
47
46
|
end
|
48
47
|
|
48
|
+
it "casts attributes to Hash" do
|
49
|
+
point = klass.new(x: 1, y: 2)
|
50
|
+
point2 = klass.new(point)
|
51
|
+
expect(point.to_h).to eq point2.to_h
|
52
|
+
end
|
53
|
+
|
49
54
|
describe "overriding the constructor" do
|
50
55
|
it "allows additional checks" do
|
51
56
|
# Could do this with an anonymous class and define_method, but we're trying to emulate
|
@@ -70,13 +75,14 @@ describe "HashInitializedStruct" do
|
|
70
75
|
it "allows partial checks" do
|
71
76
|
class MyOptionally4DPoint < HashInitializedStruct.new(:x, :y, :z, :t)
|
72
77
|
def initialize(attrs)
|
78
|
+
attrs = Hash(attrs)
|
73
79
|
provided = attrs.keys
|
74
80
|
raise_on_unrecognised_keys(provided, needed_keys)
|
75
|
-
set_attributes
|
81
|
+
set_attributes(attrs)
|
76
82
|
end
|
77
83
|
end
|
78
84
|
|
79
|
-
good =
|
85
|
+
good = MyOptionally4DPoint.new(x: 1, y: 2, z: 9) # Missing :t
|
80
86
|
expect(good.x).to eq 1
|
81
87
|
end
|
82
88
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_initialized_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Howard
|
@@ -81,9 +81,9 @@ require_paths:
|
|
81
81
|
- lib
|
82
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- - "
|
84
|
+
- - "~>"
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version: '0'
|
86
|
+
version: '2.0'
|
87
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
89
|
- - ">="
|