refinements 7.4.0 → 7.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa83a3ce542b62b6d89204aea8ac2411565a401f26150bfcdc64a2d4334d0313
4
- data.tar.gz: c34503ce9aa7b522eac87ff66384fc8c1815c5907e4048a6023208f948a33cd1
3
+ metadata.gz: 0ccd018fc5d5ae2bfa0b6fc1b9f090bc3638ac4053ea5790d7826e2c291bc378
4
+ data.tar.gz: 43cd2a8603f9e8667eab9c18aa24ccf5b1f7860054d88b7bc39e22df1bfad573
5
5
  SHA512:
6
- metadata.gz: 8bc6f8633db7a9caed51998e190aeccb77b74a755d83a8a982e93d7c4c9576044598e626b9457fb40da667aff76c9d87314ad42f4e2815d8287435eee5d71e2a
7
- data.tar.gz: c23828f5179b57747cd0a173baa7deeee2fc1513791ecf1042612a23addf8443c7c012c6f316596b197a8765904e66d93f31141037271673e50bf2a6b9b56da8
6
+ metadata.gz: b5dd7fb29e0de7fe1e51209d427889331d8179c5e92868167e818e25dd792509d4221cdf07448a86bea13820cb13ccf0c680cb4b459c7c57ebb0dc0017255aba
7
+ data.tar.gz: 94a069d63f4c565fd0c189d489887d23e7420bb63b8a9ec3cb5defc3626a87158037eb7cefdafdaa1b43e5b66764fda59dcf9007279cdcc3d8d53eadbf078bb7
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -27,8 +27,8 @@ toc::[]
27
27
  ** `#rewrite` - When given a file path and a block, it provides the contents of the recently read
28
28
  file for manipulation and immediate writing back to the same file.
29
29
  * *Hashes*:
30
- ** `#except` - Answers new hash with given keys removed without modifying calling hash.
31
- ** `#except!` - Answers new hash with given keys removed while modifying calling hash.
30
+ ** `#except` - Answers new hash with given keys removed without modifying itself.
31
+ ** `#except!` - Answers new hash with given keys removed while modifying itself.
32
32
  ** `#symbolize_keys` - Converts keys to symbols without modifying itself.
33
33
  ** `#symbolize_keys!` - Converts keys to symbols while modifying itself.
34
34
  ** `#deep_merge` - Merges deeply nested hashes together without modifying itself.
@@ -38,11 +38,13 @@ file for manipulation and immediate writing back to the same file.
38
38
  ** `#deep_symbolize_keys!` - Symbolizes keys of nested hash while modifying itself. Does not handle
39
39
  nested arrays, though.
40
40
  ** `#recurse` - Applies block to nested hash. Does not handle nested arrays, though.
41
- ** `#rekey` - Transforms keys per mapping (size of mapping can vary).
42
- ** `#reverse_merge` - Merges calling hash into passed in hash without modifying calling hash.
43
- ** `#reverse_merge!` - Merges calling hash into passed in hash while modifying calling hash.
41
+ ** `#rekey` - Transforms keys per mapping (size of mapping can vary) without modifying itself.
42
+ ** `#rekey!` - Transforms keys per mapping (size of mapping can vary) while modifying itself.
43
+ ** `#reverse_merge` - Merges calling hash into passed in hash without modifying itself.
44
+ ** `#reverse_merge!` - Merges calling hash into passed in hash while modifying itself.
44
45
  ** `#use` - Passes each hash value as a block argument for further processing.
45
46
  * *Pathnames*:
47
+ ** `Pathname` - Conversion function (refined from `Kernel`) which can cast `nil` into a pathname.
46
48
  ** `#name` - Answers file name without extension.
47
49
  ** `#copy` - Copies file from current location to new location.
48
50
  ** `#directories` - Answers all or filtered directories for current path.
@@ -53,7 +55,7 @@ file for manipulation and immediate writing back to the same file.
53
55
  ** `#make_ancestors` - Ensures all ancestor directories are created for a path.
54
56
  ** `#rewrite` - When given a block, it provides the contents of the recently read file for
55
57
  manipulation and immediate writing back to the same file.
