hanami-utils 1.1.0.beta1 → 1.1.0.beta2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe0165282131db30a45dc60b913b4a36f9eb2095
4
- data.tar.gz: c5ec0be6be92bd58c1e0b6043634b0d0af68e7fd
3
+ metadata.gz: 3e83a3e9a076efd62198e77eaced47f088e0cb51
4
+ data.tar.gz: c23f56620e1d7164f8ccc16a896846f3d88e73f3
5
5
  SHA512:
6
- metadata.gz: c4eaf7e264153e4062cafa3eccead00a4793e64e4c44f291c4b573819b4f480155122198e37d3a13283e0ad1e01a0cf96e0e3e5e3c7de3ddd48d64a35bfd7e07
7
- data.tar.gz: 93ca73d54081fb22c927a398dfd6e7d4573554a48d8847a7aef91b6134bbea4904b122a8fd577e4f0fac77420e3c9df2a0c3176e019a572b5923f9ace3718dff
6
+ metadata.gz: 7f5d9b11a03d752cb1b8ce489f9f34d8b4353e68e734f1a9c825b476756e00fa4101d57d04a2f8f19fe7beb78610f089a0bc85d5163116caa30683bafef00acc
7
+ data.tar.gz: 51b354ac98bd76b1c04ed159bec4f98be12a2444c824b20fe1691bbc1f419c124a53a237cd548394cc70f5979ce6f3068aeb69bd072af3a035084d1190934c41
@@ -1,6 +1,10 @@
1
1
  # Hanami::Utils
2
2
  Ruby core extentions and class utilities for Hanami
3
3
 
4
+ ## v1.1.0.beta2 - 2017-10-03
5
+ ### Added
6
+ - [Alfonso Uceda] Auto create directory for `Hanami::Logger`
7
+
4
8
  ## v1.1.0.beta1 - 2017-08-11
5
9
  ### Added
6
10
  - [Marion Duprey] Allow `Hanami::Interactor#call` to accept arguments. `#initialize` should be used for Dependency Injection, while `#call` should be used for input
@@ -10,12 +14,21 @@ Ruby core extentions and class utilities for Hanami
10
14
  - [Luca Guidi] Introduce `Utils::String.transform` a pipelined transformations for strings
11
15
  - [Marion Duprey & Gabriel Gizotti] Filter sensitive informations for `Hanami::Logger`
12
16
 
17
+ ## v1.0.4 - 2017-10-02
18
+ ### Fixed
19
+ - [Luca Guidi] Make `Hanami::Utils::BasicObject` to be fully compatible with Ruby's `pp` and to be inspected by Pry.
20
+ - [Thiago Kenji Okada] Fix pluralization/singularization for `"release" => "releases"`
21
+
22
+ ## v1.0.3 - 2017-09-06
23
+ ### Fixed
24
+ - [Malina Sulca] Fix pluralization/singularization for `"exercise" => "exercises"`
25
+ - [Xavier Barbosa] Fix pluralization/singularization for `"area" => "areas"`
26
+
13
27
  ## v1.0.2 - 2017-07-10
14
28
  ### Fixed
15
29
  - [Anton Davydov] Fix pluralization/singularization for `"phrase" => "phrases"`
16
30
 
17
31
  ## v1.0.1 - 2017-06-23
18
-
19
32
  ### Added
20
33
  - [Luca Guidi] Introduced `Utils::Hash.symbolize` and `.deep_symbolize`
21
34
  - [Luca Guidi] Introduced `Utils::Hash.deep_dup`
@@ -1 +1 @@
1
- require 'hanami/utils' # rubocop:disable Style/FileName
1
+ require 'hanami/utils' # rubocop:disable Naming/FileName
@@ -5,6 +5,7 @@ require 'hanami/utils/string'
5
5
  require 'hanami/utils/json'
6
6
  require 'hanami/utils/hash'
7
7
  require 'hanami/utils/class_attribute'
8
+ require 'hanami/utils/files'
8
9
 
9
10
  module Hanami
10
11
  # Hanami logger
@@ -111,7 +112,7 @@ module Hanami
111
112
 
112
113
  # @since 1.0.0
113
114
  # @api private
114
- RESERVED_KEYS = %i(app severity time).freeze
115
+ RESERVED_KEYS = %i[app severity time].freeze
115
116
 
