refinements 7.14.0 → 7.15.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: 4abbbd79616d97836ca58503bb4638e2638e14732e76e7c00b3f5c033f708edc
4
- data.tar.gz: 516c79b5361a7512ca4e63c72303d8fb0d2cb85c693bc9aa13c36ef767580f10
3
+ metadata.gz: 756d9dcbbc60385370835ad8001dd4fb84f6848aba8ca51cbe949fcd2aaa72a4
4
+ data.tar.gz: f09562bfe5991533c166f5aa0aa215a3f2fe8df3604e85dd3404a7688df67980
5
5
  SHA512:
6
- metadata.gz: 2f15aa4b466d6e610a2ffc45ad16285d27107c93a4260d214abcee42e66005951a5f2a708da6b04a28826ab3abd0a85ad0e1a707782b6ba5c51ef5cb0b705ec7
7
- data.tar.gz: ec214191217bb870ca264fbfe3fa31d57b6c37c28e0f92806f779d3ea8400fbac11ee4aa38c82d6d10d7b07187a2360a7aa810ef802e6d219a217043cd76e69c
6
+ metadata.gz: b37235bf15f3b959dd295a22c3e9c89dff28faa4124da955b0e27b2bef7db505d3093dc56369550d2863e6dc2ca3d10bbfe248da1e7a70f0eaee7fb351bd4e9f
7
+ data.tar.gz: 0c7aeed58557e626cc6494d761e79c4a0bcb60f42e79d83cef01676c9fd5fbf838dd97f4b89c3234a978455d3acfb6bdd3f715ed55dfed05a92e5f0e86d7426d
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -28,6 +28,7 @@ Enhances the following objects:
28
28
  * Pathname
29
29
  * String
30
30
  * StringIO
31
+ * Structs
31
32
 
32
33
  == Requirements
33
34
 
@@ -75,6 +76,7 @@ require "refinements/ios"
75
76
  require "refinements/pathnames"
76
77
  require "refinements/strings"
77
78
  require "refinements/string_ios"
79
+ require "refinements/structs"
78
80
  ----
79
81
 
80
82
  === Using
@@ -94,6 +96,7 @@ class Example
94
96
  using Refinements::Pathnames
95
97
  using Refinements::Strings
96
98
  using Refinements::StringIOs
99
+ using Refinements::Structs
97
100
  end
98
101
  ----
99
102
 
@@ -481,11 +484,8 @@ block, you'll need to close the stream manually.
481
484
 
482
485
  [source,ruby]
483
486
  ----
484
- io = IO.void
485
- io.closed? # => false
486
-
487
- io = IO.void { |void| void.write "nevermore" }
488
- io.closed? # => true
487
+ io = IO.void # => #<IO:fd 20>
488
+ io = IO.void { |void| void.write "nevermore" } # => #<IO:(closed)>
489
489
  ----
490
490
 
491
491
  ===== #redirect
@@ -498,11 +498,8 @@ answered instead.
498
498
  io = IO.new IO.sysopen(Pathname("test.txt").to_s, "w+")
499
499
  other = IO.new IO.sysopen(Pathname("other.txt").to_s, "w+")
500
500
 
501
- io.redirect other # => `io`
502
-
503
- io.redirect(other) { |stream| stream.write "test" }
504
- .close # => ""
505
- other.close # => "test"
501
+ io.redirect other # => #<IO:fd 20>
502
+ io.redirect(other) { |stream| stream.write "test" } # => #<IO:fd 21>
506
503
  ----
507
504
 
508
505
  ===== #reread
@@ -518,30 +515,31 @@ io.reread # => "This is a test."
518
515
  io.reread 4 # => "This"
519
516
 
520
517
  buffer = "".dup
521
- io.reread(buffer: buffer)
522
- buffer # => "This is a test."
518
+ io.reread(buffer: buffer) # => "This is a test."
519
+ buffer # => "This is a test."
523
520
  ----
524
521
 
525
522
  ===== #squelch
526
523
 
527
- Temporarily ignores any reads/writes for current stream for all code executed within the block. When
528
- not given a block, it answers itself.
524
+ Temporarily ignores any reads/writes for code executed within a block. Answers itself without any
525
+ arguments or when given a block.
529
526
 
530
527
  [source,ruby]
531
528
  ----
532
529
  io = IO.new IO.sysopen(Pathname("test.txt").to_s, "w+")
533
- io.squelch { io.write "Test" }
534
- io.reread # => ""
530
+ io.squelch # => #<IO:fd 20>
531
+ io.squelch { io.write "Test" } # => #<IO:fd 20>
532
+ io.reread # => ""
535
533
  ----
536
534
 
537
535
  ==== Pathname
538
536
 
539
537
  ===== Pathname
540
538
 
