hanami-utils 1.1.1 → 1.1.2

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
  SHA256:
3
- metadata.gz: 6fe9e18d01dfa9fc028b6844007dfcb410a0a03976bc84602ca1961527b9ed10
4
- data.tar.gz: de05ca0f54e2f88eb25f095c110e97f6655e3598b39a107b57931615589a67e3
3
+ metadata.gz: e0a22471f524190c15c4669f35dcede577bbbc83216fd5646c9d904bd87038fe
4
+ data.tar.gz: e8b2a902b6a4d8f78467ce3608a33c3c1ab297e72b425cffecac3012f11566a2
5
5
  SHA512:
6
- metadata.gz: e1279e5ab714af6ac575371da4f952349d309c7e6a804ef1aaf24f44944678dc899d15d8f9cc1e46fda6c51da6cb698d70283da61d8528aa56b8fcceebcc0516
7
- data.tar.gz: 7a1215ecec9a8bc03f4b474620575f471f254c487c87f6d9415933107d1d3c598ee8815f4086e90b84a0099e1d051519eedc36ea9d313bd97730f29263fee146
6
+ metadata.gz: 1da17b43c1ae804f6b771a6cc6901dfd9a8e64f01dc82eae83813e72e203f9c837277a0d70b93e1d590e61079fb101a0ca9eaefb017f6a922554d4570fbc5cb3
7
+ data.tar.gz: 63cfd9328ff78e3f0077a702175d987d0268b20b2f61c16e4c842cd6cd1bc83aeef296bafcf431697fb3f1e678e8269e39f6f3d09078d5efe329f0882c4a173f
data/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # Hanami::Utils
2
2
  Ruby core extentions and class utilities for Hanami
3
3
 
4
+ ## v1.1.2 - 2018-02-02
5
+ ### Added
6
+ - [Luca Guidi] Official support for Ruby: MRI 2.5
7
+
8
+ ### Fixed
9
+ - [Sean Collins & Luca Guidi] Make `Utils::Files.write` idempotent: ensure to truncate the file before to write
10
+ - [Sean Collins & Luca Guidi] Don't erase file contents when invoking `Utils::Files.touch`
11
+
12
+ ### Changed
13
+ - [Sean Collins & Luca Guidi] Deprecate `Utils::Files.rewrite` in favor of `.write`
14
+
4
15
  ## v1.1.1 - 2017-11-22
5
16
  ### Added
6
17
  - [Luca Guidi] Introduce `Utils::Hash.deep_stringify` to recursively stringify a hash
@@ -1,5 +1,6 @@
1
1
  require "pathname"
2
2
  require "fileutils"
3
+ require "hanami/utils/deprecation"
3
4
 
4
5
  module Hanami
5
6
  module Utils
@@ -15,12 +16,12 @@ module Hanami
15
16
  #
16
17
  # @since 1.1.0
17
18
  def self.touch(path)
18
- write(path, "")
19
+ mkdir_p(path)
20
+ FileUtils.touch(path)
19
21
  end
20
22
 
21
23
  # Creates a new file for the given path and content.
22
24
  # All the intermediate directories are created.
23
- # If the path already exists, it appends the contents.
24
25
  #
25
26
  # @param path [String,Pathname] the path to file
26
27
  # @param content [String, Array<String>] the content to write
@@ -28,7 +29,7 @@ module Hanami
28
29
  # @since 1.1.0
29
30
  def self.write(path, *content)
30
31
  mkdir_p(path)
31
- open(path, ::File::CREAT | ::File::WRONLY, *content)
32
+ open(path, ::File::CREAT | ::File::WRONLY | ::File::TRUNC, *content)
32
33
  end
33
34
 
34
35
  # Rewrites the contents of an existing file.
@@ -41,7 +42,11 @@ module Hanami
41
42
  #
42
43
  # @since 1.1.0
43
44
  def self.rewrite(path, *content)
44
- open(path, ::File::TRUNC | ::File::WRONLY, *content)
45
+ Hanami::Utils::Deprecation.new(
46
+ "`.rewrite' is deprecated, please use `.write'"
47
+ )
48
+ raise Errno::ENOENT unless File.exist?(path)
49
+ write(path, *content)
45
50
  end
46
51
 
47
52
  # Copies source into destination.
@@ -140,7 +145,7 @@ module Hanami
140
145
  content = ::File.readlines(path)
141
146
  content.unshift("#{line}\n")
