Class: Cachex::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/cachex/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, tags = []) ⇒ Node

Returns a new instance of Node.



6
7
8
9
10
# File 'lib/cachex/node.rb', line 6

def initialize(key, tags=[])
  @children = []
  @key = key
  @tags = tags
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/cachex/node.rb', line 4

def key
  @key
end

Instance Method Details

#add_child(node) ⇒ Object



12
13
14
15
# File 'lib/cachex/node.rb', line 12

def add_child(node)
  @children ||= []
  @children << node
end

#add_tags(additional_tags) ⇒ Object



17
18
19
# File 'lib/cachex/node.rb', line 17

def add_tags(additional_tags)
  @tags += additional_tags
end

#all_tagsObject



21
22
23
# File 'lib/cachex/node.rb', line 21

def all_tags
  [@tags, @children.map(&:key), @children.map(&:all_tags)].flatten.compact.uniq
end