541
- Enhances the conversion function -- refined from `Kernel` -- which casts `nil` into a pathname in
542
- order to avoid: `TypeError (no implicit conversion of nil into String)`. The pathname is still
543
- invalid but at least you have an instance of `Pathname`, which behaves like a _Null Object_, that
544
- can still be used to construct a valid path.
539
+ Enhances the `Kernel` conversion function which casts `nil` into a pathname in order to avoid:
540
+ `TypeError (no implicit conversion of nil into String)`. The pathname remains invalid but at least
541
+ you have an instance of `Pathname`, which behaves like a _Null Object_, that can be used to
542
+ construct a valid path.
545
543
 
546
544
  [source,ruby]
547
545
  ----
@@ -559,23 +557,23 @@ Pathname.pwd # => "/"
559
557
  Pathname("/test").make_dir.change_dir # => Pathname "/test"
560
558
  Pathname.pwd # => "/test"
561
559
 
562
- Pathname.pwd # => "/"
563
- Pathname("/test").make_dir.change_dir { # Implementation details } # => Pathname "/test"
564
- Pathname.pwd # => "/"
560
+ Pathname.pwd # => "/"
561
+ Pathname("/test").make_dir.change_dir { "example" } # => "example"
562
+ Pathname.pwd # => "/"
565
563
  ----
566
564
 
567
565
  ===== #copy
568
566
 
569
- Copies file from current location to new location.
567
+ Copies file from current location to new location while answering itself so it can be chained.
570
568
 
571
569
  [source,ruby]
572
570
  ----
573
- Pathname("input.txt").copy Pathname("output.txt")
571
+ Pathname("input.txt").copy Pathname("output.txt") # => Pathname("input.txt")
574
572
  ----
575
573
 
576
574
  ===== #directories
577
575
 
578
- Answers all or filtered directories for current path.
576
+ Answers all directories or filtered directories for current path.
579
577
 
580
578
  [source,ruby]
581
579
  ----
@@ -595,7 +593,7 @@ Pathname("example.txt.erb").extensions # => [".txt", ".erb"]
595
593
 
596
594
  ===== #files
597
595
 
598
- Answers all or filtered files for current path.
596
+ Answers all files or filtered files for current path.
599
597
 
600
598
  [source,ruby]
601
599
  ----
@@ -623,9 +621,9 @@ Ensures all ancestor directories are created for a path.
623
621
 
624
622
  [source,ruby]
625
623
  ----
626
- Pathname("/one/two").make_ancestors
627
- Pathname("/one").exist? # => true
628
- Pathname("/one/two").exist? # => false
624
+ Pathname("/one/two").make_ancestors # => Pathname("/one/two")
625
+ Pathname("/one").exist? # => true
626
+ Pathname("/one/two").exist? # => false
629
627
  ----
630
628
 
631
629
  ===== #make_dir
@@ -708,7 +706,8 @@ immediate writing back to the same file.
708
706
 
709
707
  [source,ruby]
710
708
  ----
711
- Pathname("/test.txt").rewrite { |content| content.sub "[placeholder]", "example" }
709
+ Pathname("/test.txt").rewrite # => Pathname("/test.txt")
710
+ Pathname("/test.txt").rewrite { |body| body.sub "[token]", "example" } # => Pathname("/test.txt")
712
711
  ----
713
712
 
714
713
  ===== #touch
@@ -717,8 +716,20 @@ Updates access and modification times for path. Defaults to current time.
717
716
 
718
717
  [source,ruby]
719
718
  ----
720
- Pathname("example.txt").touch
721
- Pathname("example.txt").touch at: Time.now - 1
719
+ Pathname("example.txt").touch # => Pathname("example.txt")
720
+ Pathname("example.txt").touch at: Time.now - 1 # => Pathname("example.txt")
721
+ ----
722
+
723
+ ===== #write
724
+
725
+ Writes to file and answers itself so it can be chained. See `IO.write` for details on additional
726
+ options.
727
+
728
+ [source,ruby]
729
+ ----
730
+ Pathname("example.txt").write "test" # => Pathname("example.txt")
731
+ Pathname("example.txt").write "test", offset: 1 # => Pathname("example.txt")
732
+ Pathname("example.txt").write "test", mode: "a" # => Pathname("example.txt")
722
733
  ----
723
734
 
724
735
  ==== String
@@ -838,8 +849,52 @@ io.reread # => "This is a test."
838
849
  io.reread 4 # => "This"
839
850
 
840
851
  buffer = "".dup
841
- io.reread(buffer: buffer)
842
- buffer # => "This is a test."
852
+ io.reread(buffer: buffer) # => "This is a test."
853
+ buffer # => "This is a test."
854
+ ----
855
+
856
+ ==== Struct
857
+
858
+ ===== #merge
859
+
860
+ Merges multiple attributes without mutating itself.
861
+
862
+ [source,ruby]
863
+ ----
864
+ Example = Struct.new :a, :b, :c
865
+ example = Example[1, 2, 3]
866
+ example.merge a: 10 # => #<struct a=10, b=2, c=3>
867
+ example.merge a: 10, c: 30 # => #<struct a=10, b=2, c=30>
868
+ example.merge a: 10, b: 20, c: 30 # => #<struct a=10, b=20, c=30>
869
+ example # => #<struct a=1, b=2, c=3>
870
+
871
+ Example = Struct.new :a, :b, :c, keyword_init: true
872
+ example = Example[a: 1, b: 2, c: 3]
873
+ example.merge a: 10 # => #<struct a=10, b=2, c=3>
874
+ example.merge a: 10, c: 30 # => #<struct a=10, b=2, c=30>
875
+ example.merge a: 10, b: 20, c: 30 # => #<struct a=10, b=20, c=30>
876
+ example # => #<struct a=1, b=2, c=3>
877
+ ----
878
+
879
+ ===== #merge!
880
+
881
+ Merges multiple attributes while mutating itself.
882
+
883
+ [source,ruby]
884
+ ----
885
+ Example = Struct.new :a, :b, :c
886
+ example = Example[1, 2, 3]
887
+ example.merge! a: 10 # => #<struct a=10, b=2, c=3>
888
+ example.merge! a: 10, c: 30 # => #<struct a=10, b=2, c=30>
889
+ example.merge! a: 10, b: 20, c: 30 # => #<struct a=10, b=20, c=30>
890
+ example # => #<struct a=10, b=20, c=30>
891
+
892
+ Example = Struct.new :a, :b, :c, keyword_init: true
893
+ example = Example[a: 1, b: 2, c: 3]
894
+ example.merge! a: 10 # => #<struct a=10, b=2, c=3>
895
+ example.merge! a: 10, c: 30 # => #<struct a=10, b=2, c=30>
896
+ example.merge! a: 10, b: 20, c: 30 # => #<struct a=10, b=20, c=30>
897
+ example # => #<struct a=10, b=20, c=30>
843
898
  ----
844
899
 
845
900
  == Development
@@ -10,3 +10,4 @@ require "refinements/ios"
10
10
  require "refinements/pathnames"
11
11
  require "refinements/strings"
12
12
  require "refinements/string_ios"
13
+ require "refinements/structs"
@@ -73,7 +73,7 @@ module Refinements
73
73
  end
74
74
 
75
75
  def recurse &block
76
- return self unless block_given?
76
+ return self unless block
77
77
 
78
78
  transform = yield self
79
79
 
@@ -119,7 +119,7 @@ module Refinements
119
119
  end
120
120
 
121
121
  def use &block
122
- return [] unless block_given?
122
+ return [] unless block
123
123
 
124
124
  block.parameters
125
125
  .map { |(_type, key)| self[key] }
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "7.14.0"
8
+ VERSION = "7.15.0"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  end
11
11
  end
@@ -14,7 +14,7 @@ module Refinements
14
14
 
15
15
  refine Pathname do
16
16
  def change_dir &block
17
- block_given? ? Dir.chdir(self, &block) : (Dir.chdir self and self)
17
+ block ? Dir.chdir(self, &block) : (Dir.chdir self and self)
18
18
  end
19
19
 
20
20
  def copy to
@@ -82,13 +82,17 @@ module Refinements
82
82
 
83
83
  def rewrite
84
84
  read.then { |content| write yield(content) if block_given? }
85
- self
86
85
  end
87
86
 
88
87
  def touch at: Time.now
89
88
  exist? ? utime(at, at) : write("")
90
89
  self
91
90
  end
91
+
92
+ def write content, offset: nil, **options
93
+ super content, offset, options
94
+ self
95
+ end
92
96
  end
93
97
  end
94
98
  end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Refinements
4
+ module Structs
5
+ refine Struct do
6
+ def merge **attributes
7
+ dup.merge! attributes
8
+ end
9
+
10
+ def merge! **attributes
11
+ to_h.merge(attributes).each { |key, value| self[key] = value }
12
+ self
13
+ end
14
+ end
15
+ end
16
+ end
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.14.0
4
+ version: 7.15.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-11-14 00:00:00.000000000 Z
31
+ date: 2020-11-21 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler-audit
@@ -58,6 +58,34 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0.2'
61
+ - !ruby/object:Gem::Dependency
62
+ name: gemsmith
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '14.8'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '14.8'
75
+ - !ruby/object:Gem::Dependency
76
+ name: git-lint
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.3'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.3'
61
89
  - !ruby/object:Gem::Dependency
62
90
  name: guard-rspec
63
91
  requirement: !ruby/object:Gem::Requirement
@@ -234,6 +262,7 @@ files:
234
262
  - lib/refinements/pathnames.rb
235
263
  - lib/refinements/string_ios.rb
236
264
  - lib/refinements/strings.rb
265
+ - lib/refinements/structs.rb
237
266
  homepage: https://www.alchemists.io/projects/refinements
238
267
  licenses:
239
268
  - Apache-2.0
metadata.gz.sig CHANGED
Binary file