hanami-utils 1.1.0.rc1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66ae15a13bdd0d65aadddd58a45d564becf5ecf5
4
- data.tar.gz: a311ffffa5d3ac255f76bcb3018b4c0742958083
3
+ metadata.gz: c6d30f140bf19e5b5aeb6efef73e952d2ec1410e
4
+ data.tar.gz: 497a74c90d376ffd622aa6a42c10e1a6a0c0b8d4
5
5
  SHA512:
6
- metadata.gz: f95dd49e0d014b5b7fafd0a318598ca3c3662d1571796c4f549e2f37e91c7149a0d7fe11fee4c0fe3008b9aaa1e7acfefb819e8d00ebc52febbfbed6051fa136
7
- data.tar.gz: a1f32e26274cb76fd0dea3fe718732aa82b1eaa19f0658a5e0efd3eca59507d300615293f69287fa94d541fb2a8c5c632f285f3a158770d5a47758da53086324
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
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.6'
25
25
  spec.add_development_dependency 'rake', '~> 11'
26
- spec.add_development_dependency 'rspec', '~> 3.5'
26
+ spec.add_development_dependency 'rspec', '~> 3.7'
27
27
  end
@@ -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
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Defines the version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '1.1.0.rc1'.freeze
6
+ VERSION = '1.1.0'.freeze
7
7
  end
8
8
  end
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.rc1
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-16 00:00:00.000000000 Z
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.5'
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.5'
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: 1.3.1
134
+ version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
137
  rubygems_version: 2.6.13