hanami-utils 1.0.0 → 1.0.1

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: 222ce74ee6d0046eb15654d43137779443680672
4
- data.tar.gz: 399ca64be5aa28e052f97342e53f80a9fe853901
3
+ metadata.gz: 7fde1682b3dd9e18b73474151562576b62ed40c8
4
+ data.tar.gz: af101e3c84ee66f7f981869502e63cbaa66fcc65
5
5
  SHA512:
6
- metadata.gz: f312d57686b39917b644c9e096e865a3e1f1a2a4b5c8a915f1a452216f123e6dc3170e587947e3311e13a01972a2c2f0fce047b7b6b2495a7c6584a05f8e77ec
7
- data.tar.gz: fdc41332f6d86936626eb23795271780e70036c6fae8d4458a15ddb832187a047cba81c727a1877c26938fe2900ec1c08d733d72670fc950873bb1b48da322ed
6
+ metadata.gz: 7ce2f82b2afea0388175f650a7eb13750529afcc499dd7279ebc711c269dd4f673be963abec741d4d28b35766a44061ef14d239312328fb9fbb13470f6055381
7
+ data.tar.gz: 1273ac6688f44ec40e5ee28aa3f0e4c707ac7bc81b89ef98dc8499bfa8de2d3dea9bcd36e429bc905323eef0d673ee40b7f4975c71c77a0586a3895e04a208d8
data/CHANGELOG.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # Hanami::Utils
2
2
  Ruby core extentions and class utilities for Hanami
3
3
 
4
+ ## v1.0.1 - 2017-06-23
5
+
6
+ ### Added
7
+ - [Luca Guidi] Introduced `Utils::Hash.symbolize` and `.deep_symbolize`
8
+ - [Luca Guidi] Introduced `Utils::Hash.deep_dup`
9
+
10
+ ### Fixed
11
+ - [choallin] Ensure `Utils::String#classify` to return output identical to the input for already classified strings.
12
+ - [Marion Duprey & Jonas Amundsen] Ensure `Utils::Hash#initialize` to accept frozen `Hash` as argument.
13
+
4
14
  ## v1.0.0 - 2017-04-06
5
15
 
6
16
  ## v1.0.0.rc1 - 2017-03-31
data/README.md CHANGED
@@ -81,7 +81,7 @@ Deprecate Hanami features. [[API doc](http://www.rubydoc.info/gems/hanami-utils/
81
81
 
82
82
  ### Hanami::Utils::Duplicable
83
83
 
84
- Safe `#dup` logic for Ruby objects. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Deprecation)]
84
+ Safe `#dup` logic for Ruby objects. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Duplicable)]
85
85
 
86
86
 
87
87
  ### Hanami::Utils::Escape
