refinements 7.1.0 → 7.2.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 +1 -2
- data/{LICENSE.md → LICENSE.adoc} +29 -30
- data/README.adoc +302 -0
- data/lib/refinements/arrays.rb +4 -1
- data/lib/refinements/big_decimals.rb +0 -1
- data/lib/refinements/hashes.rb +2 -4
- data/lib/refinements/identity.rb +4 -15
- data/lib/refinements/strings.rb +0 -1
- metadata +22 -21
- metadata.gz.sig +0 -0
- data/README.md +0 -263
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad5be980b8f793ae3267c3903932b56af4d7e0f4e85868086015f7f44209e6e6
|
4
|
+
data.tar.gz: 21fd8437f771085190de49af6f46e08ba3cc1cdd6844649d8e63cde20549b9f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a37bebc4c4ef4f6e0b503601f2728eee8f04c9bcde3b714e9332dac343b62f4281dc4924b178c24a011c2e6ddfcb963e479aab6b0f070fc4bd898a99f98824a
|
7
|
+
data.tar.gz: c33d3b26f9b7c19ec977a36c1904faa888f00884921abad97ac4ca76e14772fda5b87cc2455d46e8c114f4392604f216ff90e06a3648be7c00fa268b77697c44
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
/K��ɿ�^j���$h����k&�������Q@���d�t6N�.�X�c��K�G�Eq�Zs5���8�����$Z��Vl�B�|S��"��o� E��Q�̷�n|��%]�U����I�=3)�ajJ��>�x�
|
1
|
+
�5(�� r��MC��ZdeM�ibhE�uRz������:~h(�>�gl��u+6��%гoA�;�@ ��3�|y�m�n�#��R�p���A��ދ�� >���������o���CH�s�c<�k�.z�[;j�9���:`ٱw��)*��,���5�+鐓�l�2��&*#bᣕ��Kl%��*b�q�ً̘5����x<�U �+&XLϝ�U�a��9��-fz˼���-�@1gݴ��h]����AἍ�Z1)��
|
data/{LICENSE.md → LICENSE.adoc}
RENAMED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
= Apache License
|
2
2
|
|
3
3
|
Version 2.0, January 2004
|
4
4
|
|
@@ -6,7 +6,7 @@ http://www.apache.org/licenses
|
|
6
6
|
|
7
7
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8
8
|
|
9
|
-
|
9
|
+
== 1. Definitions
|
10
10
|
|
11
11
|
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by
|
12
12
|
Sections 1 through 9 of this document.
|
@@ -54,14 +54,14 @@ Contribution."
|
|
54
54
|
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a
|
55
55
|
Contribution has been received by Licensor and subsequently incorporated within the Work.
|
56
56
|
|
57
|
-
|
57
|
+
== 2. Grant of Copyright License
|
58
58
|
|
59
59
|
Subject to the terms and conditions of this License, each Contributor hereby grants to You a
|
60
60
|
perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
61
61
|
reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and
|
62
62
|
distribute the Work and such Derivative Works in Source or Object form.
|
63
63
|
|
64
|
-
|
64
|
+
== 3. Grant of Patent License
|
65
65
|
|
66
66
|
Subject to the terms and conditions of this License, each Contributor hereby grants to You a
|
67
67
|
perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
|
@@ -74,39 +74,38 @@ a Contribution incorporated within the Work constitutes direct or contributory p
|
|
74
74
|
then any patent licenses granted to You under this License for that Work shall terminate as of the
|
75
75
|
date such litigation is filed.
|
76
76
|
|
77
|
-
|
77
|
+
== 4. Redistribution
|
78
78
|
|
79
79
|
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with
|
80
80
|
or without modifications, and in Source or Object form, provided that You meet the following
|
81
81
|
conditions:
|
82
82
|
|
83
|
-
|
83
|
+
. You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
84
84
|
|
85
|
-
|
86
|
-
|
85
|
+
. You must cause any modified files to carry prominent notices stating that You changed the files;
|
86
|
+
and
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
. You must retain, in the Source form of any Derivative Works that You distribute, all copyright,
|
89
|
+
patent, trademark, and attribution notices from the Source form of the Work, excluding those
|
90
|
+
notices that do not pertain to any part of the Derivative Works; and
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
construed as modifying the License.
|
92
|
+
. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works
|
93
|
+
that You distribute must include a readable copy of the attribution notices contained within such
|
94
|
+
NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in
|
95
|
+
at least one of the following places: within a NOTICE text file distributed as part of the
|
96
|
+
Derivative Works; within the Source form or documentation, if provided along with the Derivative
|
97
|
+
Works; or, within a display generated by the Derivative Works, if and wherever such third-party
|
98
|
+
notices normally appear. The contents of the NOTICE file are for informational purposes only and
|
99
|
+
do not modify the License. You may add Your own attribution notices within Derivative Works that
|
100
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such
|
101
|
+
additional attribution notices cannot be construed as modifying the License.
|
103
102
|
|
104
103
|
You may add Your own copyright statement to Your modifications and may provide additional or
|
105
104
|
different license terms and conditions for use, reproduction, or distribution of Your modifications,
|
106
105
|
or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of
|
107
106
|
the Work otherwise complies with the conditions stated in this License.
|
108
107
|
|
109
|
-
|
108
|
+
== 5. Submission of Contributions
|
110
109
|
|
111
110
|
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the
|
112
111
|
Work by You to the Licensor shall be under the terms and conditions of this License, without any
|
@@ -114,13 +113,13 @@ additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
114
113
|
the terms of any separate license agreement you may have executed with Licensor regarding such
|
115
114
|
Contributions.
|
116
115
|
|
117
|
-
|
116
|
+
== 6. Trademarks
|
118
117
|
|
119
118
|
This License does not grant permission to use the trade names, trademarks, service marks, or product
|
120
119
|
names of the Licensor, except as required for reasonable and customary use in describing the origin
|
121
120
|
of the Work and reproducing the content of the NOTICE file.
|
122
121
|
|
123
|
-
|
122
|
+
== 7. Disclaimer of Warranty
|
124
123
|
|
125
124
|
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each
|
126
125
|
Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
@@ -129,7 +128,7 @@ TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. Y
|
|
129
128
|
responsible for determining the appropriateness of using or redistributing the Work and assume any
|
130
129
|
risks associated with Your exercise of permissions under this License.
|
131
130
|
|
132
|
-
|
131
|
+
== 8. Limitation of Liability
|
133
132
|
|
134
133
|
In no event and under no legal theory, whether in tort (including negligence), contract, or
|
135
134
|
otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or
|
@@ -139,7 +138,7 @@ License or out of the use or inability to use the Work (including but not limite
|
|
139
138
|
loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial
|
140
139
|
damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
141
140
|
|
142
|
-
|
141
|
+
== 9. Accepting Warranty or Additional Liability
|
143
142
|
|
144
143
|
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee
|
145
144
|
for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights
|
@@ -151,11 +150,11 @@ additional liability.
|
|
151
150
|
|
152
151
|
END OF TERMS AND CONDITIONS
|
153
152
|
|
154
|
-
Copyright
|
153
|
+
Copyright link:https://www.alchemists.io[Alchemists].
|
155
154
|
|
156
155
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
|
157
|
-
compliance with the License. You may obtain a
|
158
|
-
the License.
|
156
|
+
compliance with the License. You may obtain a link:https://www.apache.org/licenses/LICENSE-2.0[copy]
|
157
|
+
of the License.
|
159
158
|
|
160
159
|
Unless required by applicable law or agreed to in writing, software distributed under the License is
|
161
160
|
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
data/README.adoc
ADDED
@@ -0,0 +1,302 @@
|
|
1
|
+
:toc: macro
|
2
|
+
:toclevels: 5
|
3
|
+
:figure-caption!:
|
4
|
+
|
5
|
+
= Refinements
|
6
|
+
|
7
|
+
[link=http://badge.fury.io/rb/refinements]
|
8
|
+
image::https://badge.fury.io/rb/refinements.svg[Gem Version]
|
9
|
+
[link=https://circleci.com/gh/bkuhlmann/refinements]
|
10
|
+
image::https://circleci.com/gh/bkuhlmann/refinements.svg?style=svg[Circle CI Status]
|
11
|
+
|
12
|
+
A collection of refinements (enhancements) to core Ruby objects.
|
13
|
+
|
14
|
+
toc::[]
|
15
|
+
|
16
|
+
== Features
|
17
|
+
|
18
|
+
* *Arrays*:
|
19
|
+
** `#compress` - Removes `nil` and empty values without modifying itself.
|
20
|
+
** `#compress!` - Removes `nil` and empty values while modifying itself.
|
21
|
+
** `#ring` - Answers a circular array which can enumerate before, current, after elements.
|
22
|
+
* *DateTimes*:
|
23
|
+
** `.utc` - Answers new DateTime object for current UTC date/time.
|
24
|
+
* *BigDecimals*:
|
25
|
+
** `#inspect` - Allows one to inspect a big decimal with numeric representation.
|
26
|
+
* *Files*:
|
27
|
+
** `#name` - Answers the _name_ of file without extension.
|
28
|
+
** `#copy` - Copies an existing file to new file. Both directory structures must exist.
|
29
|
+
** `#rewrite` - When given a file path and a block, it provides the contents of the recently read
|
30
|
+
file for manipulation and immediate writing back to the same file.
|
31
|
+
** `#touch` - Updates the access and modified times of an existing file or creates the file when
|
32
|
+
not existing.
|
33
|
+
* *Hashes*:
|
34
|
+
** `#except` - Answers new hash with given keys removed without modifying calling hash.
|
35
|
+
** `#except!` - Answers new hash with given keys removed while modifying calling hash.
|
36
|
+
** `#symbolize_keys` - Converts keys to symbols without modifying itself.
|
37
|
+
** `#symbolize_keys!` - Converts keys to symbols while modifying itself.
|
38
|
+
** `#deep_merge` - Merges deeply nested hashes together without modifying itself.
|
39
|
+
** `#deep_merge!` - Merges deeply nested hashes together while modifying itself.
|
40
|
+
** `#reverse_merge` - Merges calling hash into passed in hash without modifying calling hash.
|
41
|
+
** `#reverse_merge!` - Merges calling hash into passed in hash while modifying calling hash.
|
42
|
+
* *Pathnames*:
|
43
|
+
** `#rewrite` - When given a block, it provides the contents of the recently read file for
|
44
|
+
manipulation and immediate writing back to the same file.
|
45
|
+
* *Strings*:
|
46
|
+
** `#first` - Answers first character of a string or first set of characters if given a number.
|
47
|
+
** `#last` - Answers last character of a string or last set of characters if given a number.
|
48
|
+
** `#blank?` - Answers `true`/`false` based on whether string is blank or not
|
49
|
+
(i.e. `<space>`, `\n`, `\t`, `\r`).
|
50
|
+
** `#up` - Answers string with only first letter upcased.
|
51
|
+
** `#down` - Answers string with only first letter downcased.
|
52
|
+
** `#camelcase` - Answers a camelcased string. Example: "`ThisIsCamelcase`".
|
53
|
+
** `#snakecase` - Answers a snakecased string. Example: "`this_is_snakecase`".
|
54
|
+
** `#titleize` - Answers titleized string. Example: "`This Is Titleized`".
|
55
|
+
** `#use` - Provides hash value computation, via a block, by using only the keys as arguments to
|
56
|
+
the block.
|
57
|
+
|
58
|
+
== Requirements
|
59
|
+
|
60
|
+
. https://www.ruby-lang.org[Ruby 2.7.x].
|
61
|
+
. A solid understanding of https://www.youtube.com/watch?v=qXC9Gk4dCEw[Ruby refinements and lexical
|
62
|
+
scope].
|
63
|
+
|
64
|
+
== Setup
|
65
|
+
|
66
|
+
=== Production
|
67
|
+
|
68
|
+
To install, run:
|
69
|
+
|
70
|
+
[source,bash]
|
71
|
+
----
|
72
|
+
gem install refinements
|
73
|
+
----
|
74
|
+
|
75
|
+
Add the following to your Gemfile file:
|
76
|
+
|
77
|
+
[source,ruby]
|
78
|
+
----
|
79
|
+
gem "refinements"
|
80
|
+
----
|
81
|
+
|
82
|
+
=== Development
|
83
|
+
|
84
|
+
To contribute, run:
|
85
|
+
|
86
|
+
[source,bash]
|
87
|
+
----
|
88
|
+
git clone https://github.com/bkuhlmann/refinements.git
|
89
|
+
cd refinements
|
90
|
+
bin/setup
|
91
|
+
----
|
92
|
+
|
93
|
+
You can also use the IRB console for direct access to all objects:
|
94
|
+
|
95
|
+
[source,bash]
|
96
|
+
----
|
97
|
+
bin/console
|
98
|
+
----
|
99
|
+
|
100
|
+
== Usage
|
101
|
+
|
102
|
+
=== Requires
|
103
|
+
|
104
|
+
If all refinements are not desired, add the following to your `+Gemfile+` instead:
|
105
|
+
|
106
|
+
[source,ruby]
|
107
|
+
----
|
108
|
+
gem "refinements", require: false
|
109
|
+
----
|
110
|
+
|
111
|
+
…then require the specific refinement, as needed. Example:
|
112
|
+
|
113
|
+
[source,ruby]
|
114
|
+
----
|
115
|
+
require "refinements/arrays"
|
116
|
+
require "refinements/date_times"
|
117
|
+
require "refinements/big_decimals"
|
118
|
+
require "refinements/files"
|
119
|
+
require "refinements/hashes"
|
120
|
+
require "refinements/pathnames"
|
121
|
+
require "refinements/strings"
|
122
|
+
----
|
123
|
+
|
124
|
+
=== Using
|
125
|
+
|
126
|
+
Much like including/extending a module, you’ll need modify your object(s) to use the refinement(s):
|
127
|
+
|
128
|
+
[source,ruby]
|
129
|
+
----
|
130
|
+
class Example
|
131
|
+
using Refinements::Arrays
|
132
|
+
using Refinements::DateTimes
|
133
|
+
using Refinements::BigDecimals
|
134
|
+
using Refinements::Files
|
135
|
+
using Refinements::Hashes
|
136
|
+
using Refinements::Pathnames
|
137
|
+
using Refinements::Strings
|
138
|
+
end
|
139
|
+
----
|
140
|
+
|
141
|
+
=== Examples
|
142
|
+
|
143
|
+
The following sections demonstrate how each refinement enriches your objects with new capabilities.
|
144
|
+
|
145
|
+
==== Array
|
146
|
+
|
147
|
+
[source,ruby]
|
148
|
+
----
|
149
|
+
example = ["An", nil, "", "Example"]
|
150
|
+
example.compress # => ["An", "Example"]
|
151
|
+
example # => ["An", nil, "", "Example"]
|
152
|
+
|
153
|
+
example = ["An", nil, "", "Example"]
|
154
|
+
example.compress! # => ["An", "Example"]
|
155
|
+
example # => ["An", "Example"]
|
156
|
+
|
157
|
+
example = [1, 2, 3]
|
158
|
+
example.ring # => #<Enumerator: ...>
|
159
|
+
example.ring { |(before, current, after)| puts "#{before} #{current} #{after}" }
|
160
|
+
# [3 1 2]
|
161
|
+
# [1 2 3]
|
162
|
+
# [2 3 1]
|
163
|
+
----
|
164
|
+
|
165
|
+
==== DateTime
|
166
|
+
|
167
|
+
[source,ruby]
|
168
|
+
----
|
169
|
+
DateTime.utc # => #<DateTime: 2019-12-31T18:17:00+00:00 ((2458849j,65820s,181867000n),+0s,2299161j)>
|
170
|
+
----
|
171
|
+
|
172
|
+
==== Big Decimal
|
173
|
+
|
174
|
+
[source,ruby]
|
175
|
+
----
|
176
|
+
BigDecimal.new("5.0E-10").inspect # => "#<BigDecimal:3fd3d458fe84 0.0000000005>"
|
177
|
+
----
|
178
|
+
|
179
|
+
==== File
|
180
|
+
|
181
|
+
[source,ruby]
|
182
|
+
----
|
183
|
+
File.rewrite("/test.txt") { |content| content.gsub "[placeholder]", "example" }
|
184
|
+
----
|
185
|
+
|
186
|
+
==== Hash
|
187
|
+
|
188
|
+
[source,ruby]
|
189
|
+
----
|
190
|
+
example = {a: 1, b: 2, c: 3}
|
191
|
+
example.except :a, :b # => {c: 3}
|
192
|
+
example # => {a: 1, b: 2, c: 3}
|
193
|
+
|
194
|
+
example = {a: 1, b: 2, c: 3}
|
195
|
+
example.except! :a, :b # => {c: 3}
|
196
|
+
example # => {c: 3}
|
197
|
+
|
198
|
+
example = {"a" => 1, "b" => 2}
|
199
|
+
example.symbolize_keys # => {a: 1, b: 2}
|
200
|
+
example # => {"a" => 1, "b" => 2}
|
201
|
+
|
202
|
+
example = {"a" => 1, "b" => 2}
|
203
|
+
example.symbolize_keys! # => {a: 1, b: 2}
|
204
|
+
example # => {a: 1, b: 2}
|
205
|
+
|
206
|
+
example = {a: 1, b: 2, c: 3}
|
207
|
+
example.slice :a, :c # => {a: 1, c: 3}
|
208
|
+
example # => {a: 1, b: 2, c: 3}
|
209
|
+
|
210
|
+
example = {a: 1, b: 2, c: 3}
|
211
|
+
example.slice! :a, :c # => {a: 1, c: 3}
|
212
|
+
example # => {a: 1, c: 3}
|
213
|
+
|
214
|
+
example = {a: "A", b: {one: "One", two: "Two"}}
|
215
|
+
example.deep_merge b: {one: 1} # => {a: "A", b: {one: 1, two: "Two"}}
|
216
|
+
example # => {a: "A", b: {one: "One", two: "Two"}}
|
217
|
+
|
218
|
+
example = {a: "A", b: {one: "One", two: "Two"}}
|
219
|
+
example.deep_merge! b: {one: 1} # => {a: "A", b: {one: 1, two: "Two"}}
|
220
|
+
example # => {a: "A", b: {one: 1, two: "Two"}}
|
221
|
+
|
222
|
+
example = {a: 1, b: 2}
|
223
|
+
example.reverse_merge a: 0, c: 3 # => {a: 1, b: 2, c: 3}
|
224
|
+
example # => {a: 1, b: 2}
|
225
|
+
|
226
|
+
example = {a: 1, b: 2}
|
227
|
+
example.reverse_merge! a: 0, c: 3 # => {a: 1, b: 2, c: 3}
|
228
|
+
example # => {a: 1, b: 2, c: 3}
|
229
|
+
|
230
|
+
example = {unit: "221B", street: "Baker Street", city: "London", country: "UK"}
|
231
|
+
example.use { |unit, street| "#{unit} #{street}" } # => "221B Baker Street"
|
232
|
+
----
|
233
|
+
|
234
|
+
==== Pathname
|
235
|
+
|
236
|
+
[source,ruby]
|
237
|
+
----
|
238
|
+
Pathname("test.txt").name # => Pathname("test")
|
239
|
+
|
240
|
+
Pathname("input.txt").copy Pathname("output.txt")
|
241
|
+
|
242
|
+
Pathname("/test.txt").rewrite { |content| content.sub "[placeholder]", "example" }
|
243
|
+
|
244
|
+
Pathname("test.txt").touch
|
245
|
+
Pathname("test.txt").touch accessed_at: Time.now - 1, modified_at: Time.now - 1
|
246
|
+
----
|
247
|
+
|
248
|
+
==== String
|
249
|
+
|
250
|
+
[source,ruby]
|
251
|
+
----
|
252
|
+
"example".first # => "e"
|
253
|
+
"example".first 4 # => "exam"
|
254
|
+
|
255
|
+
"instant".last # => "t"
|
256
|
+
"instant".last 3 # => "ant"
|
257
|
+
|
258
|
+
" \n\t\r".blank? # => true
|
259
|
+
"example".up # => "Example"
|
260
|
+
"EXAMPLE".down # => "eXAMPLE"
|
261
|
+
"this_is_an_example".camelcase # => "ThisIsAnExample"
|
262
|
+
"ThisIsAnExample".snakecase # => "this_is_an_example"
|
263
|
+
"ThisIsAnExample".titleize # => "This Is An Example"
|
264
|
+
----
|
265
|
+
|
266
|
+
== Tests
|
267
|
+
|
268
|
+
To test, run:
|
269
|
+
|
270
|
+
[source,bash]
|
271
|
+
----
|
272
|
+
bundle exec rake
|
273
|
+
----
|
274
|
+
|
275
|
+
== Versioning
|
276
|
+
|
277
|
+
Read link:https://semver.org[Semantic Versioning] for details. Briefly, it means:
|
278
|
+
|
279
|
+
* Major (X.y.z) - Incremented for any backwards incompatible public API changes.
|
280
|
+
* Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
|
281
|
+
* Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.
|
282
|
+
|
283
|
+
== Code of Conduct
|
284
|
+
|
285
|
+
Please note that this project is released with a link:CODE_OF_CONDUCT.adoc[CODE OF CONDUCT]. By
|
286
|
+
participating in this project you agree to abide by its terms.
|
287
|
+
|
288
|
+
== Contributions
|
289
|
+
|
290
|
+
Read link:CONTRIBUTING.adoc[CONTRIBUTING] for details.
|
291
|
+
|
292
|
+
== License
|
293
|
+
|
294
|
+
Read link:LICENSE.adoc[LICENSE] for details.
|
295
|
+
|
296
|
+
== History
|
297
|
+
|
298
|
+
Read link:CHANGES.adoc[CHANGES] for details.
|
299
|
+
|
300
|
+
== Credits
|
301
|
+
|
302
|
+
Engineered by link:https://www.alchemists.io/team/brooke_kuhlmann.html[Brooke Kuhlmann].
|
data/lib/refinements/arrays.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Refinements
|
4
|
-
# Refinements for arrays.
|
5
4
|
module Arrays
|
6
5
|
refine Array do
|
7
6
|
def compress
|
@@ -11,6 +10,10 @@ module Refinements
|
|
11
10
|
def compress!
|
12
11
|
replace compress
|
13
12
|
end
|
13
|
+
|
14
|
+
def ring &block
|
15
|
+
[last, *self, first].each_cons 3, &block
|
16
|
+
end
|
14
17
|
end
|
15
18
|
end
|
16
19
|
end
|
data/lib/refinements/hashes.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Refinements
|
4
|
-
# Refinements for hashes.
|
5
4
|
module Hashes
|
6
5
|
refine Hash do
|
7
6
|
def except *keys
|
@@ -13,12 +12,11 @@ module Refinements
|
|
13
12
|
end
|
14
13
|
|
15
14
|
def symbolize_keys
|
16
|
-
|
15
|
+
reduce({}) { |hash, (key, value)| hash.merge key.to_sym => value }
|
17
16
|
end
|
18
17
|
|
19
18
|
def symbolize_keys!
|
20
|
-
|
21
|
-
self
|
19
|
+
replace symbolize_keys
|
22
20
|
end
|
23
21
|
|
24
22
|
def deep_merge other
|
data/lib/refinements/identity.rb
CHANGED
@@ -3,20 +3,9 @@
|
|
3
3
|
module Refinements
|
4
4
|
# Gem identity information.
|
5
5
|
module Identity
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def self.label
|
11
|
-
"Refinements"
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.version
|
15
|
-
"7.1.0"
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.version_label
|
19
|
-
"#{label} #{version}"
|
20
|
-
end
|
6
|
+
NAME = "refinements"
|
7
|
+
LABEL = "Refinements"
|
8
|
+
VERSION = "7.2.0"
|
9
|
+
VERSION_LABEL = "#{LABEL} #{VERSION}"
|
21
10
|
end
|
22
11
|
end
|
data/lib/refinements/strings.rb
CHANGED
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.
|
4
|
+
version: 7.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brooke Kuhlmann
|
@@ -10,9 +10,9 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
MIIC/
|
14
|
-
|
15
|
-
|
13
|
+
MIIC/jCCAeagAwIBAgIBAzANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBpicm9v
|
14
|
+
a2UvREM9YWxjaGVtaXN0cy9EQz1pbzAeFw0yMDAzMTUxNDQ1MzJaFw0yMTAzMTUx
|
15
|
+
NDQ1MzJaMCUxIzAhBgNVBAMMGmJyb29rZS9EQz1hbGNoZW1pc3RzL0RDPWlvMIIB
|
16
16
|
IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6l1qpXTiomH1RfMRloyw7MiE
|
17
17
|
xyVx/x8Yc3EupdH7uhNaTXQGyORN6aOY//1QXXMHIZ9tW74nZLhesWMSUMYy0XhB
|
18
18
|
brs+KkurHnc9FnEJAbG7ebGvl/ncqZt72nQvaxpDxvuCBHgJAz+8i5wl6FhLw+oT
|
@@ -20,15 +20,15 @@ cert_chain:
|
|
20
20
|
D5vkU0YlAm1r98BymuJlcQ1qdkVEI1d48ph4kcS0S0nv1RiuyVb6TCAR3Nu3VaVq
|
21
21
|
3fPzZKJLZBx67UvXdbdicWPiUR75elI4PXpLIic3xytaF52ZJYyKZCNZJhNwfQID
|
22
22
|
AQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU0nzow9vc
|
23
|
-
2CdikiiE3fJhP/
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
2CdikiiE3fJhP/gY4ggwDQYJKoZIhvcNAQELBQADggEBAIHhAlD3po4sTYqacXaQ
|
24
|
+
XI9jIhrfMy//2PgbHWcETtlJPBeNUbbSNBABcllUHKqYsVDlSvSmss034KSWNR8F
|
25
|
+
bF1GcloicyvcCC4y6IoW4it0COAcdeaaxkxiBSgKdQFpff9REnDlIKK4uQ9lLxIo
|
26
|
+
Y2G5xubiziKZkyfWFuSr67PIjW3Bu673D1JVBArhA1qbgQmYQcy1CkGOjo+iO8Nf
|
27
|
+
7u/QSfBHb+r/bXhKscDgPpnKwbUmvgO2+94zJG9KsrmIydlzYfsD09aXKx0t6Xy4
|
28
|
+
2XV8FRa7/JimI07sPLC13eLY3xd/aYTi85Z782KIA4j0G8XEEWAX0ouBhlXPocZv
|
29
|
+
QWc=
|
30
30
|
-----END CERTIFICATE-----
|
31
|
-
date: 2020-01
|
31
|
+
date: 2020-04-01 00:00:00.000000000 Z
|
32
32
|
dependencies:
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: bundler-audit
|
@@ -134,14 +134,14 @@ dependencies:
|
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
137
|
+
version: '6.0'
|
138
138
|
type: :development
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
144
|
+
version: '6.0'
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
146
|
name: rspec
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -232,11 +232,11 @@ email:
|
|
232
232
|
executables: []
|
233
233
|
extensions: []
|
234
234
|
extra_rdoc_files:
|
235
|
-
- README.
|
236
|
-
- LICENSE.
|
235
|
+
- README.adoc
|
236
|
+
- LICENSE.adoc
|
237
237
|
files:
|
238
|
-
- LICENSE.
|
239
|
-
- README.
|
238
|
+
- LICENSE.adoc
|
239
|
+
- README.adoc
|
240
240
|
- lib/refinements.rb
|
241
241
|
- lib/refinements/arrays.rb
|
242
242
|
- lib/refinements/big_decimals.rb
|
@@ -246,13 +246,14 @@ files:
|
|
246
246
|
- lib/refinements/identity.rb
|
247
247
|
- lib/refinements/pathnames.rb
|
248
248
|
- lib/refinements/strings.rb
|
249
|
-
homepage: https://
|
249
|
+
homepage: https://www.alchemists.io/projects/refinements
|
250
250
|
licenses:
|
251
251
|
- Apache-2.0
|
252
252
|
metadata:
|
253
|
-
source_code_uri: https://github.com/bkuhlmann/refinements
|
254
|
-
changelog_uri: https://github.com/bkuhlmann/refinements/blob/master/CHANGES.md
|
255
253
|
bug_tracker_uri: https://github.com/bkuhlmann/refinements/issues
|
254
|
+
changelog_uri: https://www.alchemists.io/projects/refinements/changes.html
|
255
|
+
documentation_uri: https://www.alchemists.io/projects/refinements
|
256
|
+
source_code_uri: https://github.com/bkuhlmann/refinements
|
256
257
|
post_install_message:
|
257
258
|
rdoc_options: []
|
258
259
|
require_paths:
|
metadata.gz.sig
CHANGED
Binary file
|
data/README.md
DELETED
@@ -1,263 +0,0 @@
|
|
1
|
-
<p align="center">
|
2
|
-
<img src="refinements.png" alt="Refinements Icon"/>
|
3
|
-
</p>
|
4
|
-
|
5
|
-
# Refinements
|
6
|
-
|
7
|
-
[![Gem Version](https://badge.fury.io/rb/refinements.svg)](http://badge.fury.io/rb/refinements)
|
8
|
-
[![Code Climate Maintainability](https://api.codeclimate.com/v1/badges/98be62123a95d5ac32d2/maintainability)](https://codeclimate.com/github/bkuhlmann/refinements/maintainability)
|
9
|
-
[![Code Climate Test Coverage](https://api.codeclimate.com/v1/badges/98be62123a95d5ac32d2/test_coverage)](https://codeclimate.com/github/bkuhlmann/refinements/test_coverage)
|
10
|
-
[![Circle CI Status](https://circleci.com/gh/bkuhlmann/refinements.svg?style=svg)](https://circleci.com/gh/bkuhlmann/refinements)
|
11
|
-
|
12
|
-
A collection of refinements (enhancements) to core Ruby objects.
|
13
|
-
|
14
|
-
<!-- Tocer[start]: Auto-generated, don't remove. -->
|
15
|
-
|
16
|
-
## Table of Contents
|
17
|
-
|
18
|
-
- [Features](#features)
|
19
|
-
- [Requirements](#requirements)
|
20
|
-
- [Setup](#setup)
|
21
|
-
- [Usage](#usage)
|
22
|
-
- [Requires](#requires)
|
23
|
-
- [Using](#using)
|
24
|
-
- [Examples](#examples)
|
25
|
-
- [Array](#array)
|
26
|
-
- [DateTime](#datetime)
|
27
|
-
- [Big Decimal](#big-decimal)
|
28
|
-
- [File](#file)
|
29
|
-
- [Hash](#hash)
|
30
|
-
- [Pathname](#pathname)
|
31
|
-
- [String](#string)
|
32
|
-
- [Tests](#tests)
|
33
|
-
- [Versioning](#versioning)
|
34
|
-
- [Code of Conduct](#code-of-conduct)
|
35
|
-
- [Contributions](#contributions)
|
36
|
-
- [License](#license)
|
37
|
-
- [History](#history)
|
38
|
-
- [Credits](#credits)
|
39
|
-
|
40
|
-
<!-- Tocer[finish]: Auto-generated, don't remove. -->
|
41
|
-
|
42
|
-
## Features
|
43
|
-
|
44
|
-
- Provides Array refinements:
|
45
|
-
- `#compress` - Removes `nil` and empty values without modifying itself.
|
46
|
-
- `#compress!` - Removes `nil` and empty values while modifying itself.
|
47
|
-
- Provides DateTime refinements:
|
48
|
-
- `.utc` - Answers new DateTime object for current UTC date/time.
|
49
|
-
- Provides BigDecimal refinements:
|
50
|
-
- `#inspect` - Allows one to inspect a big decimal with numeric representation.
|
51
|
-
- Provides File refinements:
|
52
|
-
- `#name` - Answers the *name* of file without extension.
|
53
|
-
- `#copy` - Copies an existing file to new file. Both directory structures must exist.
|
54
|
-
- `#rewrite` - When given a file path and a block, it provides the contents of the recently read
|
55
|
-
file for manipulation and immediate writing back to the same file.
|
56
|
-
- `#touch` - Updates the access and modified times of an existing file or creates the file when
|
57
|
-
not existing.
|
58
|
-
- Provides Hash refinements:
|
59
|
-
- `#except` - Answers new hash with given keys removed without modifying calling hash.
|
60
|
-
- `#except!` - Answers new hash with given keys removed while modifying calling hash.
|
61
|
-
- `#symbolize_keys` - Converts keys to symbols without modifying itself.
|
62
|
-
- `#symbolize_keys!` - Converts keys to symbols while modifying itself.
|
63
|
-
- `#deep_merge` - Merges deeply nested hashes together without modifying itself.
|
64
|
-
- `#deep_merge!` - Merges deeply nested hashes together while modifying itself.
|
65
|
-
- `#reverse_merge` - Merges calling hash into passed in hash without modifying calling hash.
|
66
|
-
- `#reverse_merge!` - Merges calling hash into passed in hash while modifying calling hash.
|
67
|
-
- Provides Pathname refinements:
|
68
|
-
- `#rewrite` - When given a block, it provides the contents of the recently read file for
|
69
|
-
manipulation and immediate writing back to the same file.
|
70
|
-
- Provides String refinements:
|
71
|
-
- `#first` - Answers first character of a string or first set of characters if given a number.
|
72
|
-
- `#last` - Answers last character of a string or last set of characters if given a number.
|
73
|
-
- `#blank?` - Answers `true`/`false` based on whether string is blank or not (i.e. `<space>`,
|
74
|
-
`\n`, `\t`, `\r`).
|
75
|
-
- `#up` - Answers string with only first letter upcased.
|
76
|
-
- `#down` - Answers string with only first letter downcased.
|
77
|
-
- `#camelcase` - Answers a camelcased string. Example: "ThisIsCamelcase".
|
78
|
-
- `#snakecase` - Answers a snakecased string. Example: "this_is_snakecase".
|
79
|
-
- `#titleize` - Answers titleized string. Example: "This Is Titleized".
|
80
|
-
- `#use` - Provides hash value computation, via a block, by using
|
81
|
-
only the keys as arguments to the block.
|
82
|
-
|
83
|
-
## Requirements
|
84
|
-
|
85
|
-
1. [Ruby 2.7.x](https://www.ruby-lang.org).
|
86
|
-
1. A solid understanding of [Ruby refinements and lexical scope](https://www.youtube.com/watch?v=qXC9Gk4dCEw).
|
87
|
-
|
88
|
-
## Setup
|
89
|
-
|
90
|
-
Type the following to install:
|
91
|
-
|
92
|
-
gem install refinements
|
93
|
-
|
94
|
-
Add the following to your Gemfile file:
|
95
|
-
|
96
|
-
gem "refinements"
|
97
|
-
|
98
|
-
## Usage
|
99
|
-
|
100
|
-
### Requires
|
101
|
-
|
102
|
-
If all refinements are not desired, add the following to your `Gemfile` instead:
|
103
|
-
|
104
|
-
gem "refinements", require: false
|
105
|
-
|
106
|
-
...then require the specific refinement, as needed. Example:
|
107
|
-
|
108
|
-
require "refinements/arrays"
|
109
|
-
require "refinements/date_times"
|
110
|
-
require "refinements/big_decimals"
|
111
|
-
require "refinements/files"
|
112
|
-
require "refinements/hashes"
|
113
|
-
require "refinements/pathnames"
|
114
|
-
require "refinements/strings"
|
115
|
-
|
116
|
-
### Using
|
117
|
-
|
118
|
-
Much like including/extending a module, you'll need modify your object(s) to use the refinement(s):
|
119
|
-
|
120
|
-
class Example
|
121
|
-
using Refinements::Arrays
|
122
|
-
using Refinements::DateTimes
|
123
|
-
using Refinements::BigDecimals
|
124
|
-
using Refinements::Files
|
125
|
-
using Refinements::Hashes
|
126
|
-
using Refinements::Pathnames
|
127
|
-
using Refinements::Strings
|
128
|
-
end
|
129
|
-
|
130
|
-
### Examples
|
131
|
-
|
132
|
-
The following sections demonstrate how each refinement enriches your objects with new capabilities.
|
133
|
-
|
134
|
-
#### Array
|
135
|
-
|
136
|
-
example = ["An", nil, "", "Example"]
|
137
|
-
example.compress # => ["An", "Example"]
|
138
|
-
example # => ["An", nil, "", "Example"]
|
139
|
-
|
140
|
-
example = ["An", nil, "", "Example"]
|
141
|
-
example.compress! # => ["An", "Example"]
|
142
|
-
example # => ["An", "Example"]
|
143
|
-
|
144
|
-
#### DateTime
|
145
|
-
|
146
|
-
DateTime.utc # => #<DateTime: 2019-12-31T18:17:00+00:00 ((2458849j,65820s,181867000n),+0s,2299161j)>
|
147
|
-
|
148
|
-
#### Big Decimal
|
149
|
-
|
150
|
-
BigDecimal.new("5.0E-10").inspect # => "#<BigDecimal:3fd3d458fe84 0.0000000005>"
|
151
|
-
|
152
|
-
#### File
|
153
|
-
|
154
|
-
File.rewrite("/test.txt") { |content| content.gsub "[placeholder]", "example" }
|
155
|
-
|
156
|
-
#### Hash
|
157
|
-
|
158
|
-
example = {a: 1, b: 2, c: 3}
|
159
|
-
example.except :a, :b # => {c: 3}
|
160
|
-
example # => {a: 1, b: 2, c: 3}
|
161
|
-
|
162
|
-
example = {a: 1, b: 2, c: 3}
|
163
|
-
example.except! :a, :b # => {c: 3}
|
164
|
-
example # => {c: 3}
|
165
|
-
|
166
|
-
example = {"a" => 1, "b" => 2}
|
167
|
-
example.symbolize_keys # => {a: 1, b: 2}
|
168
|
-
example # => {"a" => 1, "b" => 2}
|
169
|
-
|
170
|
-
example = {"a" => 1, "b" => 2}
|
171
|
-
example.symbolize_keys! # => {a: 1, b: 2}
|
172
|
-
example # => {a: 1, b: 2}
|
173
|
-
|
174
|
-
example = {a: 1, b: 2, c: 3}
|
175
|
-
example.slice :a, :c # => {a: 1, c: 3}
|
176
|
-
example # => {a: 1, b: 2, c: 3}
|
177
|
-
|
178
|
-
example = {a: 1, b: 2, c: 3}
|
179
|
-
example.slice! :a, :c # => {a: 1, c: 3}
|
180
|
-
example # => {a: 1, c: 3}
|
181
|
-
|
182
|
-
example = {a: "A", b: {one: "One", two: "Two"}}
|
183
|
-
example.deep_merge b: {one: 1} # => {a: "A", b: {one: 1, two: "Two"}}
|
184
|
-
example # => {a: "A", b: {one: "One", two: "Two"}}
|
185
|
-
|
186
|
-
example = {a: "A", b: {one: "One", two: "Two"}}
|
187
|
-
example.deep_merge! b: {one: 1} # => {a: "A", b: {one: 1, two: "Two"}}
|
188
|
-
example # => {a: "A", b: {one: 1, two: "Two"}}
|
189
|
-
|
190
|
-
example = {a: 1, b: 2}
|
191
|
-
example.reverse_merge a: 0, c: 3 # => {a: 1, b: 2, c: 3}
|
192
|
-
example # => {a: 1, b: 2}
|
193
|
-
|
194
|
-
example = {a: 1, b: 2}
|
195
|
-
example.reverse_merge! a: 0, c: 3 # => {a: 1, b: 2, c: 3}
|
196
|
-
example # => {a: 1, b: 2, c: 3}
|
197
|
-
|
198
|
-
example = {unit: "221B", street: "Baker Street", city: "London", country: "UK"}
|
199
|
-
example.use { |unit, street| "#{unit} #{street}" } # => "221B Baker Street"
|
200
|
-
|
201
|
-
#### Pathname
|
202
|
-
|
203
|
-
Pathname("test.txt").name # => Pathname("test")
|
204
|
-
|
205
|
-
Pathname("input.txt").copy Pathname("output.txt")
|
206
|
-
|
207
|
-
Pathname("/test.txt").rewrite { |content| content.sub "[placeholder]", "example" }
|
208
|
-
|
209
|
-
Pathname("test.txt").touch
|
210
|
-
Pathname("test.txt").touch accessed_at: Time.now - 1, modified_at: Time.now - 1
|
211
|
-
|
212
|
-
#### String
|
213
|
-
|
214
|
-
"example".first # => "e"
|
215
|
-
"example".first 4 # => "exam"
|
216
|
-
|
217
|
-
"instant".last # => "t"
|
218
|
-
"instant".last 3 # => "ant"
|
219
|
-
|
220
|
-
" \n\t\r".blank? # => true
|
221
|
-
"example".up # => "Example"
|
222
|
-
"EXAMPLE".down # => "eXAMPLE"
|
223
|
-
"this_is_an_example".camelcase # => "ThisIsAnExample"
|
224
|
-
"ThisIsAnExample".snakecase # => "this_is_an_example"
|
225
|
-
"ThisIsAnExample".titleize # => "This Is An Example"
|
226
|
-
|
227
|
-
## Tests
|
228
|
-
|
229
|
-
To test, run:
|
230
|
-
|
231
|
-
bundle exec rake
|
232
|
-
|
233
|
-
## Versioning
|
234
|
-
|
235
|
-
Read [Semantic Versioning](https://semver.org) for details. Briefly, it means:
|
236
|
-
|
237
|
-
- Major (X.y.z) - Incremented for any backwards incompatible public API changes.
|
238
|
-
- Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
|
239
|
-
- Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.
|
240
|
-
|
241
|
-
## Code of Conduct
|
242
|
-
|
243
|
-
Please note that this project is released with a [CODE OF CONDUCT](CODE_OF_CONDUCT.md). By
|
244
|
-
participating in this project you agree to abide by its terms.
|
245
|
-
|
246
|
-
## Contributions
|
247
|
-
|
248
|
-
Read [CONTRIBUTING](CONTRIBUTING.md) for details.
|
249
|
-
|
250
|
-
## License
|
251
|
-
|
252
|
-
Copyright 2015 [Alchemists](https://www.alchemists.io).
|
253
|
-
Read [LICENSE](LICENSE.md) for details.
|
254
|
-
|
255
|
-
## History
|
256
|
-
|
257
|
-
Read [CHANGES](CHANGES.md) for details.
|
258
|
-
Built with [Gemsmith](https://github.com/bkuhlmann/gemsmith).
|
259
|
-
|
260
|
-
## Credits
|
261
|
-
|
262
|
-
Developed by [Brooke Kuhlmann](https://www.alchemists.io) at
|
263
|
-
[Alchemists](https://www.alchemists.io).
|