Sha256: 57b194ecf8ce7eaa1e963a0422c0cfc933b121a5d9dc4365c96527cc11a3f7bc

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

# Encoding: utf-8

module Etcd
  class Node

    include Comparable

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

    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'] and (!!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
        raise "This is not a directory, cant have children"
      end
    end

    def directory?
      !! @dir
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
etcd-0.2.0.alpha lib/etcd/node.rb