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 +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/ROADMAP.md +0 -4
- data/docs/FUNCTIONS.md +1 -0
- data/lib/ramda/object.rb +27 -0
- data/lib/ramda/version.rb +1 -1
- data/spec/ramda/object_spec.rb +47 -0
- data/spec/ramda_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d5757dd75ba41c1a2d00617b9ac764d96f378a1
|
4
|
+
data.tar.gz: 379e4d2156f99f92bb273d3b85e53f3ecab52ae4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b469dce9a379ee2b6abeb701eb8fe23aff6189a3b2075cfd7c39addda944ad205fe86fb46e6066718cb3bd819fae37efe086743b438c9b437899860ca98a5dd4
|
7
|
+
data.tar.gz: 3f8d3a0c7d2853db5c8be295651827f792774566791d2cc43880b4927e4001c4d0780a8e4dba1c49736e5f63e95f0df186119bd68cd5b6ded3c7a80af8c1efa3
|
data/CHANGELOG.md
CHANGED
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
|
[](http://badge.fury.io/rb/ramda-ruby)
|
7
|
-
[](docs/FUNCTIONS.md)
|
8
8
|
[](https://travis-ci.org/lazebny/ramda-ruby)
|
9
9
|
[](https://ci.appveyor.com/project/lazebny/ramda-ruby)
|
10
10
|
[](https://coveralls.io/r/lazebny/ramda-ruby)
|
data/ROADMAP.md
CHANGED
data/docs/FUNCTIONS.md
CHANGED
@@ -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)
|
data/lib/ramda/object.rb
CHANGED
@@ -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
|
data/lib/ramda/version.rb
CHANGED
data/spec/ramda/object_spec.rb
CHANGED
@@ -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)
|
data/spec/ramda_spec.rb
CHANGED
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.
|
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-
|
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:
|