xf 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/xf/identity.rb +1 -1
- data/lib/xf/public_api.rb +4 -0
- data/lib/xf/scope.rb +6 -4
- data/lib/xf/trace.rb +14 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b22d8834efc5ccf08dbe6de45136a10b852a88028ba851c74e7f0156fbc451d
|
4
|
+
data.tar.gz: de850927d2c583eed59712be6a9d9c7e5b8f00ef43cb2091938a4138b877f905
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9067391391eae8e1501fd9cc760865d659bc78624ab6e3c4f671790a1a6ffce05e11396ffaf547eb73006a0a6b71b1507a999ef5130d8824d3230b5add00d463
|
7
|
+
data.tar.gz: d6b465abbf9480e19b5c206071a49a9f127cc8e9c8dd737a5a72329c989f42653a9d6755355f333f58a4cb1d545de9c0ccc36dc472d6198f7e13f963d5705be5
|
data/README.md
CHANGED
@@ -6,6 +6,18 @@
|
|
6
6
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/905faea654f9e0a1f811/test_coverage)](https://codeclimate.com/github/baweaver/xf/test_coverage)
|
7
7
|
[![Build Status](https://travis-ci.org/baweaver/xf.svg?branch=master)](https://travis-ci.org/baweaver/xf)
|
8
8
|
|
9
|
+
![Xf Lemur logo](img/xf_logo.png)
|
10
|
+
|
11
|
+
Xf - Short for Xform or Transform Functions meant to manipulate
|
12
|
+
Enumerables, namely deep Hashes.
|
13
|
+
|
14
|
+
## Articles
|
15
|
+
|
16
|
+
### How it was made
|
17
|
+
|
18
|
+
* [Xf Part One - Scopes](https://medium.com/@baweaver/on-dealing-with-deep-hashes-in-ruby-xf-part-one-scopes-f63447d59ee1)
|
19
|
+
* [Xf Part Two - Traces](https://medium.com/@baweaver/on-dealing-with-deep-hashes-in-ruby-xf-part-two-traces-23b52546a753)
|
20
|
+
|
9
21
|
<!-- Tocer[start]: Auto-generated, don't remove. -->
|
10
22
|
|
11
23
|
## Table of Contents
|
data/lib/xf/identity.rb
CHANGED
data/lib/xf/public_api.rb
CHANGED
data/lib/xf/scope.rb
CHANGED
@@ -17,8 +17,8 @@ module Xf
|
|
17
17
|
# Gets a value from a Hash
|
18
18
|
#
|
19
19
|
# @return [type] [description]
|
20
|
-
def get
|
21
|
-
|
20
|
+
def get(&fn)
|
21
|
+
Proc.new { |hash| get_value(hash, &fn) }
|
22
22
|
end
|
23
23
|
|
24
24
|
# Sets a value in a Hash
|
@@ -54,8 +54,10 @@ module Xf
|
|
54
54
|
# @param hash [Hash] Hash to get value from
|
55
55
|
#
|
56
56
|
# @return [Any]
|
57
|
-
def get_value(hash)
|
58
|
-
hash.dig(*@paths)
|
57
|
+
def get_value(hash, &fn)
|
58
|
+
value = hash.dig(*@paths)
|
59
|
+
|
60
|
+
block_given? ? fn[value] : value
|
59
61
|
end
|
60
62
|
|
61
63
|
# Sets a value at the bottom of a path without mutating the original.
|
data/lib/xf/trace.rb
CHANGED
@@ -20,14 +20,24 @@ module Xf
|
|
20
20
|
@trace_path = trace_path
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# Gets a value from a Hash
|
24
|
+
#
|
25
|
+
# @param &fn [Proc]
|
26
|
+
# Block to yield the hash, key, and value from any matching element
|
27
|
+
# into. Used to transform returned values upon retrieval
|
28
|
+
#
|
29
|
+
# @return [Proc[Hash] -> Array]
|
30
|
+
# Array containing matching values, optionally transformed
|
31
|
+
def get(&fn)
|
32
|
+
Proc.new { |target| get_value(target, &fn) }
|
25
33
|
end
|
26
34
|
|
27
|
-
def get_value(hash)
|
35
|
+
def get_value(hash, &fn)
|
28
36
|
retrieved_values = []
|
29
37
|
|
30
|
-
recursing_dive(hash) { |h, k, v|
|
38
|
+
recursing_dive(hash) { |h, k, v|
|
39
|
+
retrieved_values.push(block_given? ? fn[h, k, v] : v)
|
40
|
+
}
|
31
41
|
|
32
42
|
retrieved_values
|
33
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Weaver
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gemsmith
|