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: 0a019905cb0578ccd137f19e03bc4506c4394d70
4
- data.tar.gz: d995895f24be535e41f72b7c55d8f074b05dbf66
3
+ metadata.gz: 4c4c558bba0d06f8eba89b9fc806e943f72048c6
4
+ data.tar.gz: dd7514bfb90ab42fbcc0dab354d550b7de7be98d
5
5
  SHA512:
6
- metadata.gz: eaa60f77a463b145fe836d23b06b1953ef64959a99b78e14c603280de7e655b482c5abcca48e2ceb921cd2ed8cae716fbadcc3417c4744426e80fd3b86d1bea8
7
- data.tar.gz: 9c3990737ae43394e9ea0f2d3ea8c7fe186b3165c3718edc3568f894d3cae8a5517cdc000cf4a230610b34c97cf5bfeadf308d11232ed5c274cd4ba271271a4b
6
+ metadata.gz: 4cff409d88d53deff8c4a5b8787ce2673e947fe2abd11b668b7b138aead4a2cf8352bd0280163989d55d5a6bb506f3129b63ad5680cbe06c441fd2e072d3e668
7
+ data.tar.gz: de20f2146adb828f785a3a2292fb0d26d09619622a5979bb98c1996eac4c5e0686eb6eb37d04e280f5d764867e8a8ef0942d23d027f0882c106e27f76cab73ab
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
4
  - 2.1.0
6
5
  - 2.2.0
@@ -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"
@@ -34,6 +34,7 @@ class HashInitializedStruct
34
34
  end
35
35
 
36
36
  def initialize(attrs)
37
+ attrs = Hash(attrs)
37
38
  provided = attrs.keys
38
39
  needed = needed_keys
39
40
  self.raise_on_unrecognised_keys(provided, needed)
@@ -1,3 +1,3 @@
1
1
  class HashInitializedStruct
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -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 = My3DPoint.new(x: 1, y: 2, z: 9) # Missing :t
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.2.0
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
  - - ">="