diplomat 0.16.1 → 0.16.2

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: 3a7f8b9cd84e6a867eb7f9649a92696084b4f686
4
- data.tar.gz: afdf5eb047658186b9c412a60526c14514a61bd4
3
+ metadata.gz: 0ba37ba0f0744c7b424c81b524cd86c6c14d3284
4
+ data.tar.gz: a61b033018328f55d8c4ce894c10fe675fbab896
5
5
  SHA512:
6
- metadata.gz: fc79a1d5e95146919ebd39cb75d336906bc365af0c5b68acf874306ffa3a3a75976e0c1ffcf5ab3e9385ce272d80c15dc1b701e74700ca84e6a976bb4807822c
7
- data.tar.gz: c8b793b3f7d57e3f14c39c40ca22d805807e5f5d0afa4372e6ab57264b731e803c2f2a7fb661320bf39e2118b877799018d8b2cf2568d6473dd50e8d0d82cd08
6
+ metadata.gz: 3155ef8a9a9eaad49cfacc57fc2beffc603f73213aa0212576a5b3d77fdc0c73a5722414939a6b82824b7210f06aa3cfa1c531895b2e5565f9c3b7a8811a5599
7
+ data.tar.gz: d0ec12eb626632ae3135cf795fed79317202820884f1064a74d6c15d065c5af402c31a7d2a8f1436d460b3532c7647c4df5eac7d1f4209f8f88d89561f16228e
data/lib/diplomat/kv.rb CHANGED
@@ -17,6 +17,7 @@ module Diplomat
17
17
  # @option options [String] :dc Target datacenter
18
18
  # @option options [Boolean] :keys Only return key names.
19
19
  # @option options [Boolean] :modify_index Only return ModifyIndex value.
20
+ # @option options [Boolean] :decode_values Return consul response with decoded values.
20
21
  # @option options [String] :separator List only up to a given separator. Only applies when combined with :keys option.
21
22
  # @option options [Boolean] :nil_values If to return keys/dirs with nil values
22
23
  # @param not_found [Symbol] behaviour if the key doesn't exist;
@@ -75,6 +76,9 @@ module Diplomat
75
76
  if @options and @options[:modify_index]
76
77
  return @raw.first['ModifyIndex']
77
78
  end
79
+ if @options and @options[:decode_values]
80
+ return decode_values
81
+ end
78
82
  return return_value(return_nil_values)
79
83
  when :wait
80
84
  index = raw.headers["x-consul-index"]
@@ -74,21 +74,28 @@ module Diplomat
74
74
  @raw = JSON.parse(@raw.body)
75
75
  end
76
76
 
77
+ # Return @raw with Value fields decoded
78
+ def decode_values
79
+ return @raw if @raw.first.is_a? String
80
+ @raw.inject([]) do |acc, el|
81
+ new_el = el.dup
82
+ new_el["Value"] = (Base64.decode64(el["Value"]) rescue nil)
83
+ acc << new_el
84
+ acc
85
+ end
86
+ end
87
+
77
88
  # Get the key/value(s) from the raw output
78
89
  def return_value(nil_values=false)
79
- return @value = @raw if @raw.first.is_a? String
80
- if @raw.count == 1
81
- @value = @raw.first["Value"]
82
- @value = Base64.decode64(@value) unless @value.nil?
90
+ @value = decode_values
91
+ if @value.first.is_a? String
92
+ return @value
93
+ elsif @value.count == 1
94
+ @value.first["Value"]
83
95
  else
84
- @value = @raw.reduce([]) do |acc, e|
85
- val = e["Value"].nil? ? nil : Base64.decode64(e["Value"])
86
- acc << {
87
- :key => e["Key"],
88
- :value => val
89
- } if val or nil_values
90
- acc
91
- end
96
+ @value = @value.map do |el|
97
+ { :key => el["Key"], :value => el["Value"] } if el["Value"] or nil_values
98
+ end.compact
92
99
  end
93
100
  end
94
101
 
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = "0.16.1"
2
+ VERSION = "0.16.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diplomat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.1
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hamelink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,16 +140,16 @@ dependencies:
140
140
  name: json
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: '1.8'
145
+ version: '0'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: '1.8'
152
+ version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: faraday
155
155
  requirement: !ruby/object:Gem::Requirement