Class: Etcd::Node

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/etcd/node.rb

Overview

This class represents an etcd node

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Node

rubocop:disable MethodLength



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/etcd/node.rb', line 13

def initialize(opts = {})
  @created_index = opts['createdIndex']
  @modified_index = opts['modifiedIndex']
  @ttl = opts['ttl']
  @key = opts['key']
  @value = opts['value']
  @expiration = opts['expiration']
  @dir = opts['dir']

  if opts['dir'] && (!!opts['nodes'])
    opts['nodes'].each do |data|
      children << Node.new(data)
    end
  end
end

Instance Attribute Details

#created_indexObject (readonly) Also known as: createdIndex

Returns the value of attribute created_index.



8
9
10
# File 'lib/etcd/node.rb', line 8

def created_index
  @created_index
end

#dirObject (readonly)

Returns the value of attribute dir.



8
9
10
# File 'lib/etcd/node.rb', line 8

def dir
  @dir
end

#expirationObject (readonly)

Returns the value of attribute expiration.



8
9
10
# File 'lib/etcd/node.rb', line 8

def expiration
  @expiration
end

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/etcd/node.rb', line 8

def key
  @key
end

#modified_indexObject (readonly) Also known as: modifiedIndex

Returns the value of attribute modified_index.



8
9
10
# File 'lib/etcd/node.rb', line 8

def modified_index
  @modified_index
end

#ttlObject (readonly)

Returns the value of attribute ttl.



8
9
10
# File 'lib/etcd/node.rb', line 8

def ttl
  @ttl
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/etcd/node.rb', line 8

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



29
30
31
# File 'lib/etcd/node.rb', line 29

def <=>(other)
  key <=> other.key
end

#childrenObject



33
34
35
36
37
38
39
# File 'lib/etcd/node.rb', line 33

def children
  if directory?
    @children ||= []
  else
    fail 'This is not a directory, cant have children'
  end
end

#directory?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/etcd/node.rb', line 41

def directory?
  !! @dir
end