openstruct-from_hash 0.1.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 +7 -0
- data/.pryrc +1 -0
- data/README.md +46 -0
- data/Rakefile +4 -0
- data/lib/openstruct-from_hash.rb +8 -0
- data/openstruct-from_hash.gemspec +10 -0
- data/test/openstruct-from_hash_test.rb +28 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fe6ddf9032cfb9a1bc07a032897663ffede6a793
|
4
|
+
data.tar.gz: ffd122f1e34702a2a9dd56c4ab3938cc0661024e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3525cf3626795d92a0563dc3ce9465014270728ca19cc531b2af2b8f55e8b605ae2abb2e5d8bd9e0b7a6eda40ada7233280b92f41517791dcdeebf4b3bd4c3f2
|
7
|
+
data.tar.gz: 6785be18a9839d927ef8ae089e74021da4664772aea879a640ad12c885940de7c301db543bb8f4b09801186bc677839c5e7784ed3762825a1572800cd1dd3a6b
|
data/.pryrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require './lib/openstruct-from_hash'
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
__openstruct-from_hash.rb__
|
2
|
+
|
3
|
+
Add recursive constructor from_hash to OpenStruct.
|
4
|
+
|
5
|
+
__Examples__
|
6
|
+
|
7
|
+
__1.__
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
s = OpenStruct.from_hash({'one' => {'two' => {'three' => {'four' => 'five'}}}})
|
11
|
+
s.one.two.three.four # => 'five'
|
12
|
+
```
|
13
|
+
|
14
|
+
__Install__
|
15
|
+
|
16
|
+
Rubygems:
|
17
|
+
|
18
|
+
gem install openstruct-from_hash
|
19
|
+
|
20
|
+
|
21
|
+
Bundler:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'openstruct-from_hash', '~> 0.1'
|
25
|
+
```
|
26
|
+
|
27
|
+
__License__
|
28
|
+
|
29
|
+
This is free and unencumbered software released into the public domain.
|
30
|
+
|
31
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
32
|
+
distribute this software, either in source code form or as a compiled
|
33
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
34
|
+
means.
|
35
|
+
|
36
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
37
|
+
of this software dedicate any and all copyright interest in the
|
38
|
+
software to the public domain.
|
39
|
+
|
40
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
41
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
42
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
43
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
44
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
45
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
46
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "openstruct-from_hash"
|
3
|
+
spec.version = "0.1.0"
|
4
|
+
spec.authors = ["jazzonmymind"]
|
5
|
+
spec.email = "robert@jazzonmymind.xyz"
|
6
|
+
spec.files = `git ls-files`.each_line.map(&:chomp)
|
7
|
+
spec.summary = 'Add recursive constructor from_hash to OpenStruct.'
|
8
|
+
spec.description = spec.summary
|
9
|
+
spec.homepage = "https://github.com/jazzonmymind/openstruct-from_hash.rb"
|
10
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative '../lib/openstruct-from_hash'
|
2
|
+
require 'minitest'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
class OpenStructTest < Minitest::Test
|
5
|
+
def test_from_hash_1
|
6
|
+
struct = OpenStruct.from_hash({'foo' => {'bar' => 123}})
|
7
|
+
assert_equal 123, struct.foo.bar
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_from_hash_2
|
11
|
+
struct = OpenStruct.from_hash({'baz' => 32, 'foo' => {'bar' => 123}})
|
12
|
+
assert_equal 123, struct.foo.bar
|
13
|
+
assert_equal 32, struct.baz
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_from_hash_3
|
17
|
+
struct = OpenStruct.from_hash({'foo' => 'abc', 'x' => {'y' => 'z', 'a' => 1}})
|
18
|
+
assert_equal 'abc', struct.foo
|
19
|
+
assert_equal 'z', struct.x.y
|
20
|
+
assert_equal 1, struct.x.a
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_from_hash_4
|
24
|
+
struct = OpenStruct.from_hash({'foo' => {'bar' => {'daz' => {'faz' => "yes" }}}, "defx" => "xyz"})
|
25
|
+
assert_equal "yes", struct.foo.bar.daz.faz
|
26
|
+
assert_equal "xyz", struct.defx
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openstruct-from_hash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jazzonmymind
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Add recursive constructor from_hash to OpenStruct.
|
14
|
+
email: robert@jazzonmymind.xyz
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- ".pryrc"
|
20
|
+
- README.md
|
21
|
+
- Rakefile
|
22
|
+
- lib/openstruct-from_hash.rb
|
23
|
+
- openstruct-from_hash.gemspec
|
24
|
+
- test/openstruct-from_hash_test.rb
|
25
|
+
homepage: https://github.com/jazzonmymind/openstruct-from_hash.rb
|
26
|
+
licenses: []
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.5.1
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Add recursive constructor from_hash to OpenStruct.
|
48
|
+
test_files: []
|