56
- ** `#touch` - Updates access and modification times to current time for path.
58
+ ** `#touch` - Updates access and modification times for path. Defaults to current time.
57
59
  * *Strings*:
58
60
  ** `#first` - Answers first character of a string or first set of characters if given a number.
59
61
  ** `#last` - Answers last character of a string or last set of characters if given a number.
@@ -69,8 +71,8 @@ manipulation and immediate writing back to the same file.
69
71
  == Requirements
70
72
 
71
73
  . https://www.ruby-lang.org[Ruby 2.7.x].
72
- . A solid understanding of https://www.youtube.com/watch?v=qXC9Gk4dCEw[Ruby refinements and lexical
73
- scope].
74
+ . A solid understanding of link:https://www.alchemists.io/articles/ruby_refinements[Ruby refinements
75
+ and lexical scope].
74
76
 
75
77
  == Setup
76
78
 
@@ -244,6 +246,11 @@ example.recurse(&:invert) # => {{"b" => 1} => "a"}
244
246
 
245
247
  example = {a: 1, b: 2, c: 3}
246
248
  example.rekey a: :amber, b: :blue # => {amber: 1, blue: 2, c: 3}
249
+ example # => {a: 1, b: 2, c: 3}
250
+
251
+ example = {a: 1, b: 2, c: 3}
252
+ example.rekey! a: :amber, b: :blue # => {amber: 1, blue: 2, c: 3}
253
+ example # => {amber: 1, blue: 2, c: 3}
247
254
 
248
255
  example = {a: 1, b: 2}
249
256
  example.reverse_merge a: 0, c: 3 # => {a: 1, b: 2, c: 3}
@@ -261,6 +268,8 @@ example.use { |unit, street| "#{unit} #{street}" } # => "221B Baker Street"
261
268
 
262
269
  [source,ruby]
263
270
  ----
271
+ Pathname(nil) # => Pathname("")
272
+
264
273
  Pathname("example.txt").name # => Pathname("example")
265
274
 
266
275
  Pathname("input.txt").copy Pathname("output.txt")
@@ -282,7 +291,7 @@ Pathname("/one/two").exist? # => false
282
291
  Pathname("/test.txt").rewrite { |content| content.sub "[placeholder]", "example" }
283
292
 
284
293
  Pathname("example.txt").touch
285
- Pathname("example.txt").touch accessed_at: Time.now - 1, modified_at: Time.now - 1
294
+ Pathname("example.txt").touch at: Time.now - 1
286
295
  ----
287
296
 
288
297
  ==== String
@@ -4,6 +4,7 @@ module Refinements
4
4
  module Files
5
5
  refine File.singleton_class do
6
6
  def rewrite path
7
+ warn "[DEPRECATION]: File.rewrite is deprecated, use Pathname#rewrite instead."
7
8
  read(path).then { |content| write path, yield(content) }
8
9
  end
9
10
  end
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "7.4.0"
8
+ VERSION = "7.5.0"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  end
11
11
  end
@@ -4,6 +4,14 @@ require "pathname"
4
4
 
5
5
  module Refinements
6
6
  module Pathnames
7
+ refine Kernel do
8
+ def Pathname object
9
+ return super(String(object)) unless object
10
+
11
+ super
12
+ end
13
+ end
14
+
7
15
  refine Pathname do
8
16
  def name
9
17
  basename extname
@@ -4,7 +4,7 @@ module Refinements
4
4
  module Strings
5
5
  refine String.singleton_class do
6
6
  def delimiters
7
- %r([a-z][A-Z]|\s*\-\s*|\s*\/\s*|\s*\:+\s*|\s*\_\s*|\s+)
7
+ %r([a-z][A-Z]|\s*-\s*|\s*/\s*|\s*:+\s*|\s*_\s*|\s+)
8
8
  end
9
9
  end
10
10
 
@@ -17,20 +17,18 @@ module Refinements
17
17
  return self[0] if max.zero?
18
18
  return "" if max.negative?
19
19
 
20
- self[0..(max - 1)]
20
+ self[..(max - 1)]
21
21
  end
22
22
 
23
- # :reek:TooManyStatements
24
23
  def last number = 0
25
24
  return self if empty?
26
25
 
27
26
  min = Integer number
28
- max = size - 1
29
27
 
