refinements 7.4.0 → 7.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.adoc +18 -9
- data/lib/refinements/files.rb +1 -0
- data/lib/refinements/identity.rb +1 -1
- data/lib/refinements/pathnames.rb +8 -0
- data/lib/refinements/strings.rb +19 -27
- metadata +7 -7
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ccd018fc5d5ae2bfa0b6fc1b9f090bc3638ac4053ea5790d7826e2c291bc378
|
4
|
+
data.tar.gz: 43cd2a8603f9e8667eab9c18aa24ccf5b1f7860054d88b7bc39e22df1bfad573
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5dd7fb29e0de7fe1e51209d427889331d8179c5e92868167e818e25dd792509d4221cdf07448a86bea13820cb13ccf0c680cb4b459c7c57ebb0dc0017255aba
|
7
|
+
data.tar.gz: 94a069d63f4c565fd0c189d489887d23e7420bb63b8a9ec3cb5defc3626a87158037eb7cefdafdaa1b43e5b66764fda59dcf9007279cdcc3d8d53eadbf078bb7
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/README.adoc
CHANGED
@@ -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
|
31
|
-
** `#except!` - Answers new hash with given keys removed while modifying
|
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
|
-
** `#
|
43
|
-
** `#reverse_merge
|
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
|
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.
|
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
|
294
|
+
Pathname("example.txt").touch at: Time.now - 1
|
286
295
|
----
|
287
296
|
|
288
297
|
==== String
|
data/lib/refinements/files.rb
CHANGED
data/lib/refinements/identity.rb
CHANGED
data/lib/refinements/strings.rb
CHANGED
@@ -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
|
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[
|
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[
|
28
|
+
return self[size - 1] if min.zero?
|
31
29
|
return "" if min.negative?
|
32
30
|
|
33
|
-
self[(min + 1)..
|
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
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
+
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-
|
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.
|
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
|