data/hanami-utils.gemspec CHANGED
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  lib = File.expand_path('../lib', __FILE__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
  require 'hanami/utils/version'
@@ -20,6 +18,9 @@ Gem::Specification.new do |spec|
20
18
  spec.require_paths = ['lib']
21
19
  spec.required_ruby_version = '>= 2.3.0'
22
20
 
21
+ spec.add_dependency 'transproc', '~> 1.0'
22
+
23
23
  spec.add_development_dependency 'bundler', '~> 1.6'
24
24
  spec.add_development_dependency 'rake', '~> 11'
25
+ spec.add_development_dependency 'rspec', '~> 3.5'
25
26
  end
@@ -205,12 +205,11 @@ module Hanami
205
205
  #
206
206
  # def initialize(params)
207
207
  # @params = params
208
- # @user = User.new(@params)
209
208
  # @foo = 'bar'
210
209
  # end
211
210
  #
212
211
  # def call
213
- # @user = UserRepository.new.persist(@user)
212
+ # @user = UserRepository.new.create(@params)
214
213
  # end
215
214
  # end
216
215
  #
@@ -231,12 +230,11 @@ module Hanami
231
230
  #
232
231
  # def initialize(params)
233
232
  # @params = params
234
- # @user = User.new(@params)
235
233
  # end
236
234
  #
237
235
  # # THIS WON'T BE INVOKED BECAUSE #valid? WILL RETURN false
238
236
  # def call
239
- # @user = UserRepository.new.persist(@user)
237
+ # @user = UserRepository.new.create(@params)
240
238
  # end
241
239
  #
242
240
  # private
@@ -292,7 +290,6 @@ module Hanami
292
290
  #
293
291
  # def initialize(params)
294
292
  # @params = params
295
- # @email_test = EmailTest.new(@params)
296
293
  # end
297
294
  #
298
295
  # def call
@@ -302,7 +299,7 @@ module Hanami
302
299
  #
303
300
  # private
304
301
  # def persist_email_test!
305
- # @email_test = EmailTestRepository.new.persist(@email_test)
302
+ # @email_test = EmailTestRepository.new.create(@params)
306
303
  # end
307
304
  #
308
305
  # # IF THIS RAISES AN EXCEPTION WE FORCE A FAILURE
@@ -1,4 +1,5 @@
1
1
  require 'hanami/utils/duplicable'
2
+ require 'transproc'
2
3
 
3
4
  module Hanami
4
5
  module Utils
@@ -19,6 +20,101 @@ module Hanami
19
20
  end
20
21
  end.freeze
21
22
 
23
+ extend Transproc::Registry
24
+ import Transproc::HashTransformations
25
+
26
+ # Symbolize the given hash
27
+ #
28
+ # @param input [::Hash] the input
29
+ #
30
+ # @return [::Hash] the symbolized hash
31
+ #
32
+ # @since 1.0.1
33
+ #
34
+ # @see .deep_symbolize
35
+ #
36
+ # @example Basic Usage
37
+ # require 'hanami/utils/hash'
38
+ #
39
+ # hash = Hanami::Utils::Hash.symbolize("foo" => "bar", "baz" => {"a" => 1})
40
+ # # => {:foo=>"bar", :baz=>{"a"=>1}}
41
+ #
42
+ # hash.class
43
+ # # => Hash
44
+ def self.symbolize(input)
45
+ self[:symbolize_keys].call(input)
46
+ end
47
+
48
+ # Deep symbolize the given hash
49
+ #
50
+ # @param input [::Hash] the input
51
+ #
52
+ # @return [::Hash] the deep symbolized hash
53
+ #
54
+ # @since 1.0.1
55
+ #
56
+ # @see .symbolize
57
+ #
58
+ # @example Basic Usage
59
+ # require 'hanami/utils/hash'
60
+ #
61
+ # hash = Hanami::Utils::Hash.deep_symbolize("foo" => "bar", "baz" => {"a" => 1})
62
+ # # => {:foo=>"bar", :baz=>{a:=>1}}
63
+ #
64
+ # hash.class
65
+ # # => Hash
66
+ def self.deep_symbolize(input)
67
+ self[:deep_symbolize_keys].call(input)
68
+ end
69
+
70
+ # Deep duplicate hash values
71
+ #
72
+ # The output of this function is a shallow duplicate of the input.
73
+ # Any further modification on the input, won't be reflected on the output
74
+ # and viceversa.
75
+ #
76
+ # @param input [::Hash] the input
77
+ #
78
+ # @return [::Hash] the shallow duplicate of input
79
+ #
80
+ # @since 1.0.1
81
+ #
82
+ # @example Basic Usage
83
+ # require 'hanami/utils/hash'
84
+ #
85
+ # input = { "a" => { "b" => { "c" => [1, 2, 3] } } }
86
+ # output = Hanami::Utils::Hash.deep_dup(input)
87
+ # # => {"a"=>{"b"=>{"c"=>[1,2,3]}}}
88
+ #
89
+ # output.class
90
+ # # => Hash
91
+ #
92
+ #
93
+ #
94
+ # # mutations on input aren't reflected on output
95
+ #
96
+ # input["a"]["b"]["c"] << 4
97
+ # output.dig("a", "b", "c")
98
+ # # => [1, 2, 3]
99
+ #
100
+ #
101
+ #
102
+ # # mutations on output aren't reflected on input
103
+ #
104
+ # output["a"].delete("b")
105
+ # input
106
+ # # => {"a"=>{"b"=>{"c"=>[1,2,3,4]}}}
107
+ def self.deep_dup(input)
108
+ input.each_with_object({}) do |(k, v), result|
109
+ result[k] = case v
110
+ when ::Hash
111
+ deep_dup(v)
112
+ else
113
+ Duplicable.dup(v)
114
+ end
115
+ end
116
+ end
117
+
22
118
  # Initialize the hash
23
119
  #
24
120
  # @param hash [#to_h] the value we want to use to initialize this instance
@@ -45,7 +141,7 @@ module Hanami
45
141
  # hash.to_h # => { 'foo' => ['bar'] }
46
142
  def initialize(hash = {}, &blk)
47
143
  @hash = hash.to_hash
48
- @hash.default_proc = blk
144
+ @hash.default_proc = blk if blk
49
145
  end
50
146
 
51
147
  # Convert in-place all the keys to Symbol instances.
@@ -142,7 +142,7 @@ module Hanami
142
142
  # string.classify # => 'HanamiUtils'
143
143
  def classify
144
144
  words = underscore.split(CLASSIFY_WORD_SEPARATOR).map!(&:capitalize)
145
- delimiters = scan(CLASSIFY_WORD_SEPARATOR)
145
+ delimiters = underscore.scan(CLASSIFY_WORD_SEPARATOR)
146
146
 
147
147
  delimiters.map! do |delimiter|
148
148
  delimiter == CLASSIFY_SEPARATOR ? EMPTY_STRING : NAMESPACE_SEPARATOR
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Defines the version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '1.0.0'.freeze
6
+ VERSION = '1.0.1'.freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
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-04-06 00:00:00.000000000 Z
11
+ date: 2017-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: transproc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.5'
41
69
  description: Hanami utilities
42
70
  email:
43
71
  - me@lucaguidi.com
@@ -91,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
119
  version: '0'
92
120
  requirements: []
93
121
  rubyforge_project:
94
- rubygems_version: 2.6.11
122
+ rubygems_version: 2.6.12
95
123
  signing_key:
96
124
  specification_version: 4
97
125
  summary: Ruby core extentions and Hanami utilities