hanami-utils 1.1.0.rc1 → 1.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 +4 -4
- data/CHANGELOG.md +4 -0
- data/hanami-utils.gemspec +1 -1
- data/lib/hanami/utils/hash.rb +40 -0
- data/lib/hanami/utils/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6d30f140bf19e5b5aeb6efef73e952d2ec1410e
|
4
|
+
data.tar.gz: 497a74c90d376ffd622aa6a42c10e1a6a0c0b8d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 877777f3b3e4ec23f8316a9bbe1bdc497b02a1a500550e53456c649107be24ce14adc99c10e83d5e18c1cf8deeb402137b508066573fb44056c0543ff39937dd
|
7
|
+
data.tar.gz: 741334c7eac873fd2041b27309d11d0762554592c8badbe3948260804558f707348697037f31901e56bfe96262414d85981521cdbce2128d6bce7775579ded32
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Hanami::Utils
|
2
2
|
Ruby core extentions and class utilities for Hanami
|
3
3
|
|
4
|
+
## v1.1.0 - 2017-10-25
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Introduce `Utils::Hash.deep_serialize` to recursively serialize input into `::Hash`
|
7
|
+
|
4
8
|
## v1.1.0.rc1 - 2017-10-16
|
5
9
|
|
6
10
|
## v1.1.0.beta3 - 2017-10-04
|
data/hanami-utils.gemspec
CHANGED
data/lib/hanami/utils/hash.rb
CHANGED
@@ -137,6 +137,46 @@ module Hanami
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
+
# Deep serialize given object into a `Hash`
|
141
|
+
#
|
142
|
+
# Please note that the returning `Hash` will use symbols as keys.
|
143
|
+
#
|
144
|
+
# @param input [#to_hash] the input
|
145
|
+
#
|
146
|
+
# @return [::Hash] the deep serialized hash
|
147
|
+
#
|
148
|
+
# @since 1.1.0
|
149
|
+
#
|
150
|
+
# @example Basic Usage
|
151
|
+
# require 'hanami/utils/hash'
|
152
|
+
# require 'ostruct'
|
153
|
+
#
|
154
|
+
# class Data < OpenStruct
|
155
|
+
# def to_hash
|
156
|
+
# to_h
|
157
|
+
# end
|
158
|
+
# end
|
159
|
+
#
|
160
|
+
# input = Data.new("foo" => "bar", baz => [Data.new(hello: "world")])
|
161
|
+
#
|
162
|
+
# Hanami::Utils::Hash.deep_serialize(input)
|
163
|
+
# # => {:foo=>"bar", :baz=>[{:hello=>"world"}]}
|
164
|
+
def self.deep_serialize(input) # rubocop:disable Metrics/MethodLength
|
165
|
+
input.to_hash.each_with_object({}) do |(key, value), output|
|
166
|
+
output[key.to_sym] =
|
167
|
+
case value
|
168
|
+
when ->(h) { h.respond_to?(:to_hash) }
|
169
|
+
deep_serialize(value)
|
170
|
+
when Array
|
171
|
+
value.map do |item|
|
172
|
+
item.respond_to?(:to_hash) ? deep_serialize(item) : item
|
173
|
+
end
|
174
|
+
else
|
175
|
+
value
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
140
180
|
# Initialize the hash
|
141
181
|
#
|
142
182
|
# @param hash [#to_h] the value we want to use to initialize this instance
|
data/lib/hanami/utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: transproc
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
75
|
+
version: '3.7'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
82
|
+
version: '3.7'
|
83
83
|
description: Hanami utilities
|
84
84
|
email:
|
85
85
|
- me@lucaguidi.com
|
@@ -129,9 +129,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: 2.3.0
|
130
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
131
|
requirements:
|
132
|
-
- - "
|
132
|
+
- - ">="
|
133
133
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
134
|
+
version: '0'
|
135
135
|
requirements: []
|
136
136
|
rubyforge_project:
|
137
137
|
rubygems_version: 2.6.13
|