142
147
 
143
- rewrite(path, content)
148
+ write(path, content)
144
149
  end
145
150
 
146
151
  # Adds a new line at the bottom of the file
@@ -159,7 +164,7 @@ module Hanami
159
164
  content = ::File.readlines(path)
160
165
  content << "#{contents}\n"
161
166
 
162
- rewrite(path, content)
167
+ write(path, content)
163
168
  end
164
169
 
165
170
  # Replace first line in `path` that contains `target` with `replacement`.
@@ -178,7 +183,7 @@ module Hanami
178
183
  content = ::File.readlines(path)
179
184
  content[index(content, path, target)] = "#{replacement}\n"
180
185
 
181
- rewrite(path, content)
186
+ write(path, content)
182
187
  end
183
188
 
184
189
  # Replace last line in `path` that contains `target` with `replacement`.
@@ -197,7 +202,7 @@ module Hanami
197
202
  content = ::File.readlines(path)
198
203
  content[-index(content.reverse, path, target) - 1] = "#{replacement}\n"
199
204
 
200
- rewrite(path, content)
205
+ write(path, content)
201
206
  end
202
207
 
203
208
  # Inject `contents` in `path` before `target`.
@@ -217,7 +222,7 @@ module Hanami
217
222
  i = index(content, path, target)
218
223
 
219
224
  content.insert(i, "#{contents}\n")
220
- rewrite(path, content)
225
+ write(path, content)
221
226
  end
222
227
 
223
228
  # Inject `contents` in `path` after `target`.
@@ -237,7 +242,7 @@ module Hanami
237
242
  i = index(content, path, target)
238
243
 
239
244
  content.insert(i + 1, "#{contents}\n")
240
- rewrite(path, content)
245
+ write(path, content)
241
246
  end
242
247
 
243
248
  # Removes line from `path`, matching `target`.
@@ -254,7 +259,7 @@ module Hanami
254
259
  i = index(content, path, target)
255
260
 
256
261
  content.delete_at(i)
257
- rewrite(path, content)
262
+ write(path, content)
258
263
  end
259
264
 
260
265
  # Removes `target` block from `path`
@@ -293,7 +298,7 @@ module Hanami
293
298
  ending = starting + index(content[starting..-1], path, closing)
294
299
 
295
300
  content.slice!(starting..ending)
296
- rewrite(path, content)
301
+ write(path, content)
297
302
 
298
303
  remove_block(path, target) if match?(content, target)
299
304
  end
@@ -329,7 +329,7 @@ module Hanami
329
329
  # 'bignum' => 13289301283 ** 2,
330
330
  # 'float' => 1.0,
331
331
  # 'complex' => Complex(0.3),
332
- # 'bigdecimal' => BigDecimal.new('12.0001'),
332
+ # 'bigdecimal' => BigDecimal('12.0001'),
333
333
  # 'rational' => Rational(0.3),
334
334
  # 'string' => 'foo bar',
335
335
  # 'hash' => { a: 1, b: 'two', c: :three },
@@ -244,7 +244,7 @@ module Hanami
244
244
  # Hanami::Utils::Kernel.Integer("1") # => 1
245
245
  # Hanami::Utils::Kernel.Integer(Rational(0.3)) # => 0
246
246
  # Hanami::Utils::Kernel.Integer(Complex(0.3)) # => 0
247
- # Hanami::Utils::Kernel.Integer(BigDecimal.new(12.00001)) # => 12
247
+ # Hanami::Utils::Kernel.Integer(BigDecimal(12.00001)) # => 12
248
248
  # Hanami::Utils::Kernel.Integer(176605528590345446089)
249
249
  # # => 176605528590345446089
250
250
  #
@@ -311,11 +311,11 @@ module Hanami
311
311
  # Hanami::Utils::Kernel.Integer(input) # => TypeError
312
312
  #
313
313
  # # bigdecimal infinity
314
- # input = BigDecimal.new("Infinity")
314
+ # input = BigDecimal("Infinity")
315
315
  # Hanami::Utils::Kernel.Integer(input) # => TypeError
316
316
  #
317
317
  # # bigdecimal NaN
318
- # input = BigDecimal.new("NaN")
318
+ # input = BigDecimal("NaN")
319
319
  # Hanami::Utils::Kernel.Integer(input) # => TypeError
320
320
  #
321
321
  # # big rational