116
117
  include Utils::ClassAttribute
117
118
 
@@ -453,7 +454,14 @@ module Hanami
453
454
  # logger.info "Hello World"
454
455
  #
455
456
  # # => {"app":"Hanami","severity":"DEBUG","time":"2017-03-30T13:57:59Z","message":"Hello World"}
456
- def initialize(application_name = nil, *args, stream: $stdout, level: DEBUG, formatter: nil, filter: []) # rubocop:disable Metrics/ParameterLists
457
+ # rubocop:disable Lint/HandleExceptions
458
+ # rubocop:disable Metrics/ParameterLists
459
+ def initialize(application_name = nil, *args, stream: $stdout, level: DEBUG, formatter: nil, filter: [])
460
+ begin
461
+ Utils::Files.mkdir_p(stream)
462
+ rescue TypeError
463
+ end
464
+
457
465
  super(stream, *args)
458
466
 
459
467
  @level = _level(level)
@@ -21,7 +21,7 @@ module Hanami
21
21
  #
22
22
  # @see http://ruby-doc.org/core/Object.html#method-i-inspect
23
23
  def inspect
24
- "#<#{self.class}:#{'%x' % (__id__ << 1)}#{__inspect}>" # rubocop:disable Style/FormatString
24
+ "#<#{self.class}:#{'0x0000%x' % (__id__ << 1)}#{__inspect}>" # rubocop:disable Style/FormatString
25
25
  end
26
26
 
27
27
  # Alias for __id__
@@ -37,13 +37,14 @@ module Hanami
37
37
 
38
38
  # Interface for pp
39
39
  #
40
+ # @param printer [PP] the Pretty Printable printer
40
41
  # @return [String] the pretty-printable inspection of the object
41
42
  #
42
43
  # @since 0.9.0
43
44
  #
44
45
  # @see https://ruby-doc.org/stdlib/libdoc/pp/rdoc/PP.html
45
- def pretty_print(*)
46
- inspect
46
+ def pretty_print(printer)
47
+ printer.text(inspect)
47
48
  end
48
49
 
49
50
  # Returns true if responds to the given method.
@@ -69,7 +69,7 @@ module Hanami
69
69
  case value
70
70
  when NilClass, FalseClass, TrueClass, Symbol, Numeric
71
71
  value
72
- when v = blk && blk.call(value)
72
+ when v = blk&.call(value)
73
73
  v
74
74
  else
75
75
  value.dup
@@ -362,7 +362,7 @@ module Hanami
362
362
  # @api private
363
363
  #
364
364
  # @see Hanami::Utils::Escape.url
365
- DEFAULT_URL_SCHEMES = %w(http https mailto).freeze
365
+ DEFAULT_URL_SCHEMES = %w[http https mailto].freeze
366
366
 
367
367
  # The output of an escape.
368
368
  #
@@ -511,7 +511,7 @@ module Hanami
511
511
  return input if input.is_a?(SafeString)
512
512
 
