diplomat 2.0.1 → 2.0.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: e4c8c4d80b3709be01d325281097f3db8506cb9c
4
- data.tar.gz: cb5c77df09a30b802e4a69c7d55c0f634f13d27c
3
+ metadata.gz: 821e0c50069009a97db9397d14f0c5c4eefba50c
4
+ data.tar.gz: 0204f17c74c81cc3676ef9332ed5bace9150e5ab
5
5
  SHA512:
6
- metadata.gz: 58067ecae844fea9ce3e2240847542820c65ff17c49b6e1cd4b7c02a8f2872089f1ddb9c075a824d2265f6c10055a1f669dfeab4612e45ca1389390046ba404f
7
- data.tar.gz: 011a2fe3e0a428922e13b595f86f143514227c80a3cf12aa0a17f20b99b3e0bafe20af9982fd70383a697686e874852df6de86bee90e8235e8af0c4bc44106dd
6
+ metadata.gz: fdf627aad378afb53880105c43ad280d4eb81900f1c1ec82bed4d37abcaff34a9ea17cc7db8e022fb44ea4c4167019d32366687648d4233585645f83d8936788
7
+ data.tar.gz: 5df07529deabb282661cb8cae6ccd5939685c7a4ab86d60f93306942d562f5301fa41fbd93cbcde9ce8ca5f3630cf21c9596e75d77b492611ec198f3a4036342
@@ -14,6 +14,7 @@ module Diplomat
14
14
  # @option options [String] :dc Target datacenter
15
15
  # @option options [Boolean] :keys Only return key names.
16
16
  # @option options [Boolean] :modify_index Only return ModifyIndex value.
17
+ # @option options [Boolean] :session Only return Session value.
17
18
  # @option options [Boolean] :decode_values Return consul response with decoded values.
18
19
  # @option options [String] :separator List only up to a given separator.
19
20
  # Only applies when combined with :keys option.
@@ -76,8 +77,9 @@ module Diplomat
76
77
  @raw = raw
77
78
  @raw = parse_body
78
79
  return @raw.first['ModifyIndex'] if @options && @options[:modify_index]
80
+ return @raw.first['Session'] if @options && @options[:session]
79
81
  return decode_values if @options && @options[:decode_values]
80
- return convert_to_hash(return_value(return_nil_values, transformation)) if @options && @options[:convert_to_hash]
82
+ return convert_to_hash(return_value(return_nil_values, transformation, true)) if @options && @options[:convert_to_hash]
81
83
  return return_value(return_nil_values, transformation)
82
84
  when :wait
83
85
  index = raw.headers['x-consul-index']
@@ -103,6 +105,7 @@ module Diplomat
103
105
  # @param options [Hash] the query params
104
106
  # @option options [Integer] :cas The modify index
105
107
  # @option options [String] :dc Target datacenter
108
+ # @option options [String] :acquire Session to attach to key
106
109
  # @return [Bool] Success or failure of the write (can fail in c-a-s mode)
107
110
  # rubocop:disable MethodLength, AbcSize
108
111
  def put(key, value, options = nil)
@@ -112,6 +115,7 @@ module Diplomat
112
115
  url += check_acl_token
113
116
  url += use_cas(@options)
114
117
  url += dc(@options)
118
+ url += acquire(@options)
115
119
  req.url concat_url url
116
120
  req.body = value
117
121
  end
@@ -186,6 +190,10 @@ module Diplomat
186
190
  options && options[:dc] ? use_named_parameter('dc', options[:dc]) : []
187
191
  end
188
192
 
193
+ def acquire(options)
194
+ options && options[:acquire] ? use_named_parameter('acquire', options[:acquire]) : []
195
+ end
196
+
189
197
  def keys(options)
190
198
  options && options[:keys] ? ['keys'] : []
191
199
  end
@@ -148,14 +148,20 @@ module Diplomat
148
148
  end
149
149
 
150
150
  # Get the key/value(s) from the raw output
151
- def return_value(nil_values = false, transformation = nil)
151
+ # rubocop:disable PerceivedComplexity, MethodLength, CyclomaticComplexity, AbcSize
152
+ def return_value(nil_values = false, transformation = nil, return_hash = false)
152
153
  @value = decode_values
153
154
  return @value if @value.first.is_a? String
154
-
155
- @value = @value.map do |el|
156
- el['Value'] = transformation.call(el['Value']) if transformation && !el['Value'].nil?
157
- { key: el['Key'], value: el['Value'] } if el['Value'] || nil_values
158
- end.compact
155
+ if @value.count == 1 && !return_hash
156
+ @value = @value.first['Value']
157
+ @value = transformation.call(@value) if transformation && !@value.nil?
158
+ return @value
159
+ else
160
+ @value = @value.map do |el|
161
+ el['Value'] = transformation.call(el['Value']) if transformation && !el['Value'].nil?
162
+ { key: el['Key'], value: el['Value'] } if el['Value'] || nil_values
163
+ end.compact
164
+ end
159
165
  end
160
166
  # rubocop:enable PerceivedComplexity, MethodLength, CyclomaticComplexity, AbcSize
161
167
 
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '2.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diplomat
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hamelink
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-02 00:00:00.000000000 Z
12
+ date: 2017-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler