refinements 1.0.0 → 2.0.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
  SHA1:
3
- metadata.gz: 187d41db156d487f8f558ff6479bdaf1b5529175
4
- data.tar.gz: 3944401486fe06119d64a1412bb64a23c12653fb
3
+ metadata.gz: 17b47190dc2dd923e2970e7e78a2cb449a02b570
4
+ data.tar.gz: b98ff991a80234011b9032cb37ab884f18517483
5
5
  SHA512:
6
- metadata.gz: dedc8913cb29503b6589cede6211caef97708a977793c612374abb00b8d72ed1100cce3f7bd7be441dcd5ebaa7d02ef954c29f1ac6810aa34902ab9b14e30df8
7
- data.tar.gz: 69caac9d19cb287026da1fbb992dfa6ae8b9d58efe07baa01ec263fe7f5f3ad1ee534da2508bb8a8f15da65e4e7ec7baf9bc2153b87794c2b57f14a29d1b124d
6
+ metadata.gz: 92469e4d6ad36f32fc2cdb84303c286863831875caa144d3859d4d21d683f3ab8b6ef347e59ff4e364d588d5585613fd374b80cf352e007fc572f79447ca3b16
7
+ data.tar.gz: 056235b52753623d09440e7d3e99b660dfeb52e9eab9986d70686a5fdfe68925ee96ccc524cec11e33798e95bc05990b3e32bb364efb39992c98ef18108e49a2
data/README.md CHANGED
@@ -1,35 +1,10 @@
1
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
2
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
3
- # Table of Contents
4
-
5
- - [Refinements](#refinements)
6
- - [Table of Contents](#table-of-contents)
7
- - [Features](#features)
8
- - [Requirements](#requirements)
9
- - [Setup](#setup)
10
- - [Usage](#usage)
11
- - [Requires](#requires)
12
- - [Using](#using)
13
- - [Examples](#examples)
14
- - [Array](#array)
15
- - [Big Decimal](#big-decimal)
16
- - [Tests](#tests)
17
- - [Versioning](#versioning)
18
- - [Code of Conduct](#code-of-conduct)
19
- - [Contributions](#contributions)
20
- - [License](#license)
21
- - [History](#history)
22
- - [Credits](#credits)
23
-
24
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
25
-
26
1
  # Refinements
27
2
 
28
3
  [![Gem Version](https://badge.fury.io/rb/refinements.svg)](http://badge.fury.io/rb/refinements)
29
4
  [![Code Climate GPA](https://codeclimate.com/github/bkuhlmann/refinements.svg)](https://codeclimate.com/github/bkuhlmann/refinements)
30
5
  [![Code Climate Coverage](https://codeclimate.com/github/bkuhlmann/refinements/coverage.svg)](https://codeclimate.com/github/bkuhlmann/refinements)
31
6
  [![Gemnasium Status](https://gemnasium.com/bkuhlmann/refinements.svg)](https://gemnasium.com/bkuhlmann/refinements)
32
- [![Travis CI Status](https://secure.travis-ci.org/bkuhlmann/refinements.svg)](http://travis-ci.org/bkuhlmann/refinements)
7
+ [![Travis CI Status](https://secure.travis-ci.org/bkuhlmann/refinements.svg)](https://travis-ci.org/bkuhlmann/refinements)
33
8
  [![Patreon](https://img.shields.io/badge/patreon-donate-brightgreen.svg)](https://www.patreon.com/bkuhlmann)
34
9
 
35
10
  Provides a collection of refinements for core Ruby objects.
@@ -45,8 +20,9 @@ Provides a collection of refinements for core Ruby objects.
45
20
  - [Requires](#requires)
46
21
  - [Using](#using)
47
22
  - [Examples](#examples)
48
- - [Array](#array)
49
23
  - [Big Decimal](#big-decimal)
24
+ - [Array](#array)
25
+ - [Hash](#hash)
50
26
  - [Tests](#tests)
51
27
  - [Versioning](#versioning)
52
28
  - [Code of Conduct](#code-of-conduct)
@@ -59,21 +35,27 @@ Provides a collection of refinements for core Ruby objects.
59
35
 
60
36
  # Features
61
37
 
62
- - Adds Array refinements:
63
- - `Array#compress` - Removes nil and empty values without modifying original values.
64
- - `Array#compress!` - Removes nil and empty values and modifies original values.
65
38
  - Adds BigDecimal refinements:
66
- - `BigDecimal#inspect` - Allows one to inspect a big decimal with numeric representation.
39
+ - `BigDecimal#inspect` - Allows one to inspect a big decimal with numeric representation.
40
+ - Adds Array refinements:
41
+ - `Array#compress` - Removes nil and empty values without modifying itself.
42
+ - `Array#compress!` - Removes nil and empty values and modifies itself.
43
+ - Adds Hash refinements:
44
+ - `#deep_merge` - Merges deeply nested hashes together without itself.
45
+ - `#deep_merge!` - Merges deeply nested hashes together and modifies itself.
46
+ - `#reverse_merge` - Merges calling hash into passed in hash without modifying calling hash.
47
+ - `#reverse_merge!` - Merges calling hash into passed in hash and modifies calling hash.
67
48
 
68
49
  # Requirements
69
50
 
70
- 0. [MRI 2.x.x](http://www.ruby-lang.org).
51
+ 0. [MRI 2.3.x](https://www.ruby-lang.org).
52
+ 0. A solid understanding of [Ruby refinements and lexical scope](https://www.youtube.com/watch?v=qXC9Gk4dCEw).
71
53
 
72
54
  # Setup
73
55
 
74
56
  For a secure install, type the following from the command line (recommended):
75
57
 
76
- gem cert --add <(curl -Ls http://www.my-website.com/gem-public.pem)
58
+ gem cert --add <(curl -Ls https://www.my-website.com/gem-public.pem)
77
59
  gem install refinements --trust-policy MediumSecurity
78
60
 
79
61
  NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while
@@ -95,8 +77,9 @@ Due to this gem being a collection of Ruby refinements, none of the refinements
95
77
  reduce code bloat for your app. Instead, require the specific requirement for the code that needs it. You'll want to
96
78
  require one or all of the following:
97
79
 
98
- require "refinements/array_extensions"
99
80
  require "refinements/big_decimal_extensions"
81
+ require "refinements/array_extensions"
82
+ require "refinements/hash_extensions"
100
83
 
101
84
  ## Using
102
85
 
@@ -104,8 +87,9 @@ In addition to requiring the appropriate refinement file for the code that needs
104
87
  refinement by using the `using` keyword within your object. You'll want to use one or all of the following:
105
88
 
106
89
  class Example
107
- using Refinements::ArrayExtensions
108
90
  using Refinements::BigDecimalExtensions
91
+ using Refinements::ArrayExtensions
92
+ using Refinements::HashExtensions
109
93
  end
110
94
 
111
95
  ## Examples
@@ -113,6 +97,11 @@ refinement by using the `using` keyword within your object. You'll want to use o
113
97
  With the appropriate refinements required and used within your objects, the following sections demonstrates how each
114
98
  refinement enriches your objects with new capabilities.
115
99
 
100
+ ### Big Decimal
101
+
102
+ big = BigDecimal.new "5.0E-10"
103
+ big.inspect # => "#<BigDecimal:3fd3d458fe84 0.0000000005>"
104
+
116
105
  ### Array
117
106
 
118
107
  example = ["An", nil, "", "Example"]
@@ -123,10 +112,23 @@ refinement enriches your objects with new capabilities.
123
112
  example.compress! # => ["An", "Example"]
124
113
  example # => ["An", "Example"]
125
114
 
126
- ### Big Decimal
115
+ ### Hash
127
116
 
128
- big = BigDecimal.new "5.0E-10"
129
- big.inspect # => "#<BigDecimal:3fd3d458fe84 0.0000000005>"
117
+ example = {a: "A", b: {one: "One", two: "Two"}}
118
+ example.deep_merge b: {one: 1} # => {a: "A", b: {one: 1, two: "Two"}}
119
+ example # => {a: "A", b: {one: "One", two: "Two"}}
120
+
121
+ example = {a: "A", b: {one: "One", two: "Two"}}
122
+ example.deep_merge! b: {one: 1} # => {a: "A", b: {one: 1, two: "Two"}}
123
+ example # => {a: "A", b: {one: 1, two: "Two"}}
124
+
125
+ example = {a: 1, b: 2}
126
+ example.reverse_merge a: 0, c: 3 # => {a: 1, b: 2, c: 3}
127
+ example # => {a: 1, b: 2}
128
+
129
+ example = {a: 1, b: 2}
130
+ example.reverse_merge! a: 0, c: 3 # => {a: 1, b: 2, c: 3}
131
+ example # => {a: 1, b: 2, c: 3}
130
132
 
131
133
  # Tests
132
134
 
@@ -0,0 +1,32 @@
1
+ module Refinements
2
+ # Refinements for Hashes.
3
+ module HashExtensions
4
+ refine Hash do
5
+ def deep_merge other_hash
6
+ dup.deep_merge! other_hash
7
+ end
8
+
9
+ def deep_merge! other_hash
10
+ other_hash.each.with_object self do |(other_key, other_value), original_hash|
11
+ current_value = original_hash[other_key]
12
+ original_hash[other_key] = deep_merge_value current_value, other_value
13
+ end
14
+ end
15
+
16
+ def reverse_merge other_hash
17
+ other_hash.merge self
18
+ end
19
+
20
+ def reverse_merge! other_hash
21
+ merge!(other_hash) { |_, left_value, _| left_value }
22
+ end
23
+
24
+ private
25
+
26
+ def deep_merge_value current_value, other_value
27
+ return current_value.deep_merge(other_value) if current_value.is_a?(Hash) && other_value.is_a?(Hash)
28
+ other_value
29
+ end
30
+ end
31
+ end
32
+ end
@@ -10,7 +10,7 @@ module Refinements
10
10
  end
11
11
 
12
12
  def self.version
13
- "1.0.0"
13
+ "2.0.0"
14
14
  end
15
15
 
16
16
  def self.label_version
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ desc "Open IRB console for gem development environment"
4
+ task :console do
5
+ require "irb"
6
+ require "refinements"
7
+ ARGV.clear
8
+ IRB.start
9
+ end
metadata CHANGED
@@ -1,36 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinements
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDeDCCAmCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBBMQ8wDQYDVQQDDAZicm9v
14
- a2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQBGRYC
15
- aW8wHhcNMTUwNzA1MTQ1MzExWhcNMTYwNzA0MTQ1MzExWjBBMQ8wDQYDVQQDDAZi
16
- cm9va2UxGjAYBgoJkiaJk/IsZAEZFgphbGNoZW1pc3RzMRIwEAYKCZImiZPyLGQB
17
- GRYCaW8wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCzhOVcvLGBCceM
18
- PppVpJLUKsnskWzc1VqBXmv30feKNw+MOxMQaDsIP421qwqGO/2JHY60Kuobssk+
19
- 8/wqZkVFF/FFKxoQjuhlhc+VWLm8jWgXd4N1kwO2yytscQTzxc5qXarwA+36fqVH
20
- RhBAHhjka+HdBI+6o3CXRHJoC47iav+QpR7u/wYl3gNq6MJO3MmTKqHegEDLjRN0
21
- FJAr3bRAwq03ZtTuAVA2bdKLGThehe1RRRtJHJ/PHpmL2c203/GTXYtG6C8ILZIp
22
- ZroTqQ8yglCJ+3hSOmodZqSAQ0Rj7GJgtuNH81qlSrHu5sTvoZjGmEqSIhvsSJ80
23
- wKoPdZnFAgMBAAGjezB5MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQW
24
- BBSUnF478a5lB4xuOBiktJdMJv6JmDAfBgNVHREEGDAWgRRicm9va2VAYWxjaGVt
25
- aXN0cy5pbzAfBgNVHRIEGDAWgRRicm9va2VAYWxjaGVtaXN0cy5pbzANBgkqhkiG
26
- 9w0BAQUFAAOCAQEAT7KtBXWsq1KA7NOSMeFEDeSvhrgdLwCG/37pIu0rjvx9iAW4
27
- gncxV0MccqIUtaF+lekjlXkIO+rXAVjvdha23KtpFTW90dYXp4NLPnPlSdyvYzJy
28
- FIAaWGvujOT8xEu4umd45q5aepE8li4bR071i5Z7F0trKNVYYrxjQFmH5SSKYRT/
29
- fXtICtAh1de3z3SOSK58IMPwjuoApYBxiqlmx0Uhla7mrzCE5+NmLPit3hLH6JFK
30
- aSif+qBc6oHD7EQWPF5cZkzkIURuwNwPBngZGxIKaMAgRhjGFXzUMAaq++r59cS9
31
- xTfQ4k6fglKEgpnLAXiKdo2c8Ym+X4rIKFfedQ==
32
- -----END CERTIFICATE-----
33
- date: 2015-11-21 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2016-01-17 00:00:00.000000000 Z
34
12
  dependencies:
35
13
  - !ruby/object:Gem::Dependency
36
14
  name: rake
@@ -256,9 +234,11 @@ files:
256
234
  - lib/refinements.rb
257
235
  - lib/refinements/array_extensions.rb
258
236
  - lib/refinements/big_decimal_extensions.rb
237
+ - lib/refinements/hash_extensions.rb
259
238
  - lib/refinements/identity.rb
260
- - lib/refinements/tasks/rspec.rake
261
- - lib/refinements/tasks/rubocop.rake
239
+ - lib/tasks/console.rake
240
+ - lib/tasks/rspec.rake
241
+ - lib/tasks/rubocop.rake
262
242
  homepage: https://github.com/bkuhlmann/refinements
263
243
  licenses:
264
244
  - MIT
@@ -269,9 +249,9 @@ require_paths:
269
249
  - lib
270
250
  required_ruby_version: !ruby/object:Gem::Requirement
271
251
  requirements:
272
- - - ">="
252
+ - - "~>"
273
253
  - !ruby/object:Gem::Version
274
- version: '0'
254
+ version: '2.3'
275
255
  required_rubygems_version: !ruby/object:Gem::Requirement
276
256
  requirements:
277
257
  - - ">="
@@ -279,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
259
  version: '0'
280
260
  requirements: []
281
261
  rubyforge_project:
282
- rubygems_version: 2.5.0
262
+ rubygems_version: 2.5.1
283
263
  signing_key:
284
264
  specification_version: 4
285
265
  summary: Provides a collection of refinements for core Ruby objects.
@@ -1 +0,0 @@
1
- ������ze���$(k�΢o�O6d�z�U�>���rƂ�q2��@�� ���?�W?��� �T/��HE�I"�N�HD�Q)�s�������;�9R�,�U�[Y�҇n1dWMd��A!b��j�f�8:X��w�V���$�l|�I42��!u� ž��w���(L�W�*�\��d�Kυ�?��"Y0FK�8nf��t���Eum�Jl����\�ﳖw�r�dvX�~�>,[ږ�="�Nw��_�� �6 ��.eV0s�
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file