513
513
  SafeString.new(
514
- URI::Parser.new.extract(
514
+ URI::DEFAULT_PARSER.extract(
515
515
  URI.decode_www_form_component(input),
516
516
  schemes
517
517
  ).first.to_s
@@ -69,6 +69,26 @@ module Hanami
69
69
  self[:deep_symbolize_keys].call(input)
70
70
  end
71
71
 
72
+ # Stringify the given hash
73
+ #
74
+ # @param input [::Hash] the input
75
+ #
76
+ # @return [::Hash] the stringified hash
77
+ #
78
+ # @since 1.0.1
79
+ #
80
+ # @example Basic Usage
81
+ # require 'hanami/utils/hash'
82
+ #
83
+ # hash = Hanami::Utils::Hash.stringify(foo: "bar", baz: {a: 1})
84
+ # # => {"foo"=>"bar", "baz"=>{:a=>1}}
85
+ #
86
+ # hash.class
87
+ # # => Hash
88
+ def self.stringify(input)
89
+ self[:stringify_keys].call(input)
90
+ end
91
+
72
92
  # Deep duplicate hash values
73
93
  #
74
94
  # The output of this function is a shallow duplicate of the input.
@@ -161,7 +181,7 @@ module Hanami
161
181
  # hash.keys # => [:a, :b]
162
182
  # hash.inspect # => { :a => 23, :b => { 'c' => ["x", "y", "z"] } }
163
183
  def symbolize!
164
- keys.each do |k|
184
+ keys.each do |k| # rubocop:disable Performance/HashEachMethods (this breaks the build)
165
185
  v = delete(k)
166
186
  self[k.to_sym] = v
167
187
  end
@@ -184,7 +204,7 @@ module Hanami
184
204
  # hash.keys # => [:a, :b]
185
205
  # hash.inspect # => {:a=>23, :b=>{:c=>["x", "y", "z"]}}
186
206
  def deep_symbolize!
187
- keys.each do |k|
207
+ keys.each do |k| # rubocop:disable Performance/HashEachMethods (this breaks the build)
188
208
  v = delete(k)
189
209
  v = self.class.new(v).deep_symbolize! if v.respond_to?(:to_hash)
190
210
 
@@ -208,9 +228,8 @@ module Hanami
208
228
  #
209
229
  # hash.keys # => [:a, :b]
210
230
  # hash.inspect # => {"a"=>23, "b"=>{"c"=>["x", "y", "z"]}}
211
-
212
231
  def stringify!
213
- keys.each do |k|
232
+ keys.each do |k| # rubocop:disable Performance/HashEachMethods (this breaks the build)
214
233
  v = delete(k)
215
234
  v = self.class.new(v).stringify! if v.respond_to?(:to_hash)
216
235
 
@@ -220,10 +239,6 @@ module Hanami
220
239
  self
221
240
  end
222
241
 
223
- def self.stringify(input)
224
- self[:stringify_keys].call(input)
225
- end
226
-
227
242
  # Return a deep copy of the current Hanami::Utils::Hash
228
243
  #
229
244
  # @return [Hash] a deep duplicated self
@@ -226,7 +226,8 @@ module Hanami
226
226
  'police' => 'police',
227
227
  # regressions
228
228
  # https://github.com/hanami/utils/issues/106
229
- 'album' => 'albums'
229
+ 'album' => 'albums',
230
+ 'area' => 'areas'
230
231
  )
231
232
 
232
233
  # Irregular rules for singulars
@@ -267,8 +268,11 @@ module Hanami
267
268
  'species' => 'species',
268
269
  'police' => 'police',
269
270
  # fallback
271
+ 'areas' => 'area',
270
272
  'hives' => 'hive',
271
- 'phases' => 'phase'
273
+ 'phases' => 'phase',
274
+ 'exercises' => 'exercise',
275
+ 'releases' => 'release'
272
276
  )
273
277
 
274
278
  # Block for custom inflection rules.
@@ -309,10 +313,19 @@ module Hanami
309
313
  # exception 'alga', 'algae'
310
314
  # end
311
315
  def self.exception(singular, plural)
316
+ add_to_inflecto(singular, plural)
312
317
  singulars.add(plural, singular)
313
318
  plurals.add(singular, plural)
314
319
  end
315
320
 
321
+ # Since ROM uses Inflecto for it inferences, we need to add an exception to it
322
+ # when one is registered against our Inflector.
323
+ # @api private
324
+ def self.add_to_inflecto(singular, plural)
325
+ return unless defined? Inflecto
326
+ Inflecto.inflections.irregular(singular, plural)
327
+ end
328
+
316
329
  # Add an uncountable word
317
330
  #
318
331
  # @param [Array<String>] words
@@ -132,7 +132,7 @@ module Hanami
132
132
  # @see #relative
133
133
  def relative!
134
134
  @string.gsub!(/(?<!:)#{separator * 2}/, separator)
135
- @string.sub!(/\A#{separator}/, '')
135
+ @string[/\A#{separator}|^/] = ''
136
136
 
137
137
  self
138
138
  end
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Defines the version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '1.1.0.beta1'.freeze
6
+ VERSION = '1.1.0.beta2'.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.beta1
4
+ version: 1.1.0.beta2
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-08-11 00:00:00.000000000 Z
11
+ date: 2017-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: transproc
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: 1.3.1
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.6.11
137
+ rubygems_version: 2.6.13
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Ruby core extentions and Hanami utilities