openstruct-from_hash.rb 0.3.2 → 0.3.3

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
  SHA256:
3
- metadata.gz: 7b918513414685919dd0cfd9912ba7df354d442bff8362916b2621286d7f2f9e
4
- data.tar.gz: 9448da3b2e76e02336b052c18213bf7aa70ccbf3f72256cd2977f21dd69f42c3
3
+ metadata.gz: acab5b4bc8644f21c1240b529886644a54b70c6922a13e09b4c73d21901791e9
4
+ data.tar.gz: e15db4781da6d1bb2cbbd05ff872e1b703fd6c072604b6bda7a4504f08997fba
5
5
  SHA512:
6
- metadata.gz: e5cc797cadf4e9df79a93ac2f6a3bac472634d8b96a210dde5aa2b7ec931517341658e102a29364f5401dfcafabb4f89979c1e2cb80deb2f9fe7e88f6094c9e6
7
- data.tar.gz: cdbd5e9b6277f8918730fb7f829a7bc3821a75103f5b97301288879fe7107ac3a2c975ca2b0b0b9344f11ae9baf5ff5f4c7536be0360e03bffe9eb2779669705
6
+ metadata.gz: 8ad00f9a336affbea429f99ad62d2a2752ea0cc8c4d2640965cc14836d17efd133460a8ae79e28f2011d4ba161bc401c55ff9cdca0bdaadae1146b168d4c5647
7
+ data.tar.gz: 550e0229a30ecdb801ab70b68326224a8051520ef241c8453ba5bc4ebb80bf0c7b0be1dc82f60092bcf127935f066a5baebc96ec1e4a21b2e385e727a6099018
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
+ Gemfile.lock
1
2
  *.gem
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v0.3.3
4
+
5
+ * Improve `README.md` documentation.
6
+
3
7
  ## v0.3.2
4
8
 
5
9
  * Document `OpenStruct::FromHash::VERSION`.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ group :test do
4
+ gem 'rspec'
5
+ end
data/README.md CHANGED
@@ -13,18 +13,36 @@ constructor for the OpenStruct class that is apart of Ruby's standard library.
13
13
  ## <a id='examples'>Examples</a>
14
14
 
15
15
 
16
+ __1.__
17
+
18
+ Recursively initialize an OpenStruct:
19
+
16
20
  ```ruby
17
21
  require 'ostruct'
18
22
  require 'openstruct-from_hash'
19
23
  obj = OpenStruct.from_hash(
20
24
  str: 'foo',
21
25
  ary: [{ number: 20 }],
22
- person: { name: 'John', age: 21.5, friends: [{name: 'Amy'}] }
26
+ person: { name: 'John', friends: [{name: 'Amy'}] }
23
27
  )
24
28
  obj.str # => 'foo'
25
29
  obj.ary[0].number # => 20
26
30
  obj.person.name # => 'John'
27
- obj.person.age # => 21.5
31
+ obj.person.friends[0].name # => 'Amy'
32
+ ```
33
+
34
+ __2.__
35
+
36
+ Recursively initialize an OpenStruct from a JSON object:
37
+
38
+ ```ruby
39
+ require 'json'
40
+ require 'ostruct'
41
+ require 'openstruct-from_hash'
42
+ json = '{ "ary": [{ "number": 20 }], "person": { "name": "John", "friends": [{ "name": "Amy" }] } }'
43
+ obj = OpenStruct.from_hash JSON.parse(json)
44
+ obj.ary[0].number # => 20
45
+ obj.person.name # => 'John'
28
46
  obj.person.friends[0].name # => 'Amy'
29
47
  ```
30
48
 
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'bundler/gem_tasks'
2
+ desc 'Run the tests.'
2
3
  task :test do
3
- sh 'ruby test/openstruct-from_hash_test.rb'
4
+ sh 'bundle exec rspec'
4
5
  end
5
6
  task default: :test
@@ -4,7 +4,7 @@ class OpenStruct
4
4
  # @return [String]
5
5
  # The current version of openstruct-from_hash.rb
6
6
  #
7
- VERSION = '0.3.2'.freeze
7
+ VERSION = '0.3.3'.freeze
8
8
 
9
9
  #
10
10
  # @example
@@ -0,0 +1,24 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ require 'ostruct'
4
+ require 'openstruct-from_hash'
5
+
6
+ RSpec.describe OpenStruct::FromHash do
7
+ let(:ostruct) do
8
+ OpenStruct.from_hash(
9
+ str: 'foo',
10
+ ary: [{ number: 20 }, BasicObject.new],
11
+ person: { name: 'John', friends: [{ name: 'Amy' }] }
12
+ )
13
+ end
14
+
15
+ describe '#from_hash' do
16
+ it 'recursively initializes an OpenStruct' do
17
+ expect(ostruct.str).to eq('foo')
18
+ expect(ostruct.ary[0].number).to eq(20)
19
+ expect(BasicObject === ostruct.ary[1]).to be(true)
20
+ expect(ostruct.person.name).to eq('John')
21
+ expect(ostruct.person.friends[0].name).to eq('Amy')
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstruct-from_hash.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Gleeson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-01 00:00:00.000000000 Z
11
+ date: 2018-12-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: openstruct-from_hash.rb implements OpenStruct.from_hash(), a recursive
14
14
  constructor for the OpenStruct class that is apart of Ruby's standard library.
@@ -20,12 +20,13 @@ files:
20
20
  - ".gitignore"
21
21
  - ".pryrc"
22
22
  - CHANGELOG.md
23
+ - Gemfile
23
24
  - LICENSE.txt
24
25
  - README.md
25
26
  - Rakefile
26
27
  - lib/openstruct-from_hash.rb
27
28
  - openstruct-from_hash.gemspec
28
- - test/openstruct-from_hash_test.rb
29
+ - spec/openstruct-from_hash_spec.rb
29
30
  homepage: https://github.com/r-obert/openstruct-from_hash.rb
30
31
  licenses:
31
32
  - MIT
@@ -1,20 +0,0 @@
1
- require 'bundler/setup'
2
- require 'ostruct'
3
- require 'openstruct-from_hash'
4
- require 'minitest'
5
- require 'minitest/autorun'
6
-
7
- class OpenStructTest < Minitest::Test
8
- def test_from_hash_1
9
- obj = OpenStruct.from_hash(
10
- str: 'foo',
11
- ary: [{ number: 20 }, BasicObject.new],
12
- person: { name: 'John', friends: [{ name: 'Amy' }] }
13
- )
14
- assert_equal 'foo', obj.str
15
- assert_equal 20, obj.ary[0].number
16
- assert BasicObject === obj.ary[1]
17
- assert_equal 'John', obj.person.name
18
- assert_equal 'Amy', obj.person.friends[0].name
19
- end
20
- end