refinements 6.2.2 → 6.3.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: d5ba775099d5db3e1c9d5cc47aa06412cc0adeddfbfc52f6cf8862f13af7441a
4
- data.tar.gz: 3ee7c50aa7c658d0eab3dba89079bfe34c1b8c36935a5747248956fc27444e5e
3
+ metadata.gz: b1ea3f558caa4371babea8a3cf9653d95a785575456cc6be4b043f5811984c49
4
+ data.tar.gz: cf99c530f40b36cc5f14143e75cb781d75bd7d3c8e79387e5ea76c89c95bb48d
5
5
  SHA512:
6
- metadata.gz: 24d00666e8499824b2434a49b145811f9b227c7990c1dd83dcacb369869636b445564d14027893a7ed8b4c661619101bfa285985a2916757ffbfa6115b0f9b74
7
- data.tar.gz: 3ef9f9fc3b89754eca711a5152bbef5ac2bc5cbc5ad320d147f6585f699df6ff097e718f7de5ca498b0e269b2b686b1bc18f8f7a94c162504cff0ba8252cbe4d
6
+ metadata.gz: 3074e9fbfeb98ca10cbed67f38bb7daf103898e570884f49eee277337799b165058dfff0210bcb87d5472193f4b02cd39d0dc10211ab492c94b5d7ac3d73d966
7
+ data.tar.gz: 70aec9d111a40cd8d0d965de5f6b43f7482210b1101b678785b14635145ebc587ed4789dad04053092a9bd134ea2834873b4da8f5ec9cc52db46687549f5a691
checksums.yaml.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -24,7 +24,9 @@ Provides additional enhancements (refinements) to core Ruby objects.
24
24
  - [Examples](#examples)
25
25
  - [Array](#array)
26
26
  - [Big Decimal](#big-decimal)
27
+ - [File](#file)
27
28
  - [Hash](#hash)
29
+ - [Pathname](#pathname)
28
30
  - [String](#string)
29
31
  - [Tests](#tests)
30
32
  - [Versioning](#versioning)
@@ -43,6 +45,9 @@ Provides additional enhancements (refinements) to core Ruby objects.
43
45
  - `#compress!` - Removes `nil` and empty values while modifying itself.
44
46
  - Provides BigDecimal refinements:
45
47
  - `#inspect` - Allows one to inspect a big decimal with numeric representation.
48
+ - Provides File refinements:
49
+ - `.rewrite` - When given a file path and a block, it provides the contents of the recently read
50
+ file for manipulation and immediate writing back to the same file.
46
51
  - Provides Hash refinements:
47
52
  - `#except` - Answers new hash with given keys removed without modifying calling hash.
48
53
  - `#except!` - Answers new hash with given keys removed while modifying calling hash.
@@ -52,6 +57,9 @@ Provides additional enhancements (refinements) to core Ruby objects.
52
57
  - `#deep_merge!` - Merges deeply nested hashes together while modifying itself.
53
58
  - `#reverse_merge` - Merges calling hash into passed in hash without modifying calling hash.
54
59
  - `#reverse_merge!` - Merges calling hash into passed in hash while modifying calling hash.
60
+ - Provides Pathname refinements:
61
+ - `#rewrite` - When given a block, it provides the contents of the recently read file for
62
+ manipulation and immediate writing back to the same file.
55
63
  - Provides String refinements:
56
64
  - `#first` - Answers first character of a string or first set of characters if given a number.
57
65
  - `#last` - Answers last character of a string or last set of characters if given a number.
@@ -92,8 +100,9 @@ If all refinements are not desired, add the following to your `Gemfile` instead:
92
100
 
93
101
  require "refinements/arrays"
94
102
  require "refinements/big_decimals"
103
+ require "refinements/files"
95
104
  require "refinements/hashes"
96
- require "refinements/objects"
105
+ require "refinements/pathnames"
97
106
  require "refinements/strings"
98
107
 
99
108
  ### Using
@@ -103,8 +112,9 @@ Much like including/extending a module, you'll need modify your object(s) to use
103
112
  class Example
104
113
  using Refinements::Arrays
105
114
  using Refinements::BigDecimals
115
+ using Refinements::Files
106
116
  using Refinements::Hashes
107
- using Refinements::Objects
117
+ using Refinements::Pathnames
108
118
  using Refinements::Strings
109
119
  end
110
120
 
@@ -124,8 +134,11 @@ The following sections demonstrate how each refinement enriches your objects wit
124
134
 
125
135
  #### Big Decimal
126
136
 
127
- big = BigDecimal.new "5.0E-10"
128
- big.inspect # => "#<BigDecimal:3fd3d458fe84 0.0000000005>"
137
+ BigDecimal.new("5.0E-10").inspect # => "#<BigDecimal:3fd3d458fe84 0.0000000005>"
138
+
139
+ #### File
140
+
141
+ File.rewrite("/test.txt") { |content| content.gsub "[placeholder]", "example" }
129
142
 
130
143
  #### Hash
131
144
 
@@ -172,6 +185,10 @@ The following sections demonstrate how each refinement enriches your objects wit
172
185
  example = {unit: "221B", street: "Baker Street", city: "London", country: "UK"}
173
186
  example.use { |unit, street| "#{unit} #{street}" } # => "221B Baker Street"
174
187
 
188
+ #### Pathname
189
+
190
+ Pathname("/test.txt").rewrite { |content| content.sub "[placeholder]", "example" }
191
+
175
192
  #### String
176
193
 
177
194
  "example".first # => "e"
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Refinements
4
+ module Files
5
+ refine File.singleton_class do
6
+ def rewrite path
7
+ read(path).then { |content| write path, yield(content) }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -12,7 +12,7 @@ module Refinements
12
12
  end
13
13
 
14
14
  def self.version
15
- "6.2.2"
15
+ "6.3.0"
16
16
  end
17
17
 
18
18
  def self.version_label
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+
5
+ module Refinements
6
+ module Pathnames
7
+ refine Pathname do
8
+ def rewrite
9
+ read.then { |content| write yield(content) }
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/refinements.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "refinements/identity"
3
4
  require "refinements/arrays"
4
5
  require "refinements/big_decimals"
6
+ require "refinements/files"
5
7
  require "refinements/hashes"
6
- require "refinements/identity"
8
+ require "refinements/pathnames"
7
9
  require "refinements/strings"
data.tar.gz.sig CHANGED
Binary file
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: 6.2.2
4
+ version: 6.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  dKvURM+1PwDCzC5tvRwjhUJIizau6+MtkFCvJHmaAj1aZL3odcPejHj5Hxt/0CUW
29
29
  y84=
30
30
  -----END CERTIFICATE-----
31
- date: 2019-06-01 00:00:00.000000000 Z
31
+ date: 2019-07-07 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: awesome_print
@@ -218,14 +218,14 @@ dependencies:
218
218
  requirements:
219
219
  - - "~>"
220
220
  - !ruby/object:Gem::Version
221
- version: '1.3'
221
+ version: '1.4'
222
222
  type: :development
223
223
  prerelease: false
224
224
  version_requirements: !ruby/object:Gem::Requirement
225
225
  requirements:
226
226
  - - "~>"
227
227
  - !ruby/object:Gem::Version
228
- version: '1.3'
228
+ version: '1.4'
229
229
  - !ruby/object:Gem::Dependency
230
230
  name: rubocop-rspec
231
231
  requirement: !ruby/object:Gem::Requirement
@@ -282,8 +282,10 @@ files:
282
282
  - lib/refinements.rb
283
283
  - lib/refinements/arrays.rb
284
284
  - lib/refinements/big_decimals.rb
285
+ - lib/refinements/files.rb
285
286
  - lib/refinements/hashes.rb
286
287
  - lib/refinements/identity.rb
288
+ - lib/refinements/pathnames.rb
287
289
  - lib/refinements/strings.rb
288
290
  homepage: https://github.com/bkuhlmann/refinements
289
291
  licenses:
@@ -307,7 +309,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
307
309
  - !ruby/object:Gem::Version
308
310
  version: '0'
309
311
  requirements: []
310
- rubygems_version: 3.0.3
312
+ rubygems_version: 3.0.4
311
313
  signing_key:
312
314
  specification_version: 4
313
315
  summary: Provides additional enhancements (refinements) to core Ruby objects.
metadata.gz.sig CHANGED
Binary file