refinements 12.10.0 → 13.0.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: 56d9d8ea056f8d22d211d5d9ad964b74e5fc86eb4be0b3476a1cd15c0ef74856
4
- data.tar.gz: bd3d5e64e0dfd3ae296d81a6b96212390b223f79b91d14fd3af14eab2c2dd867
3
+ metadata.gz: fceef99a782c47ebc49c3838188470d7733a92df5402f94e4acb343963a3af88
4
+ data.tar.gz: 04b4536366245c5a31710d35830f8144271fdb369cd1a69d0a1ca0b6d609b95d
5
5
  SHA512:
6
- metadata.gz: 63f889fedadba076370027afce7f0e176bd7e840d6b470d99043033a39f79277a4aebe7b0573e8d6c367432c59e98cb77b26ee62b5148f420121b632d86f8dfb
7
- data.tar.gz: 47712bdf7aff52e05671f7fed297bd06f54dfa1e554e529723c3ab932b2204d30630a25906b757769f314c213e004014fc887bcdfd5b6ac36edf1949bd16335d
6
+ metadata.gz: d0ef79f4049cfe582f4516111c70f0568ade844a659c13e5e7d65b87651d14a8d938de3fcae525c274266f9bb66021babdc455f02f3cd9367f90dcd5b33f69ba
7
+ data.tar.gz: 50acd2a2dd7ff2a280cd978f2b37ae7edd71b54e41b0c4e6bdae31b955148daee2fd9980f8aefa21d61d47bcfa6e8ebe1df46281808a333482bdedd480f0d8af
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -18,8 +18,6 @@ Enhances the following objects:
18
18
  * DateTime
19
19
  * Hash
20
20
  * IO
21
- * LogDevice
22
- * Logger
23
21
  * Module
24
22
  * Object
25
23
  * Pathname
@@ -86,8 +84,6 @@ require "refinements/data"
86
84
  require "refinements/date_time"
87
85
  require "refinements/hash"
88
86
  require "refinements/io"
89
- require "refinements/log_device"
90
- require "refinements/logger"
91
87
  require "refinements/module"
92
88
  require "refinements/object"
93
89
  require "refinements/pathname"
@@ -111,8 +107,6 @@ class Example
111
107
  using Refinements::DateTime
112
108
  using Refinements::Hash
113
109
  using Refinements::IO
114
- using Refinements::LogDevice
115
- using Refinements::Logger
116
110
  using Refinements::Module
117
111
  using Refinements::Object
118
112
  using Refinements::Pathname
@@ -187,25 +181,6 @@ Removes given array or elements without mutating itself.
187
181
  [1, 2, 3, 4, 5].excluding 4, 5 # [1, 2, 3]
188
182
  ----
189
183
 
190
- ===== #filter_find
191
-
192
- ⚠️ _This is deprecated and will be removed in Version 13.0.0._
193
-
194
- Answers the first element which evaluates to true from a filtered collection.
195
-
196
- [source,ruby]
197
- ----
198
- handlers = [
199
- -> object { object if object == :b },
200
- proc { false },
201
- -> object { object if object == :a }
202
- ]
203
-
204
- handlers.filter_find # Enumerator::Lazy
205
- handlers.filter_find { |handler| handler.call :a } # :a
206
- handlers.filter_find { |handler| handler.call :x } # nil
207
- ----
208
-
209
184
  ===== #including
210
185
 
211
186
  Adds given array or elements without mutating itself.
@@ -922,69 +897,6 @@ io.squelch { io.write "Test" } # "#<IO:fd 20>"
922
897
  io.reread # ""
923
898
  ----
924
899
 
