refinements 7.6.0 → 7.7.0

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: b33464363d548d0cc888f7f3b1efac924eb2490a3846353589d892900d03de0d
4
- data.tar.gz: da1d401505c092c0b2e8850f476affb1932b79db770b4f11c263300e208f3457
3
+ metadata.gz: 3b7d7affd4176bb25ee87d3718b592a0bd2b07be2bad86d584f06f0d16dcd866
4
+ data.tar.gz: 256ab9f274581c668a06949a41501c50885f9681dd6150c9b58046d59cf87de7
5
5
  SHA512:
6
- metadata.gz: 6c8072c3a3d8348e871ed72c7519295fb4ade95e2463bf56424f42689909dc7113805fbc817012196a395442af811f4d215a5bc89cf8952bd4506b0a4cd49536
7
- data.tar.gz: 7797a5f506eb95d5999234c6e506ef9b0f4b949cfa41f831fcf883425fea7cb3da3b3ff3ef72f5c218236c006c38aeb2a957127ccf5177748fc3cac4291498ba
6
+ metadata.gz: 356b4ea5575bbec34d4b2c31495c59b49ce9efe00bedcce194d458c8bdbbcf47ca87e3be00b60f910af14e2768cf8b42de909fcdec652a895d8de706652e0777
7
+ data.tar.gz: 0a7d8c6bd99585868ec7b2d119f7014e1c2ebf571324d23c8be209bd364417c4106f465a4f0dd6ab012fb6f82e1024ae803ef0d27949051e6c65b4aa2d6f63dd
@@ -1,2 +1 @@
1
- ���8XoF���A�>����Ld�oG)KV���h���u�o���ڊziˍ�`����\��~R�U��
2
- ǧ6�kQ)õ���;+���GOD��tw�ůlV�� j���i��z`���)&�&�`�t�'������rY��O���vb�A�/b]���?B_DR#S��V�w��c�(�C�ӯn�? �r�։������VC�Sw)�{Їa$c~#��}� �Ow&�#;�">��"B�Cm��l9��=i�o��
1
+ ���.��� Q~ҵᮺiÆV��<gS�:�8������f��@J�/�'D�}*��O$���Br
data.tar.gz.sig CHANGED
Binary file
@@ -52,6 +52,8 @@ file for manipulation and immediate writing back to the same file.
52
52
  ** `#directories` - Answers all or filtered directories for current path.
53
53
  ** `#extensions` - Answers file extensions as an array.
54
54
  ** `#files` - Answers all or filtered files for current path.
55
+ ** `#gsub` - Same behavior as `String#gsub` but answers a path with patterns replaced with desired
56
+ substitutes.
55
57
  ** `#relative_parent_from` - Answers relative path from parent directory. This is a complement to
56
58
  `#relative_path_from`.
57
59
  ** `#make_ancestors` - Ensures all ancestor directories are created for a path.
@@ -69,6 +71,8 @@ manipulation and immediate writing back to the same file.
69
71
  ** `#snakecase` - Answers a snakecased string.
70
72
  ** `#titleize` - Answers titleized string.
71
73
  ** `#to_bool` - Answers string as a boolean.
74
+ * *String IOs*:
75
+ ** `#reread` - Answers full string by rewinding to beginning of string and reading all content.
72
76
 
73
77
  == Requirements
74
78
 
@@ -287,11 +291,16 @@ Pathname("input.txt").copy Pathname("output.txt")
287
291
 
288
292
  Pathname("/example").directories # => [Pathname("a"), Pathname("b")]
289
293
  Pathname("/example").directories "a*" # => [Pathname("a")]
294
+ Pathname("/example").directories flag: File::FNM_DOTMATCH # => [Pathname(".."), Pathname(".")]
290
295
 
291
296
  Pathname("example.txt.erb").extensions # => [".txt", ".erb"]
292
297
 
293
298
  Pathname("/example").files # => [Pathname("a.txt"), Pathname("a.png")]
294
299
  Pathname("/example").files "*.png" # => [Pathname("a.png")]
300
+ Pathname("/example").files flag: File::FNM_DOTMATCH # => [Pathname(".ruby-version")]
301
+
302
+ Pathname("/a/path/some/path").gsub("path", "test") # => Pathname("/a/test/some/test")
303
+ Pathname("/%placeholder%/some/%placeholder%").gsub("%placeholder%", "test") # => Pathname("/test/some/test")
295
304
 
296
305
  Pathname("/one/two/three").relative_parent_from("/one") # => Pathname "two"
297
306
 
@@ -334,6 +343,21 @@ Pathname("example.txt").touch at: Time.now - 1
334
343
  "example".to_bool # => false
