Class: Dagger::Vertex

Inherits:
Object
  • Object
show all
Defined in:
lib/dagger/vertex.rb

Overview

Vertex class for Dagger, representing a filesystem directory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Vertex

Returns a new instance of Vertex.



7
8
9
10
11
12
13
# File 'lib/dagger/vertex.rb', line 7

def initialize(name)
  initialize_forest

  meta['_meta.name'] = name
  meta['_meta.basename'] = File.basename(name)
  meta['_meta.dirname'] = File.dirname(name)
end

Instance Attribute Details

#inheritedObject (readonly)

Returns the value of attribute inherited.



15
16
17
# File 'lib/dagger/vertex.rb', line 15

def inherited
  @inherited
end

#keysObject (readonly)

Returns the value of attribute keys.



15
16
17
# File 'lib/dagger/vertex.rb', line 15

def keys
  @keys
end

#localObject (readonly)

Returns the value of attribute local.



15
16
17
# File 'lib/dagger/vertex.rb', line 15

def local
  @local
end

#metaObject (readonly)

Returns the value of attribute meta.



15
16
17
# File 'lib/dagger/vertex.rb', line 15

def meta
  @meta
end

Instance Method Details

#<<(keytree) ⇒ Object



31
32
33
# File 'lib/dagger/vertex.rb', line 31

def <<(keytree)
  local << keytree
end

#[](key) ⇒ Object



21
22
23
24
25
# File 'lib/dagger/vertex.rb', line 21

def [](key)
  key = KeyTree::Path[key] unless key.is_a? KeyTree::Path
  return inherited[key[1..-1]] if key.prefix?(KeyTree::Path['^'])
  keys[key]
end

#edge_added(edge) ⇒ Object



35
36
37
38
# File 'lib/dagger/vertex.rb', line 35

def edge_added(edge)
  return unless edge.head?(self)
  inherited << edge.tail.keys
end

#edge_removed(edge) ⇒ Object



40
41
42
43
# File 'lib/dagger/vertex.rb', line 40

def edge_removed(edge)
  return unless edge.head?(self)
  inherited.reject! { |tree| tree.equal?(edge.tail.keys) }
end

#fetch(key) ⇒ Object



27
28
29
# File 'lib/dagger/vertex.rb', line 27

def fetch(key)
  keys.fetch(key)
end

#nameObject Also known as: to_s



17
18
19
# File 'lib/dagger/vertex.rb', line 17

def name
  meta['_meta.name']
end