bogo 0.2.6 → 0.2.8

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: 509f58f7b55fade966863353064046832ea7d2d8
4
- data.tar.gz: 17c71d9e4d7ce5d87783bd64ca74709dfc5db64c
3
+ metadata.gz: 7ec29a67728ffbbaf47b982278ada80c261d31dc
4
+ data.tar.gz: 4e4fdefbbf834b13f81d1376abe7bb313cc650ed
5
5
  SHA512:
6
- metadata.gz: 2e750ba668266417ccd98d3affea633ee6ecb6b1003eafab60c53c04fac7562278083dcf2b2bc6d0745283fc5728447503f5d2f33cf14790aed046db8a7baa8b
7
- data.tar.gz: 589e3ec867abfcbfb52e89942118698133161b89aca8ba30912d803e493defdacdb686a477e44a6681b2342e64308fb4e0174c05c63210c25b68e7fe5a0e829b
6
+ metadata.gz: c5bbed35f2489b6eff54bb7705ea0415b3de11ff3f7579671834ce010128e8aebf5032a193677f803855f5c144c044ff28fbf83675d677267d4d45e9af30402a
7
+ data.tar.gz: 0b7530c5d0f21a58c14e22266604f3df71ea34c3414c968ef1a4c8adfc365677a627763e5cf9c0327ab33076f6377bfc59f652878b19cfa28343afea29f6920f
@@ -1,3 +1,6 @@
1
+ # v0.2.8
2
+ * [Smash] Support block default values via Smash#fetch
3
+
1
4
  # v0.2.6
2
5
  * [Smash] Use Hash#dig if available to speed up access (GH-5)
3
6
 
@@ -83,10 +83,20 @@ module Bogo
83
83
  #
84
84
  # @param args [String, Symbol, Object] key path to walk. last value default to return
85
85
  # @return [Object] value at key or default value
86
- def fetch(*args)
87
- default_value = args.pop
88
- val = retrieve(*args)
89
- val == NO_VALUE ? default_value : val
86
+ def fetch(*args, &block)
87
+ if(block_given?)
88
+ default_value = block
89
+ elsif(args.size > 1)
90
+ default_value = args.pop
91
+ elsif(args.size < 1)
92
+ raise ArgumentError.new("Default value must be provided for #fetch")
93
+ end
94
+ result = retrieve(*args)
95
+ if(result == NO_VALUE)
96
+ block_given? ? default_value.call(self) : default_value
97
+ else
98
+ result
99
+ end
90
100
  end
91
101
 
92
102
  # Set value at given path
@@ -1,4 +1,4 @@
1
1
  module Bogo
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.2.6')
3
+ VERSION = Gem::Version.new('0.2.8')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bogo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-08 00:00:00.000000000 Z
11
+ date: 2017-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie