Sha256: 0144cad5a0e327dba8a62b90fef12ecf6f2e709969aa7d00640390eb27ba8f3c

Contents?: true

Size: 985 Bytes

Versions: 3

Compression:

Stored size: 985 Bytes

Contents

# Encoding: utf-8

module Etcd
  # This class represents an etcd node
  class Node
    include Comparable

    attr_reader :created_index, :modified_index, :expiration, :ttl, :key, :value
    alias_method :createdIndex, :created_index
    alias_method :modifiedIndex, :modified_index

    # rubocop:disable MethodLength
    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

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

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

    def directory?
      !! @dir
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
etcd-0.2.2 lib/etcd/node.rb
etcd-0.2.1 lib/etcd/node.rb
etcd-0.2.0.beta.1 lib/etcd/node.rb