openhash 0.0.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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +25 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/open_hash.rb +66 -0
- data/openhash.gemspec +30 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ce62159b96a8bf1a4e9858346d62db25bfa36735d07338b31e6f7033397386dd
|
4
|
+
data.tar.gz: '0748023153497b09f2923a17e48b4d1ed7697d14655119ac45ef89eeeeb0524d'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c0751f116ec4d76be10389e35e251fc5a2824f90aa055b97c0b0606900af31d43c4b7e999b26b348dc4bb9b7b03e985c22583ea04f8e286aeb0160c57612405
|
7
|
+
data.tar.gz: e4c3f5fc2b3380b6a33214bfa4a303221dcfff606489e1258442eea9eb34479eef2829a0c202cb0d6a57d0240307982b456392d9a830be276a900c4b50b26972
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
openhash (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.0)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.0)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 2.0)
|
30
|
+
openhash!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Charles Koyeung
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## OpenHash ##
|
2
|
+
|
3
|
+
OpenHash lets Hash called and assigned by the key in chainable way.
|
4
|
+
|
5
|
+
### Installation ###
|
6
|
+
# Manually from RubyGems.org
|
7
|
+
$ gem install openhash
|
8
|
+
|
9
|
+
# Or Gemfile if you are using Bundler
|
10
|
+
$ gem openhash
|
11
|
+
|
12
|
+
### Usage ###
|
13
|
+
```ruby
|
14
|
+
# person = OpenHash.new(name: "John Smith", hometown: { city: "London" })
|
15
|
+
# person.name #=> "John Smith"
|
16
|
+
# person.hometown.country #=> "UK"
|
17
|
+
#
|
18
|
+
# person = OpenHash.new
|
19
|
+
# person.name = "Piter Lee"
|
20
|
+
# person.hometown.city = "Guangzhou"
|
21
|
+
# person.parents.father.name = "Heron Lee"
|
22
|
+
# person #=> { name: "Piter Lee", hometown: { city: "Guangzhou" }, parents: { father: { name: "Heron Lee" } } }
|
23
|
+
```
|
24
|
+
### License ###
|
25
|
+
Released under the [MIT](http://opensource.org/licenses/MIT) license. See LICENSE file for details.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "openhash"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/open_hash.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
# OpenHash lets Hash called and assigned by the key in chainable way.
|
6
|
+
# Example:
|
7
|
+
#
|
8
|
+
# person = OpenHash.new(name: "John Smith", hometown: { city: "London" })
|
9
|
+
# person.name #=> "John Smith"
|
10
|
+
# person.hometown.country #=> "UK"
|
11
|
+
#
|
12
|
+
# person = OpenHash.new
|
13
|
+
# person.name = "Piter Lee"
|
14
|
+
# person.hometown.city = "Guangzhou"
|
15
|
+
# person.parents.father.name = "Heron Lee"
|
16
|
+
# person #=> { name: "Piter Lee", hometown: { city: "Guangzhou" }, parents: { father: { name: "Heron Lee" } } }
|
17
|
+
#
|
18
|
+
class OpenHash < OpenStruct
|
19
|
+
def initialize(hash = {})
|
20
|
+
hash = hash.each_with_object({}) do |(k, v), r|
|
21
|
+
r[k] = v.is_a?(Hash) ? OpenHash.new(v) : v
|
22
|
+
end
|
23
|
+
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
alias inspect to_h
|
28
|
+
|
29
|
+
def method_missing(name, *args) # :nodoc:
|
30
|
+
super || BlackHole.new(self, name)
|
31
|
+
end
|
32
|
+
|
33
|
+
# BlackHole Class
|
34
|
+
class BlackHole < BasicObject
|
35
|
+
def initialize(ohash, *args)
|
36
|
+
@ohash = ohash
|
37
|
+
@chain_methods = args
|
38
|
+
end
|
39
|
+
|
40
|
+
def inspect
|
41
|
+
"nil"
|
42
|
+
end
|
43
|
+
|
44
|
+
# Append a method name to chain methods
|
45
|
+
def <<(method_name)
|
46
|
+
@chain_methods << method_name
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def method_missing(name, *args) # :nodoc:
|
51
|
+
case name
|
52
|
+
when /([^=]+)=\z/
|
53
|
+
last_ohash = @ohash
|
54
|
+
|
55
|
+
@chain_methods.each do |method_name|
|
56
|
+
last_ohash[method_name] = ::OpenHash.new
|
57
|
+
last_ohash = last_ohash[method_name]
|
58
|
+
end
|
59
|
+
|
60
|
+
last_ohash[name] = args[0]
|
61
|
+
else
|
62
|
+
self << name
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/openhash.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "openhash"
|
8
|
+
spec.version = '0.0.1'
|
9
|
+
spec.authors = ["cenxky"]
|
10
|
+
spec.email = ["cenxky@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "OpenHash lets Hash called and assigned by the key in chainable way."
|
13
|
+
spec.description = "OpenHash lets Hash called and assigned by the key in chainable way."
|
14
|
+
spec.homepage = "https://github.com/cenxky/openhash"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openhash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cenxky
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: OpenHash lets Hash called and assigned by the key in chainable way.
|
56
|
+
email:
|
57
|
+
- cenxky@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/open_hash.rb
|
73
|
+
- openhash.gemspec
|
74
|
+
homepage: https://github.com/cenxky/openhash
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.7.6
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: OpenHash lets Hash called and assigned by the key in chainable way.
|
98
|
+
test_files: []
|