Class: Valise::Stack::PrefixesDecorator

Inherits:
Decorator show all
Defined in:
lib/valise/stack/prefixes-decorator.rb

Instance Attribute Summary collapse

Attributes inherited from Valise::Stack

#segments, #valise

Instance Method Summary collapse

Methods inherited from Decorator

#each, #rel_path, #segments, #valise

Methods inherited from Valise::Stack

#below, #depth_of, #diffed, #dump_load, #each, #exts, #find, #item_for, #merge_diff, #merged, #not_above, #pfxs, #raw_find, #rel_path, #reverse

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(stack) ⇒ PrefixesDecorator

Returns a new instance of PrefixesDecorator.



5
6
7
8
# File 'lib/valise/stack/prefixes-decorator.rb', line 5

def initialize(stack)
  super
  @prefixes = []
end

Instance Attribute Details

#prefixesObject

Returns the value of attribute prefixes.



10
11
12
# File 'lib/valise/stack/prefixes-decorator.rb', line 10

def prefixes
  @prefixes
end

Instance Method Details

#decorate_item(item) ⇒ Object



26
27
28
29
30
31
# File 'lib/valise/stack/prefixes-decorator.rb', line 26

def decorate_item(item)
  @prefixes.each do |pfx|
    dec_stack = sub_stack(item.stack, pfx)
    yield(dec_stack.item_for(item.root))
  end
end

#inspectObject



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

def inspect
  "P#{prefixes.inspect}x#{@stack.inspect}"
end

#reget(root) ⇒ Object



16
17
18
19
20
# File 'lib/valise/stack/prefixes-decorator.rb', line 16

def reget(root)
  decorated = self.new(super)
  decorated.prefixes = self.prefixes
  decorated
end

#sub_stack(stack, pfx) ⇒ Object



22
23
24
# File 'lib/valise/stack/prefixes-decorator.rb', line 22

def sub_stack(stack, pfx)
  SinglePrefixDecorator.new(stack, self, pfx)
end