xf 0.1.1 → 0.1.2

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -0
  3. data/lib/xf/identity.rb +1 -1
  4. data/lib/xf/scope.rb +10 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b22d8834efc5ccf08dbe6de45136a10b852a88028ba851c74e7f0156fbc451d
4
- data.tar.gz: de850927d2c583eed59712be6a9d9c7e5b8f00ef43cb2091938a4138b877f905
3
+ metadata.gz: de2a5575576ea006a32330169f46e8283b69daf1f94d8b5714978e37fd981c9b
4
+ data.tar.gz: f89fa8eb3e35a23ffed94f516f750e3dd84ec814f9ae4817ef5adc206cda01f9
5
5
  SHA512:
6
- metadata.gz: 9067391391eae8e1501fd9cc760865d659bc78624ab6e3c4f671790a1a6ffce05e11396ffaf547eb73006a0a6b71b1507a999ef5130d8824d3230b5add00d463
7
- data.tar.gz: d6b465abbf9480e19b5c206071a49a9f127cc8e9c8dd737a5a72329c989f42653a9d6755355f333f58a4cb1d545de9c0ccc36dc472d6198f7e13f963d5705be5
6
+ metadata.gz: '0715912967cc2c85bf01a6486cfe4714784e28d1a6a20cde1c480ec07416d9e62d25ab6e8d9973262b9d762122f4bbe1f81c2f55a07ca0a69152a7edf0531d6f'
7
+ data.tar.gz: 01c1f8b67288c6da4fe374ecae5804d8cda543c8038ef661a19de76f83271e315878bf3b0d51f9ce70de5298511ddab841f6827d8049d033cabade000a746a7f
data/README.md CHANGED
@@ -65,6 +65,9 @@ people = [{name: "Robert", age: 22}, {name: "Roberta", age: 22}, {name: "Foo", a
65
65
 
66
66
  people.map(&Xf.scope(:age).get)
67
67
  # => [22, 22, 42, 18]
68
+
69
+ people.map(&Xf.scope(:age).get { |v| v > 20 })
70
+ # => [true, true, true, false]
68
71
  ```
69
72
 
70
73
  Let's try setting a value:
@@ -129,6 +132,13 @@ first_name_trace = Xf.trace('first')
129
132
  people.map(&first_name_trace.get)
130
133
  # => [["Erickson"], ["Pugh"], ["Mullen"], ["Jacquelyn"], ["Miller"], ["Jolene"]]
131
134
 
135
+ # It can take a function too that gives back the parent hash and key as well.
136
+ #
137
+ # Why no shorthand? Arity of the function, and you can't have more than one `&`
138
+ # in the same code block. Ruby's no fan of it.
139
+ people.map(&first_name_trace.get { |h, k, v| v.downcase })
140
+ # => [["erickson"], ["pugh"], ["mullen"], ["jacquelyn"], ["miller"], ["jolene"]]
141
+
132
142
  # You can even compose them if you want to. Just remember compose
133
143
  people.flat_map(&Xf.compose(first_name_trace.set('Spartacus'), first_name_trace.get))
134
144
  # => ["Spartacus", "Spartacus", "Spartacus", "Spartacus", "Spartacus", "Spartacus"]
@@ -12,7 +12,7 @@ module Xf
12
12
  end
13
13
 
14
14
  def self.version
15
- "0.1.1"
15
+ "0.1.2"
16
16
  end
17
17
 
18
18
  def self.version_label
@@ -51,11 +51,20 @@ module Xf
51
51
  # Direct value getter, though it may be wiser to use Hash#dig here
52
52
  # instead if you're concerned about speed.
53
53
  #
54
+ # If the object does not respond to dig, Xf will attempt to use an
55
+ # array bracket accessor dive instead for compatability reasons.
56
+ #
54
57
  # @param hash [Hash] Hash to get value from
55
58
  #
56
59
  # @return [Any]
57
60
  def get_value(hash, &fn)
58
- value = hash.dig(*@paths)
61
+ value = if hash.respond_to?(:dig)
62
+ hash.dig(*@paths)
63
+ else
64
+ new_hash = hash
65
+ @paths.each { |s| new_hash = new_hash[s] }
66
+ new_hash
67
+ end
59
68
 
60
69
  block_given? ? fn[value] : value
61
70
  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.1
4
+ version: 0.1.2
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-06-21 00:00:00.000000000 Z
11
+ date: 2018-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gemsmith