@@ -364,7 +364,7 @@ module Hanami
364
364
  # Hanami::Utils::Kernel.BigDecimal("1") # => 1
365
365
  # Hanami::Utils::Kernel.BigDecimal(Rational(0.3)) # => 0.3
366
366
  # Hanami::Utils::Kernel.BigDecimal(Complex(0.3)) # => 0.3
367
- # Hanami::Utils::Kernel.BigDecimal(BigDecimal.new(12.00001)) # => 12.00001
367
+ # Hanami::Utils::Kernel.BigDecimal(BigDecimal(12.00001)) # => 12.00001
368
368
  # Hanami::Utils::Kernel.BigDecimal(176605528590345446089)
369
369
  # # => 176605528590345446089
370
370
  #
@@ -373,7 +373,7 @@ module Hanami
373
373
  #
374
374
  # UltimateAnswer = Struct.new(:question) do
375
375
  # def to_d
376
- # BigDecimal.new(42)
376
+ # BigDecimal(42)
377
377
  # end
378
378
  # end
379
379
  #
@@ -422,7 +422,7 @@ module Hanami
422
422
  when ->(a) { a.respond_to?(:to_d) }
423
423
  arg.to_d
424
424
  else
425
- BigDecimal.new(arg)
425
+ ::Kernel.BigDecimal(arg)
426
426
  end
427
427
  rescue NoMethodError
428
428
  raise TypeError.new "can't convert #{inspect_type_error(arg)}into BigDecimal"
@@ -454,7 +454,7 @@ module Hanami
454
454
  # Hanami::Utils::Kernel.Float("1") # => 1.0
455
455
  # Hanami::Utils::Kernel.Float(Rational(0.3)) # => 0.3
456
456
  # Hanami::Utils::Kernel.Float(Complex(0.3)) # => 0.3
457
- # Hanami::Utils::Kernel.Float(BigDecimal.new(12.00001)) # => 12.00001
457
+ # Hanami::Utils::Kernel.Float(BigDecimal(12.00001)) # => 12.00001
458
458
  # Hanami::Utils::Kernel.Float(176605528590345446089)
459
459
  # # => 176605528590345446089.0
460
460
  #
@@ -493,11 +493,11 @@ module Hanami
493
493
  # Hanami::Utils::Kernel.Float("2.5/1") # => 2.5
494
494
  #
495
495
  # # bigdecimal infinity
496
- # input = BigDecimal.new("Infinity")
496
+ # input = BigDecimal("Infinity")
497
497
  # Hanami::Utils::Kernel.Float(input) # => Infinity
498
498
  #
499
499
  # # bigdecimal NaN
500
- # input = BigDecimal.new("NaN")
500
+ # input = BigDecimal("NaN")
501
501
  # Hanami::Utils::Kernel.Float(input) # => NaN
502
502
  #
503
503
  # @example Unchecked Exceptions
@@ -606,9 +606,9 @@ module Hanami
606
606
  #
607
607
  # Hanami::Utils::Kernel.String(Rational(-22)) # => "-22/1"
608
608
  # Hanami::Utils::Kernel.String(Complex(11, 2)) # => "11+2i"
609
- # Hanami::Utils::Kernel.String(BigDecimal.new(7944.2343, 10)) # => "0.79442343E4"
610
- # Hanami::Utils::Kernel.String(BigDecimal.new('Infinity')) # => "Infinity"
611
- # Hanami::Utils::Kernel.String(BigDecimal.new('NaN')) # => "Infinity"
609
+ # Hanami::Utils::Kernel.String(BigDecimal(7944.2343, 10)) # => "0.79442343E4"
610
+ # Hanami::Utils::Kernel.String(BigDecimal('Infinity')) # => "Infinity"
611
+ # Hanami::Utils::Kernel.String(BigDecimal('NaN')) # => "Infinity"
612
612
  #
613
613
  # @example String interface
614
614
  # require 'hanami/utils/kernel'
@@ -212,7 +212,7 @@ module Hanami
212
212
  #
213
213
  # @param input [::String] the input
214
214
  #
215
- # @return [String] the transformed string
215
+ # @return [::String] the transformed string
216
216
  #
217
217
  # @since 1.1.0
218
218
  #
@@ -239,7 +239,7 @@ module Hanami
239
239
  #
240
240
  # @param input [::String] the input
241
241
  #
242
- # @return [String] the transformed string
242
+ # @return [::String] the transformed string
243
243
  #