30
- return self[max] if min.zero?
28
+ return self[size - 1] if min.zero?
31
29
  return "" if min.negative?
32
30
 
33
- self[(min + 1)..max]
31
+ self[(min + 1)..]
34
32
  end
35
33
 
36
34
  def blank?
@@ -50,33 +48,27 @@ module Refinements
50
48
  end
51
49
 
52
50
  def camelcase
53
- if match? self.class.delimiters
54
- split(%r(\s*\-\s*|\s*\/\s*|\s*\:+\s*)).then { |parts| combine parts, :up, "::" }
55
- .then { |text| text.split(/\s*\_\s*|\s+/) }
56
- .then { |parts| combine parts, :up }
57
- else
58
- up
59
- end
51
+ return up unless match? self.class.delimiters
52
+
53
+ split(%r(\s*-\s*|\s*/\s*|\s*:+\s*)).then { |parts| combine parts, :up, "::" }
54
+ .then { |text| text.split(/\s*_\s*|\s+/) }
55
+ .then { |parts| combine parts, :up }
60
56
  end
61
57
 
62
58
  def snakecase
63
- if match? self.class.delimiters
64
- split(%r(\s*\-\s*|\s*\/\s*|\s*\:+\s*)).then { |parts| combine parts, :down, "/" }
65
- .then { |txt| txt.split(/(?=[A-Z])|\s*\_\s*|\s+/) }
66
- .then { |parts| combine parts, :down, "_" }
67
- else
68
- downcase
69
- end
59
+ return downcase unless match? self.class.delimiters
60
+
61
+ split(%r(\s*-\s*|\s*/\s*|\s*:+\s*)).then { |parts| combine parts, :down, "/" }
62
+ .then { |text| text.split(/(?=[A-Z])|\s*_\s*|\s+/) }
63
+ .then { |parts| combine parts, :down, "_" }
70
64
  end
71
65
 
72
66
  def titleize
73
- if match? self.class.delimiters
74
- split(/(?=[A-Z])|\s*\_\s*|\s*\-\s*|\s+/).then { |parts| combine parts, :up, " " }
75
- .then { |text| text.split %r(\s*\/\s*|\s*\:+\s*) }
76
- .then { |parts| combine parts, :up, "/" }
77
- else
78
- capitalize
79
- end
67
+ return capitalize unless match? self.class.delimiters
68
+
69
+ split(/(?=[A-Z])|\s*_\s*|\s*-\s*|\s+/).then { |parts| combine parts, :up, " " }
70
+ .then { |text| text.split %r(\s*/\s*|\s*:+\s*) }
71
+ .then { |parts| combine parts, :up, "/" }
80
72
  end
81
73
 
82
74
  def to_bool
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinements
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.4.0
4
+ version: 7.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -28,7 +28,7 @@ cert_chain:
28
28
  2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
29
29
  QWc=
30
30
  -----END CERTIFICATE-----
31
- date: 2020-05-21 00:00:00.000000000 Z
31
+ date: 2020-06-07 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler-audit
@@ -226,7 +226,7 @@ dependencies:
226
226
  - - "~>"
227
227
  - !ruby/object:Gem::Version
228
228
  version: '0.18'
229
- description:
229
+ description:
230
230
  email:
231
231
  - brooke@alchemists.io
232
232
  executables: []
@@ -254,7 +254,7 @@ metadata:
254
254
  changelog_uri: https://www.alchemists.io/projects/refinements/changes.html
255
255
  documentation_uri: https://www.alchemists.io/projects/refinements
256
256
  source_code_uri: https://github.com/bkuhlmann/refinements
257
- post_install_message:
257
+ post_install_message:
258
258
  rdoc_options: []
259
259
  require_paths:
260
260
  - lib
@@ -269,8 +269,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
269
269
  - !ruby/object:Gem::Version
270
270
  version: '0'
271
271
  requirements: []
272
- rubygems_version: 3.1.3
273
- signing_key:
272
+ rubygems_version: 3.1.4
273
+ signing_key:
274
274
  specification_version: 4
275
275
  summary: A collection of refinements to core Ruby objects.
276
276
  test_files: []
metadata.gz.sig CHANGED
Binary file