ramda-ruby 0.10.0 → 0.11.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
  SHA1:
3
- metadata.gz: 65ad97e5bb00333847f6a7705f72b84ae81f7549
4
- data.tar.gz: 2aab392d448af389c478cf44c1a3f5639d8948b0
3
+ metadata.gz: 2d5757dd75ba41c1a2d00617b9ac764d96f378a1
4
+ data.tar.gz: 379e4d2156f99f92bb273d3b85e53f3ecab52ae4
5
5
  SHA512:
6
- metadata.gz: 5ba02e63aeb102d71134428662f1eb7574bee6f6bb57e8befa70616272fc05d7e635b4023ceae1811232069abe9b2a83e4f1afc424e8cd7c4ee277a8954651a0
7
- data.tar.gz: e9e6e79f2b65392162157d504813a20caa3116b9096f1e2c369d709b3c4c650b9039604f5840a02c6a33edcb18ba903305b27d1d05340c3c8549093c0237c2a6
6
+ metadata.gz: b469dce9a379ee2b6abeb701eb8fe23aff6189a3b2075cfd7c39addda944ad205fe86fb46e6066718cb3bd819fae37efe086743b438c9b437899860ca98a5dd4
7
+ data.tar.gz: 3f8d3a0c7d2853db5c8be295651827f792774566791d2cc43880b4927e4001c4d0780a8e4dba1c49736e5f63e95f0df186119bd68cd5b6ded3c7a80af8c1efa3
@@ -1,6 +1,13 @@
1
1
  Not Released
2
2
  ---------------
3
3
 
4
+ Release 0.11.0
5
+ ---------------
6
+
7
+ Added:
8
+
9
+ * dissoc_path
10
+
4
11
  Release 0.10.0
5
12
  ---------------
6
13
 