244
244
  # @since 1.1.0
245
245
  #
@@ -282,7 +282,7 @@ module Hanami
282
282
  #
283
283
  # @param input [::String] the input
284
284
  #
285
- # @return [String] the transformed string
285
+ # @return [::String] the transformed string
286
286
  #
287
287
  # @since 1.1.0
288
288
  #
@@ -300,7 +300,7 @@ module Hanami
300
300
  #
301
301
  # @param input [::String] the input
302
302
  #
303
- # @return [String] the transformed string
303
+ # @return [::String] the transformed string
304
304
  #
305
305
  # @since 1.1.0
306
306
  #
@@ -386,7 +386,7 @@ module Hanami
386
386
  #
387
387
  # @param string [::String, Symbol] the value we want to initialize
388
388
  #
389
- # @return [String] self
389
+ # @return [Hanami::Utils::String] self
390
390
  #
391
391
  # @since 0.1.0
392
392
  def initialize(string)
@@ -441,7 +441,7 @@ module Hanami
441
441
 
442
442
  # Return a CamelCase version of the string
443
443
  #
444
- # @return [String] the transformed string
444
+ # @return [Hanami::Utils::String] the transformed string
445
445
  #
446
446
  # @since 0.1.0
447
447
  #
@@ -466,7 +466,7 @@ module Hanami
466
466
  # Revised version of `ActiveSupport::Inflector.underscore` implementation
467
467
  # @see https://github.com/rails/rails/blob/feaa6e2048fe86bcf07e967d6e47b865e42e055b/activesupport/lib/active_support/inflector/methods.rb#L90
468
468
  #
469
- # @return [String] the transformed string
469
+ # @return [Hanami::Utils::String] the transformed string
470
470
  #
471
471
  # @since 0.1.0
472
472
  #
@@ -507,7 +507,7 @@ module Hanami
507
507
 
508
508
  # Return the string without the Ruby namespace of the class
509
509
  #
510
- # @return [String] the transformed string
510
+ # @return [Hanami::Utils::String] the transformed string
511
511
  #
512
512
  # @since 0.1.0
513
513
  #
@@ -525,7 +525,7 @@ module Hanami
525
525
 
526
526
  # Return the top level namespace name
527
527
  #
528
- # @return [String] the transformed string
528
+ # @return [Hanami::Utils::String] the transformed string
529
529
  #
530
530
  # @since 0.1.2
531
531
  #
@@ -602,7 +602,7 @@ module Hanami
602
602
 
603
603
  # Returns the hash of the internal string
604
604
  #
605
- # @return [Fixnum]
605
+ # @return [Integer]
606
606
  #
607
607
  # @since 0.3.0
608
608
  def hash
@@ -611,7 +611,7 @@ module Hanami
611
611
 
612
612
  # Returns a string representation
613
613
  #
614
- # @return [String]
614
+ # @return [::String]
615
615
  #
616
616
  # @since 0.3.0
617
617
  def to_s
@@ -633,7 +633,7 @@ module Hanami
633
633
 
634
634
  # Split the string with the given pattern
635
635
  #
636
- # @return [Array<String>]
636
+ # @return [Array<::String>]
637
637
  #
638
638
  # @see http://www.ruby-doc.org/core/String.html#method-i-split
639
639
  #
@@ -644,7 +644,7 @@ module Hanami
644
644
 
645
645
  # Replace the given pattern with the given replacement
646
646
  #
647
- # @return [String,nil]
647
+ # @return [::String]
648
648
  #
649
649
  # @see http://www.ruby-doc.org/core/String.html#method-i-gsub
650
650
  #
@@ -657,9 +657,10 @@ module Hanami
657
657
  end
658
658
  end
659
659
 
660
- # Both forms iterate through str, matching the pattern
660
+ # Iterate through the string, matching the pattern.
661
+ # Either return all those patterns, or pass them to the block.
661
662
  #
662
- # @return [String,nil]
663
+ # @return [Array<::String>]
663
664
  #
664
665
  # @see http://www.ruby-doc.org/core/String.html#method-i-scan
665
666
  #
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Defines the version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '1.1.1'.freeze
6
+ VERSION = '1.1.2'.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.1
4
+ version: 1.1.2
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-11-22 00:00:00.000000000 Z
11
+ date: 2018-02-02 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: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.7.1
137
+ rubygems_version: 2.7.4
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: Ruby core extentions and Hanami utilities