Class: FakeConsul::Server

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/fake_consul/server.rb

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



7
8
9
# File 'lib/fake_consul/server.rb', line 7

def initialize
  restore!
end

Instance Method Details

#clearObject

Clear current data and delete backing marshalling file



61
62
63
64
65
# File 'lib/fake_consul/server.rb', line 61

def clear
  super
  return unless File.exist?(db_file)
  File.delete(db_file)
end

#delete(key, options = nil) ⇒ Boolean

Fake delete

Performs no http requests but deletes data from local hash

Parameters:

  • key (String)
  • options (Hash) (defaults to: nil)

    unused/unimplemented

Returns:

  • (Boolean)

    true :trollface:



52
53
54
55
56
57
# File 'lib/fake_consul/server.rb', line 52

def delete(key, options = nil)
  super(key)
  compact
  persist!
  true
end

#get(key, options = nil, not_found = :reject, found = :return) ⇒ Array<Hash>

Fake get

Performs no http requests but stores data in local hash

Parameters:

  • key (String)
  • options (Hash) (defaults to: nil)
  • not_found (Symbol) (defaults to: :reject)

    unused/unimplemented

  • found (Symbol) (defaults to: :return)

    not unused/unimplemented

Returns:

  • (Array<Hash>)

    e.g. [‘foo’, value: ‘bar’]



21
22
23
24
25
26
27
28
29
# File 'lib/fake_consul/server.rb', line 21

def get(key, options = nil, not_found = :reject, found = :return)
  options ||= {}

  if options[:recurse]
    find_keys_recursive(key)
  else
    consul_export_format(key)
  end
end

#put(key, value, options = nil) ⇒ Boolean

Fake put

Performs no http requests but retrieves data from local hash

Parameters:

  • key (String)
  • options (Hash) (defaults to: nil)

    unused/unimplemented

Returns:

  • (Boolean)

    true :trollface:



38
39
40
41
42
43
# File 'lib/fake_consul/server.rb', line 38

def put(key, value, options = nil)
  self[key] = value
  compact
  persist!
  true
end