Module: Diplomat::ApiOptions

Included in:
Acl, Event, Kv, Lock, Node, Query, Service
Defined in:
lib/diplomat/api_options.rb

Overview

Helper methods for interacting with the Consul RESTful API

Instance Method Summary collapse

Instance Method Details

#check_acl_tokenObject



4
5
6
# File 'lib/diplomat/api_options.rb', line 4

def check_acl_token
  use_named_parameter('token', Diplomat.configuration.acl_token)
end

#use_cas(options) ⇒ Object



8
9
10
# File 'lib/diplomat/api_options.rb', line 8

def use_cas(options)
  options ? use_named_parameter('cas', options[:cas]) : []
end

#use_consistency(options) ⇒ Object



12
13
14
# File 'lib/diplomat/api_options.rb', line 12

def use_consistency(options)
  options && options[:consistency] ? [options[:consistency].to_s] : []
end

#valid_transaction_verbsHash

Mapping for valid key/value store transaction verbs and required parameters

rubocop:disable MethodLength

Returns:

  • (Hash)

    valid key/store transaction verbs and required parameters



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/diplomat/api_options.rb', line 20

def valid_transaction_verbs
  {
    'set' => %w[Key Value],
    'cas' => %w[Key Value Index],
    'lock' => %w[Key Value Session],
    'unlock' => %w[Key Value Session],
    'get' => %w[Key],
    'get-tree' => %w[Key],
    'check-index' => %w[Key Index],
    'check-session' => %w[Key Session],
    'delete' => %w[Key],
    'delete-tree' => %w[Key],
    'delete-cas' => %w[Key Index]
  }
end

#valid_value_transactionsArray<String>

Key/value store transactions that require that a value be set

Returns:

  • (Array<String>)

    verbs that require a value be set



40
41
42
43
44
# File 'lib/diplomat/api_options.rb', line 40

def valid_value_transactions
  @valid_value_transactions ||= valid_transaction_verbs.select do |verb, requires|
    verb if requires.include? 'Value'
  end
end