openstruct_utils 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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +1 -0
- data/lib/openstruct_utils/version.rb +3 -0
- data/lib/openstruct_utils.rb +40 -0
- data/openstruct_utils.gemspec +23 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
data.tar.gz: 54469145f4daa7b3e0a8fde3419921a8c03cb129
|
4
|
+
metadata.gz: c05575e6f0ccedda4826e672f47e8cf6cbe74a56
|
5
|
+
SHA512:
|
6
|
+
data.tar.gz: 32915bed64723e0fa5d5c73aa2a00d1de8a0ac79f670bb2fc44271cd075ac7212a7a851779069adbdc2fdd927915078d54cc9e0ed276153fdd797f003828d857
|
7
|
+
metadata.gz: 9b726331d5258f83a9c399433848aa677849055d83219d3052082eb567318e10878ffafeb04190a50a92f742923e3852fe5a0ac51870f00e3e0d810f3743fa35
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 cheyang
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# OpenstructUtils
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'openstruct_utils'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install openstruct_utils
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
struct = OpenStruct.new({:package=>"redis.zip",:knife=>"knife"})
|
22
|
+
|
23
|
+
struct = OpenStruct.new({:a =>[1, 2, 3]})
|
24
|
+
|
25
|
+
struct = OpenStruct.new(:redis=>struct)
|
26
|
+
|
27
|
+
to_hash:
|
28
|
+
puts OpenstructUtils::openstruct_to_hash
|
29
|
+
|
30
|
+
to_json:
|
31
|
+
puts OpenstructUtils::openstruct_to_json struct
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( http://github.com/<my-github-username>/openstruct_utils/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "openstruct_utils/version"
|
2
|
+
require 'json'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module OpenstructUtils
|
6
|
+
def self.openstruct_to_json struct
|
7
|
+
JSON.pretty_generate openstruct_to_hash struct
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def self.openstruct_to_hash struct
|
12
|
+
hash = struct.marshal_dump
|
13
|
+
|
14
|
+
recurisive_transform_openstruct_to_hash hash
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.recurisive_transform_openstruct_to_hash hash
|
18
|
+
|
19
|
+
|
20
|
+
hash.each_pair do |key, val|
|
21
|
+
if val.instance_of?(Hash)
|
22
|
+
hash[key] = recurisive_transform_openstruct_to_hash val
|
23
|
+
elsif val.instance_of?(Array)
|
24
|
+
hash[key] = val.map do |arr|
|
25
|
+
if arr.instance_of?(OpenStruct)
|
26
|
+
recurisive_transform_openstruct_to_hash arr.marshal_dump
|
27
|
+
elsif arr.instance_of?(Hash)
|
28
|
+
recurisive_transform_openstruct_to_hash arr
|
29
|
+
else
|
30
|
+
arr
|
31
|
+
end
|
32
|
+
end
|
33
|
+
elsif val.instance_of?(OpenStruct)
|
34
|
+
hash[key] = recurisive_transform_openstruct_to_hash val.marshal_dump
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'openstruct_utils/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "openstruct_utils"
|
8
|
+
spec.version = OpenstructUtils::VERSION
|
9
|
+
spec.authors = ["cheyang"]
|
10
|
+
spec.email = ["cheyang@163.com"]
|
11
|
+
spec.summary = "Transform the openstruct object to hash."
|
12
|
+
spec.description = "Transform the openstruct object to hash."
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openstruct_utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cheyang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2014-05-27 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
prerelease: false
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: "1.5"
|
22
|
+
type: :development
|
23
|
+
version_requirements: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: rake
|
26
|
+
prerelease: false
|
27
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- &id003
|
30
|
+
- ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id002
|
35
|
+
description: Transform the openstruct object to hash.
|
36
|
+
email:
|
37
|
+
- cheyang@163.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- LICENSE.txt
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- lib/openstruct_utils.rb
|
51
|
+
- lib/openstruct_utils/version.rb
|
52
|
+
- openstruct_utils.gemspec
|
53
|
+
homepage: ""
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- *id003
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- *id003
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.0.14
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Transform the openstruct object to hash.
|
76
|
+
test_files: []
|
77
|
+
|