Class: PathstringRoot

Inherits:
Pathstring show all
Defined in:
lib/pathstring_root.rb

Constant Summary

Constants inherited from Pathstring

Pathstring::VERSION

Instance Attribute Summary collapse

Attributes inherited from Pathstring

#content

Instance Method Summary collapse

Methods inherited from Pathstring

#initialize, join, #rename, #save, #save!, #with_relative_root

Constructor Details

This class inherits a constructor from Pathstring

Instance Attribute Details

#branching_class=(value) ⇒ Object

Sets the attribute branching_class

Parameters:

  • value

    the value to set the attribute branching_class to.



10
11
12
# File 'lib/pathstring_root.rb', line 10

def branching_class=(value)
  @branching_class = value
end

#lastObject (readonly)

last selected element



8
9
10
# File 'lib/pathstring_root.rb', line 8

def last
  @last
end

Instance Method Details

#branching(path = nil) ⇒ Object

list of an element’s children as instances of the elements class



26
27
28
29
30
31
32
# File 'lib/pathstring_root.rb', line 26

def branching(path=nil)
  join(path || @last || '').children.sort.map do |cell|
    enroot(cell).tap { |c| yield c if block_given? }
  end
rescue # yeah yeah... i know Errno::ENOTDIR, but i don't care enough
  nil
end

#enroot(path) ⇒ Object

instantiate with parameter and set the right facade



20
21
22
# File 'lib/pathstring_root.rb', line 20

def enroot(path)
  branching_class.new(path, self).tap { |e| e.relative! }
end

#read(path = nil) ⇒ Object

a little utility method to make PathstringRoot complete



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

def read(path=nil)
  (select(path) || @last).read rescue nil
end

#select(path) ⇒ Object

Useful memoize. Needed to be done here because i really don’t want to do it enroot



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

def select(path)
  @last = enroot path if path
end