data/README.md CHANGED
@@ -4,7 +4,7 @@ Ramda Ruby
4
4
  This is a ruby version of [Ramda Js](http://ramdajs.com) library.
5
5
 
6
6
  [![Gem Version](https://badge.fury.io/rb/ramda-ruby.svg)](http://badge.fury.io/rb/ramda-ruby)
7
- [![Functions](https://img.shields.io/badge/Functions-170-green.svg)](docs/FUNCTIONS.md)
7
+ [![Functions](https://img.shields.io/badge/Functions-171-green.svg)](docs/FUNCTIONS.md)
8
8
  [![Travis badge](https://travis-ci.org/lazebny/ramda-ruby.svg?branch=master)](https://travis-ci.org/lazebny/ramda-ruby)
9
9
  [![AppVeyor status](https://ci.appveyor.com/api/projects/status/ponccdax7aj4ufw2?svg=true)](https://ci.appveyor.com/project/lazebny/ramda-ruby)
10
10
  [![Coverage Status](https://coveralls.io/repos/lazebny/ramda-ruby/badge.png)](https://coveralls.io/r/lazebny/ramda-ruby)
data/ROADMAP.md CHANGED
@@ -1,7 +1,3 @@
1
- Release 0.11.0
2
- ---------------
3
- * dissoc_path
4
-
5
1
  Release 0.12.0
6
2
  ---------------
7
3
  * apperture
@@ -142,6 +142,7 @@ Object
142
142
  * [assoc_path](http://ramdajs.com/docs/#assocPath)
143
143
  * [clone](http://ramdajs.com/docs/#clone)
144
144
  * [dissoc](http://ramdajs.com/docs/#dissoc)
145
+ * [dissoc_path](http://ramdajs.com/docs/#dissocPath)
145
146
  * [eq_props](http://ramdajs.com/docs/#eqProps)
146
147
  * [evolve](http://ramdajs.com/docs/#evolve)
147
148
  * [has](http://ramdajs.com/docs/#has)
@@ -75,6 +75,33 @@ module Ramda
75
75
  ::Ramda.clone(obj).tap { |o| o.delete(prop) }
76
76
  end
77
77
 
78
+ # Makes a shallow clone of an object, omitting the property
79
+ # at the given path. Note that this copies and flattens prototype
80
+ # properties onto the new object as well.
81
+ # All non-primitive properties are copied by reference.
82
+ #
83
+ # [Idx] -> {k: v} -> {k: v}
84
+ # Idx = String | Int
85
+ #
86
+ curried_method(:dissoc_path) do |path, obj|
87
+ cloned = obj.dup
88
+ unless path.empty?
89
+ result = path[1..-1].reduce([cloned, path[0]]) do |(acc, last_key), key|
90
+ case acc[last_key]
91
+ when ::Array, ::Hash
92
+ [acc[last_key], key]
93
+ else
94
+ [acc, last_key]
95
+ end
96
+ end
97
+
98
+ acc, last_key = result
99
+
100
+ acc.is_a?(::Array) ? acc.delete_at(last_key) : acc.delete(last_key)
101
+ end
102
+ cloned
103
+ end
104
+
78
105
  # Returns whether or not an object has an own property with the specified name
79
106
  #
80
107
  # s -> {s: x} -> Boolean
@@ -1,3 +1,3 @@
1
1
  module Ramda
2
- VERSION = '0.10.0'.freeze
2
+ VERSION = '0.11.0'.freeze
3
3
  end
@@ -66,6 +66,53 @@ describe Ramda::Object do
66
66
  end
67
67
  end
68
68
 
69
+ context '#dissoc_path' do
70
+ it 'makes a shallow clone of an object, omitting only what is necessary for the path' do
71
+ obj1 = {
72
+ a: { b: 1, c: 2, d: { e: 3 } },
73
+ f: [{ g: 4 }, { h: 5, i: 6, j: { k: 7, l: 8 } }],
74
+ m: 9
75
+ }
76
+ obj2 = R.dissoc_path([:f, 1, :i], obj1)
77
+
78
+ expect(obj2).to eq(a: { b: 1, c: 2, d: { e: 3 } },
79
+ f: [{ g: 4 }, { h: 5, j: { k: 7, l: 8 } }],
80
+ m: 9)
81
+ expect(obj2[:a]).to be(obj1[:a])
82
+ expect(obj2[:m]).to be(obj1[:m])
83
+ expect(obj2[:f][0]).to be(obj1[:f][0])
84
+ expect(obj2[:f][1][:h]).to be(obj1[:f][1][:h])
85
+ expect(obj2[:f][1][:j]).to be(obj1[:f][1][:j])
86
+ end
87
+
88
+ it 'does not try to omit inner properties that do not exist' do
89
+ obj1 = { a: 1, b: { c: 2, d: 3 }, e: 4, f: 5 }
90
+ obj2 = R.dissoc_path([:x, 0, :z], obj1)
91
+
92
+ expect(obj2).to eq(a: 1, b: { c: 2, d: 3 }, e: 4, f: 5)
93
+
94
+ expect(obj2[:a]).to be(obj1[:a])
95
+ expect(obj2[:b]).to be(obj1[:b])
96
+ expect(obj2[:f]).to be(obj1[:f])
97
+ end
98
+
99
+ it 'leaves an empty object when all properties omitted' do
100
+ obj1 = { a: 1, b: { c: 2 }, d: 3 }
101
+ obj2 = R.dissoc_path([:b, :c], obj1)
102
+ expect(obj2).to eq(a: 1, b: {}, d: 3)
103
+ end
104
+
105
+ it 'leaves an empty array when all indexes are omitted' do
106
+ obj1 = { a: 1, b: [2], d: 3 }
107
+ obj2 = R.dissoc_path([:b, 0], obj1)
108
+ expect(obj2).to eq(a: 1, b: [], d: 3)
109
+ end
110
+
111
+ it 'accepts empty path' do
112
+ expect(R.dissoc_path([], a: 1, b: 2)).to eq(a: 1, b: 2)
113
+ end
114
+ end
115
+
69
116
  context '#has' do
70
117
  it 'from docs' do
71
118
  has_name = r.has(:name)
@@ -50,6 +50,7 @@ describe Ramda do
50
50
  r(:difference)
51
51
  r(:difference_with)
52
52
  r(:dissoc)
53
+ r(:dissoc_path)
53
54
  r(:divide)
54
55
  r(:drop)
55
56
  r(:drop_while)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ramda-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Lazebny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-03 00:00:00.000000000 Z
11
+ date: 2017-07-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby version of Ramda Js library.
14
14
  email: