Class: Valise::Stack

Inherits:
Object
  • Object
show all
Includes:
ItemEnum, Unpath
Defined in:
lib/valise/stack.rb,
lib/valise/stack/decorator.rb,
lib/valise/stack/prefixes-decorator.rb,
lib/valise/stack/extensions-decorator.rb

Direct Known Subclasses

Decorator

Defined Under Namespace

Classes: Decorator, ExtensionsDecorator, PrefixesDecorator, SingleExtensionDecorator, SinglePrefixDecorator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ItemEnum

#absent, #present, #writable

Methods included from Unpath

#clean_pathname, #containing_workspace, #current_directory, #file_from_backtrace, #from_here, #make_pathname, #starting_directory, #up_to, #up_until

Constructor Details

#initialize(path, set) ⇒ Stack

Returns a new instance of Stack.



16
17
18
19
# File 'lib/valise/stack.rb', line 16

def initialize(path, set)
  @segments = make_pathname(path)
  @valise = set
end

Instance Attribute Details

#segmentsObject (readonly)

Returns the value of attribute segments.



21
22
23
# File 'lib/valise/stack.rb', line 21

def segments
  @segments
end

#valiseObject (readonly)

Returns the value of attribute valise.



21
22
23
# File 'lib/valise/stack.rb', line 21

def valise
  @valise
end

Instance Method Details

#below(item) ⇒ Object



47
48
49
# File 'lib/valise/stack.rb', line 47

def below(item)
  reget(valise.below(item.root))
end

#depth_of(item) ⇒ Object



55
56
57
# File 'lib/valise/stack.rb', line 55

def depth_of(item)
  valise.depth_of(item.root)
end

#diffed(item, value) ⇒ Object



39
40
41
# File 'lib/valise/stack.rb', line 39

def diffed(item, value)
  merge_diff.diff(item, value)
end

#dump_loadObject



31
32
33
# File 'lib/valise/stack.rb', line 31

def dump_load
  valise.serialization_for(self)
end

#eachObject



91
92
93
94
95
# File 'lib/valise/stack.rb', line 91

def each
  valise.each do |root|
    yield(item_for(root))
  end
end

#exts(*extensions) ⇒ Object



71
72
73
74
75
# File 'lib/valise/stack.rb', line 71

def exts(*extensions)
  exts = ExtensionsDecorator.new(self)
  exts.extensions = extensions
  return exts
end

#findObject



65
66
67
68
69
# File 'lib/valise/stack.rb', line 65

def find
  valise.cached(:find, rel_path) do
    raw_find
  end
end

#inspectObject



12
13
14
# File 'lib/valise/stack.rb', line 12

def inspect
  "<default>:#{(@segments||%{?})} #{@valise.inspect}"
end

#item_for(root) ⇒ Object



87
88
89
# File 'lib/valise/stack.rb', line 87

def item_for(root)
  Item.new(self, root, dump_load)
end

#merge_diffObject



27
28
29
# File 'lib/valise/stack.rb', line 27

def merge_diff
  valise.merge_diff_for(self)
end

#merged(item) ⇒ Object



35
36
37
# File 'lib/valise/stack.rb', line 35

def merged(item)
  merge_diff.merge(item)
end

#not_above(item) ⇒ Object



43
44
45
# File 'lib/valise/stack.rb', line 43

def not_above(item)
  reget(valise.not_above(item.root))
end

#pfxs(*prefixes) ⇒ Object



77
78
79
80
81
# File 'lib/valise/stack.rb', line 77

def pfxs(*prefixes)
  pfxs = PrefixesDecorator.new(self)
  pfxs.prefixes = prefixes
  return pfxs
end

#raw_findObject

Raises:



59
60
61
62
63
# File 'lib/valise/stack.rb', line 59

def raw_find
  item = present.first
  return item unless item.nil?
  raise Errors::NotFound, "#{self.inspect} not found"
end

#reget(root) ⇒ Object



83
84
85
# File 'lib/valise/stack.rb', line 83

def reget(root)
  root.get(segments)
end

#rel_pathObject



23
24
25
# File 'lib/valise/stack.rb', line 23

def rel_path
  @segments
end

#reverseObject



51
52
53
# File 'lib/valise/stack.rb', line 51

def reverse
  reget(valise.reverse)
end