335
344
  ----
336
345
 
346
+ ==== String IO
347
+
348
+ [source,ruby]
349
+ ----
350
+ io = StringIO.new
351
+ io.write "This is a test."
352
+ io.reread # => "This is a test."
353
+
354
+ io.reread(4) => "This"
355
+
356
+ buffer = "".dup
357
+ io.reread(buffer: buffer)
358
+ buffer # => "This is a test."
359
+ ----
360
+
337
361
  == Tests
338
362
 
339
363
  To test, run:
@@ -8,3 +8,4 @@ require "refinements/files"
8
8
  require "refinements/hashes"
9
9
  require "refinements/pathnames"
10
10
  require "refinements/strings"
11
+ require "refinements/string_ios"
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "7.6.0"
8
+ VERSION = "7.7.0"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  end
11
11
  end
@@ -23,16 +23,20 @@ module Refinements
23
23
  self
24
24
  end
25
25
 
26
- def directories pattern = "*"
27
- glob(pattern).select(&:directory?).sort
26
+ def directories pattern = "*", flag: File::FNM_SYSCASE
27
+ glob(pattern, flag).select(&:directory?).sort
28
28
  end
29
29
 
30
30
  def extensions
31
31
  basename.to_s.split(/(?=\.)+/).tap(&:shift)
32
32
  end
33
33
 
34
- def files pattern = "*"
35
- glob(pattern).select(&:file?).sort
34
+ def files pattern = "*", flag: File::FNM_SYSCASE
35
+ glob(pattern, flag).select(&:file?).sort
36
+ end
37
+
38
+ def gsub pattern, replacement
39
+ self.class.new to_s.gsub(pattern, replacement)
36
40
  end
37
41
 
38
42
  def relative_parent_from root
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stringio"
4
+
5
+ module Refinements
6
+ module StringIOs
7
+ refine StringIO do
8
+ def reread length = nil, buffer: nil
9
+ tap(&:rewind).read length, buffer
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,9 +2,12 @@
2
2
 
3
3
  module Refinements
4
4
  module Strings
5
+ DELIMITERS = %r([a-z][A-Z]|\s*-\s*|\s*/\s*|\s*:+\s*|\s*_\s*|\s+).freeze
6
+
5
7
  refine String.singleton_class do
6
8
  def delimiters
7
- %r([a-z][A-Z]|\s*-\s*|\s*/\s*|\s*:+\s*|\s*_\s*|\s+)
9
+ warn "[DEPRECATION]: .delimiters is deprecated, use DELIMITERS instead."
10
+ DELIMITERS
8
11
  end
9
12
  end
10
13
 
@@ -48,7 +51,7 @@ module Refinements
48
51
  end
49
52
 
50
53
  def camelcase
51
- return up unless match? self.class.delimiters
54
+ return up unless match? DELIMITERS
52
55
 
53
56
  split(%r(\s*-\s*|\s*/\s*|\s*:+\s*)).then { |parts| combine parts, :up, "::" }
54
57
  .then { |text| text.split(/\s*_\s*|\s+/) }
@@ -56,7 +59,7 @@ module Refinements
56
59
  end
57
60
 
58
61
  def snakecase
59
- return downcase unless match? self.class.delimiters
62
+ return downcase unless match? DELIMITERS
60
63
 
61
64
  split(%r(\s*-\s*|\s*/\s*|\s*:+\s*)).then { |parts| combine parts, :down, "/" }
62
65
  .then { |text| text.split(/(?=[A-Z])|\s*_\s*|\s+/) }
@@ -64,7 +67,7 @@ module Refinements
64
67
  end
65
68
 
66
69
  def titleize
67
- return capitalize unless match? self.class.delimiters
70
+ return capitalize unless match? DELIMITERS
68
71
 
69
72
  split(/(?=[A-Z])|\s*_\s*|\s*-\s*|\s+/).then { |parts| combine parts, :up, " " }
70
73
  .then { |text| text.split %r(\s*/\s*|\s*:+\s*) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinements
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.6.0
4
+ version: 7.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
29
29
  QWc=
30
30
  -----END CERTIFICATE-----
31
- date: 2020-07-04 00:00:00.000000000 Z
31
+ date: 2020-08-05 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler-audit
@@ -245,6 +245,7 @@ files:
245
245
  - lib/refinements/hashes.rb
246
246
  - lib/refinements/identity.rb
247
247
  - lib/refinements/pathnames.rb
248
+ - lib/refinements/string_ios.rb
248
249
  - lib/refinements/strings.rb
249
250
  homepage: https://www.alchemists.io/projects/refinements
250
251
  licenses:
metadata.gz.sig CHANGED
Binary file