925
- ==== LogDevice
926
-
927
- ===== #reread
928
-
929
- Answers previously written content by rewinding to beginning of device.
930
-
931
- [source,ruby]
932
- ----
933
- # With File.
934
- device = Logger::LogDevice.new "test.log"
935
- device.write "Test."
936
- device.reread # "Test."
937
-
938
- # With StringIO.
939
- device = Logger::LogDevice.new StringIO.new
940
- device.write "Test."
941
- device.reread # "Test."
942
-
943
- # With STDOUT.
944
- device = Logger::LogDevice.new $stdout
945
- device.write "Test."
946
- device.reread # ""
947
- ----
948
-
949
- ==== Logger
950
-
951
- ===== #reread
952
-
953
- Answers previously written content by rewinding to beginning of log.
954
-
955
- [source,ruby]
956
- ----
957
- # With File.
958
- logger = Logger.new "test.log"
959
- logger.write "Test."
960
- logger.reread # "Test."
961
-
962
- # With StringIO.
963
- logger = Logger.new StringIO.new
964
- logger.write "Test."
965
- logger.reread # "Test."
966
-
967
- # With STDOUT.
968
- logger = Logger.new $stdout
969
- logger.write "Test."
970
- logger.reread # ""
971
- ----
972
-
973
- ===== #any
974
-
975
- Allows you to log _any_ message which is identical in behavior and functionality to the `Logger#unknown` method only this requires less typing and better matches the terminology used by the `#unknown` method.
976
-
977
- [source,ruby]
978
- ----
979
- logger = Logger.new STDOUT
980
-
981
- logger.any "Test."
982
- # A, [2000-01-10T09:00:00.847428 #44925] ANY -- : Test.
983
-
984
- logger.any { "Test." }
985
- A, [2000-01-10T09:00:00.330719 #44925] ANY -- : Test.
986
- ----
987
-
988
900
  ==== Module
989
901
 
990
902
  ===== #pseudonym
@@ -1083,29 +995,6 @@ Answers user home directory.
1083
995
  Pathname.home # Pathname "/Users/demo"
1084
996
  ----
1085
997
 
1086
- ===== .make_temp_dir
1087
-
1088
- Wraps `Dir.mktmpdir` with the following behavior (see
1089
- link:https://rubyapi.org/o/Dir.mktmpdir#method-c-mktmpdir[Dir.mktmpdir] for details):
1090
-
1091
- * *Without Block* - Answers a newly created Pathname instance which is not automatically cleaned up.
1092
- * *With Block* Yields a Pathname instance, answers result of given block, and automatically cleans
1093
- up temporary directory after block exits.
1094
-
1095
- The following examples use truncated temporary directories for illustration purposes only. In
1096
- reality, these paths will be longer depending on which operating system you are using.
1097
-
1098
- [source,ruby]
1099
- ----
1100
- Pathname.make_temp_dir # Pathname:/var/folders/T/temp-20200101-16940-r8
1101
- Pathname.make_temp_dir prefix: "prefix-" # Pathname:/var/folders/T/prefix-20200101-16940-r8
1102
- Pathname.make_temp_dir suffix: "-suffix" # Pathname:/var/folders/T/temp-20200101-16940-r8-suffix
1103
- Pathname.make_temp_dir prefix: "prefix-", suffix: "-suffix" # Pathname:/var/folders/T/prefix-20200101-16940-r8-suffix
1104
- Pathname.make_temp_dir root: "/example" # Pathname:/example/temp-20200101-16940-r8
1105
- Pathname.make_temp_dir { "I am a block result" } # "I am a block result"
1106
- Pathname.make_temp_dir { |path| path.join "sub_dir" } # Pathname:/var/folders/T/temp-20200101-16940-r8/sub_dir
1107
- ----
1108
-
1109
998
  ===== .require_tree
1110
999
 
1111
1000
  Requires all Ruby files in given root path and corresponding nested tree structure. All files are sorted before being required to ensure consistent behavior. Example:
@@ -1158,6 +1047,8 @@ custom.change_dir { |path| path } # Pathname "$HOME/demo/test"
1158
1047
  Pathname.pwd # "$HOME/demo" (Present Working Directory)
1159
1048
  ----
1160
1049
 
1050
+ ⚠️ This method is _not thread safe_ and suffers the same issues as found with native `Dir.chdir` functionality because the underlying native call is global. Use with care.
1051
+
1161
1052
  ===== #copy
1162
1053
 
1163
1054
  Copies file from current location to new location while answering itself so it can be chained.
@@ -1231,7 +1122,7 @@ of contents. If a directory or file doesn't exist, it will be created.
1231
1122
 
1232
1123
  [source,ruby]
1233
1124
  ----
1234
- directory = Pathname("test").make_path
1125
+ directory = Pathname("test").mkpath
1235
1126
  file = directory.join("test.txt").write("example")
1236
1127
 
1237
1128
  file.empty.read # ""
@@ -1293,17 +1184,6 @@ Pathname("/one").make_dir # Pathname("/one")
1293
1184
  Pathname("/one").make_dir.make_dir # Pathname("/one")
1294
1185
  ----
1295
1186
 
1296
- ===== #make_path
1297
-
1298
- Provides alternative `#mkpath` behavior by always answering itself (even when full path exists) and
1299
- not throwing errors when directory does exist in order to ensure the pathname can be chained.
1300
-
1301
- [source,ruby]
1302
- ----
1303
- Pathname("/one/two/three").make_path # Pathname("/one/two/three")
1304
- Pathname("/one/two/three").make_path.make_path # Pathname("/one/two/three")
1305
- ----
1306
-
1307
1187
  ===== #name
1308
1188
 
1309
1189
  Answers file name without extension.
@@ -1347,27 +1227,6 @@ Pathname("/test").remove_dir # Pathname("/test")
1347
1227
  Pathname("/test").remove_dir.remove_dir # Pathname("/test")
1348
1228
  ----
1349
1229
 
1350
- ===== #remove_tree
1351
-
1352
- Provides alternative `#rmtree` behavior by always answering itself (even when full path exists) and
1353
- not throwing errors when directory does exist in order to ensure the pathname can be chained.
1354
-
1355
- [source,ruby]
1356
- ----
1357
- parent_path = Pathname "/one"
1358
- child_path = parent_path.join "two"
1359
-
1360
- child_path.make_path
1361
- parent_path.remove_tree # Pathname "/one"
1362
- child_path.exist? # false
1363
- parent_path.exist? # false
1364
-
1365
- child_path.make_path
1366
- child_path.remove_tree # Pathname "/one/two"
1367
- child_path.exist? # false
1368
- parent_path.exist? # true
1369
- ----
1370
-
1371
1230
  ===== #rewrite
1372
1231
 
1373
1232
  When given a block, it provides the contents of the recently read file for manipulation and
@@ -1628,24 +1487,6 @@ io.to_str # "One, Two."
1628
1487
 
1629
1488
  ==== Struct
1630
1489
 
1631
- ===== .with_positions
1632
-
1633
- ⚠️ _This is deprecated and will be removed in Version 13.0.0._
1634
-
1635
- Answers a struct instance with given positional arguments regardless of
1636
- whether the struct was constructed with positional or keyword arguments.
1637
-
1638
- [source,ruby]
1639
- ----
1640
- Example = Struct.new :a, :b, :c
1641
- Example.with_positions 1, 2, 3 # #<struct a=1, b=2, c=3>
1642
- Example.with_positions 1 # #<struct a=1, b=nil, c=nil>
1643
-
1644
- Example = Struct.new :a, :b, :c, keyword_init: true
1645
- Example.with_positions 1, 2, 3 # #<struct a=1, b=2, c=3>
1646
- Example.with_positions 1 # #<struct a=1, b=nil, c=nil>
1647
- ----
1648
-
1649
1490
  ===== #diff
1650
1491
 
1651
1492
  Allows you to obtain the differences between two objects.
@@ -1700,47 +1541,6 @@ example.merge! a: 10, b: 20, c: 30 # #<struct Struct::Example a=10, b=20, c=30>
1700
1541
  example # #<struct Struct::Example a=10, b=20, c=30>
1701
1542
  ----
1702
1543
 
1703
- ===== #revalue
1704
-
1705
- Transforms values without mutating itself. An optional hash can be supplied to target specific
1706
- attributes. In the event that a block isn't supplied, the struct will answer itself since there is
1707
- nothing to operate on. Works regardless of whether the struct is constructed with
1708
- positional or keyword arguments.
1709
-
1710
- [source,ruby]
1711
- ----
1712
- example = Struct.new("Example", :a, :b, :c).new 1, 2, 3
1713
-
1714
- example.revalue { |value| value * 2 } # #<struct Struct::Example a=2, b=4, c=6>
1715
- example.revalue(c: 2) { |previous, current| previous + current } # #<struct Struct::Example a=1, b=2, c=5>
1716
- example.revalue c: 2 # #<struct Struct::Example a=1, b=2, c=3>
1717
- example.revalue # #<struct Struct::Example a=1, b=2, c=3>
1718
- example # #<struct Struct::Example a=1, b=2, c=3>
1719
- ----
1720
-
1721
- ===== #revalue!
1722
-
1723
- Transforms values while mutating itself. An optional hash can be supplied to target specific
1724
- attributes. In the event that a block isn't supplied, the struct will answer itself since there is
1725
- nothing to operate on. Works regardless of whether the struct is constructed with
1726
- positional or keyword arguments.
1727
-
1728
- [source,ruby]
1729
- ----
1730
- one = Struct.new("One", :a, :b, :c).new 1, 2, 3
1731
- one.revalue! { |value| value * 2 } # #<struct Struct::One a=2, b=4, c=6>
1732
- one # #<struct Struct::One a=2, b=4, c=6>
1733
-
1734
- two = Struct.new("Two", :a, :b, :c).new 1, 2, 3
1735
- two.revalue!(c: 2) { |previous, current| previous + current } # #<struct Struct::Two a=1, b=2, c=5>
1736
- two # #<struct Struct::Two a=1, b=2, c=5>
1737
-
1738
- three = Struct.new("Three", :a, :b, :c).new 1, 2, 3
1739
- three.revalue! c: 2 # #<struct Struct::Three a=1, b=2, c=3>
1740
- three.revalue! # #<struct Struct::Three a=1, b=2, c=3>
1741
- three # #<struct Struct::Three a=1, b=2, c=3>
1742
- ----
1743
-
1744
1544
  ===== #transmute
1745
1545
 
1746
1546
  Transmutes given enumerable by using the foreign key map and merging those key values into the
@@ -19,13 +19,6 @@ module Refinements
19
19
 
20
20
  def excluding(*elements) = self - elements.flatten
21
21
 
22
- def filter_find(&)
23
- warn "`#{self.class}##{__method__}` is deprecated and will be removed in Version 13.0.0.",
24
- category: :deprecated
25
-
26
- block_given? ? lazy.map(&).find(&:itself) : lazy
27
- end
28
-
29
22
  def including(*elements) = self + elements.flatten
30
23
 
31
24
  def intersperse(*elements) = product([elements]).tap(&:pop).flatten.push(last)
@@ -88,8 +88,8 @@ module Refinements
88
88
 
89
89
  def transform_with(**) = dup.transform_with!(**)
90
90
 
91
- def transform_with!(**operations)
92
- operations.each { |key, function| self[key] = function.call self[key] if key? key }
91
+ def transform_with!(**mutations)
92
+ mutations.each { |key, function| transform_value! key, &function }
93
93
  self
94
94
  end
95
95
 
@@ -7,7 +7,7 @@ module Refinements
7
7
  module IO
8
8
  refine ::IO.singleton_class do
9
9
  def void
10
- new(sysopen("/dev/null", "w+")).then do |io|
10
+ new(sysopen(File::NULL, "w+")).then do |io|
11
11
  return io unless block_given?
12
12
 
13
13
  yield io
@@ -16,14 +16,6 @@ module Refinements
16
16
  refine ::Pathname.singleton_class do
17
17
  def home = new ENV.fetch("HOME", "")
18
18
 
19
- def make_temp_dir prefix: "temp-", suffix: nil, root: nil
20
- if block_given?
21
- Dir.mktmpdir([prefix, suffix], root) { |path| yield new(path) }
22
- else
23
- new Dir.mktmpdir([prefix, suffix], root)
24
- end
25
- end
26
-
27
19
  def require_tree(root) = new(root).files("**/*.rb").each { |path| require path.to_s }
28
20
 
29
21
  def root = new(File::SEPARATOR)
@@ -56,7 +48,7 @@ module Refinements
56
48
  glob(pattern, flag).select(&:directory?)
57
49
  end
58
50
 
59
- def empty = file? ? (truncate(0) and self) : remove_tree.make_dir
51
+ def empty = file? ? (truncate(0) and self) : rmtree.make_dir
60
52
 
61
53
  def extensions = basename.to_s.split(/(?=\.)+/).tap(&:shift)
62
54
 
@@ -71,11 +63,6 @@ module Refinements
71
63
 
72
64
  def make_dir = exist? ? self : (mkdir and self)
73
65
 
74
- def make_path
75
- mkpath
76
- self
77
- end
78
-
79
66
  def name = basename extname
80
67
 
81
68
  def puts(content) = write "#{content}\n"
@@ -84,11 +71,6 @@ module Refinements
84
71
 
85
72
  def remove_dir = exist? ? (rmdir and self) : self
86
73
 
87
- def remove_tree
88
- rmtree if exist?
89
- self
90
- end
91
-
92
74
  def rewrite = read.then { |content| write yield(content) if block_given? }
93
75
 
94
76
  def touch at = Time.now
@@ -5,15 +5,6 @@ require "refinements/shared/diff"
5
5
  module Refinements
6
6
  # Provides additional enhancements to the Struct primitive.
7
7
  module Struct
8
- refine ::Struct.singleton_class do
9
- def with_positions(*values)
10
- warn "`#{self.class}##{__method__}` is deprecated and will be removed in Version 13.0.0.",
11
- category: :deprecated
12
-
13
- keyword_init? ? new(**members.zip(values).to_h) : new(*values)
14
- end
15
- end
16
-
17
8
  refine ::Struct do
18
9
  import_methods Shared::Diff
19
10
 
@@ -24,19 +15,6 @@ module Refinements
24
15
  self
25
16
  end
26
17
 
27
- def revalue attributes = each_pair
28
- return self unless block_given?
29
-
30
- dup.tap { |copy| attributes.each { |key, value| copy[key] = yield self[key], value } }
31
- end
32
-
33
- def revalue! attributes = each_pair
34
- return self unless block_given?
35
-
36
- attributes.each { |key, value| self[key] = yield self[key], value }
37
- self
38
- end
39
-
40
18
  def transmute(...) = dup.transmute!(...)
41
19
 
42
20
  def transmute! object, **key_map
data/lib/refinements.rb CHANGED
@@ -6,8 +6,6 @@ require "refinements/data"
6
6
  require "refinements/date_time"
7
7
  require "refinements/hash"
8
8
  require "refinements/io"
9
- require "refinements/log_device"
10
- require "refinements/logger"
11
9
  require "refinements/module"
12
10
  require "refinements/object"
13
11
  require "refinements/pathname"
data/refinements.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "refinements"
5
- spec.version = "12.10.0"
5
+ spec.version = "13.0.0"
6
6
  spec.authors = ["Brooke Kuhlmann"]
7
7
  spec.email = ["brooke@alchemists.io"]
8
8
  spec.homepage = "https://alchemists.io/projects/refinements"
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.signing_key = Gem.default_key_path
23
23
  spec.cert_chain = [Gem.default_cert_path]
24
24
 
25
- spec.required_ruby_version = ">= 3.3", "<= 3.4"
25
+ spec.required_ruby_version = "~> 3.4"
26
26
 
27
27
  spec.files = Dir["*.gemspec", "lib/**/*"]
28
28
  spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinements
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.10.0
4
+ version: 13.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain:
11
10
  - |
@@ -35,9 +34,8 @@ cert_chain:
35
34
  3n5C8/6Zh9DYTkpcwPSuIfAga6wf4nXc9m6JAw8AuMLaiWN/r/2s4zJsUHYERJEu
36
35
  gZGm4JqtuSg8pYjPeIJxS960owq+SfuC+jxqmRA54BisFCv/0VOJi7tiJVY=
37
36
  -----END CERTIFICATE-----
38
- date: 2024-10-22 00:00:00.000000000 Z
37
+ date: 2024-12-27 00:00:00.000000000 Z
39
38
  dependencies: []
40
- description:
41
39
  email:
42
40
  - brooke@alchemists.io
43
41
  executables: []
@@ -55,8 +53,6 @@ files:
55
53
  - lib/refinements/date_time.rb
56
54
  - lib/refinements/hash.rb
57
55
  - lib/refinements/io.rb
58
- - lib/refinements/log_device.rb
59
- - lib/refinements/logger.rb
60
56
  - lib/refinements/module.rb
61
57
  - lib/refinements/object.rb
62
58
  - lib/refinements/pathname.rb
@@ -79,16 +75,12 @@ metadata:
79
75
  label: Refinements
80
76
  rubygems_mfa_required: 'true'
81
77
  source_code_uri: https://github.com/bkuhlmann/refinements
82
- post_install_message:
83
78
  rdoc_options: []
84
79
  require_paths:
85
80
  - lib
86
81
  required_ruby_version: !ruby/object:Gem::Requirement
87
82
  requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '3.3'
91
- - - "<="
83
+ - - "~>"
92
84
  - !ruby/object:Gem::Version
93
85
  version: '3.4'
94
86
  required_rubygems_version: !ruby/object:Gem::Requirement
@@ -97,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
89
  - !ruby/object:Gem::Version
98
90
  version: '0'
99
91
  requirements: []
100
- rubygems_version: 3.5.22
101
- signing_key:
92
+ rubygems_version: 3.6.2
102
93
  specification_version: 4
103
94
  summary: A collection of core object refinements.
104
95
  test_files: []
metadata.gz.sig CHANGED
Binary file
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "logger"
4
- require "refinements/string_io"
5
-
6
- module Refinements
7
- # Provides additional enhancements to a log device.
8
- module LogDevice
9
- using StringIO
10
-
11
- refine ::Logger::LogDevice do
12
- def reread
13
- case dev
14
- when ::File then dev.class.new(dev).read
15
- when ::StringIO then dev.reread
16
- else ""
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "refinements/log_device"
4
-
5
- module Refinements
6
- # Provides additional enhancements to a logger.
7
- module Logger
8
- using LogDevice
9
-
10
- refine ::Logger do
11
- def reread = @logdev.reread
12
-
13
- alias_method :any, :unknown
14
- end
15
- end
16
- end