Class: RVC::FS
- Inherits:
-
Object
- Object
- RVC::FS
- Defined in:
- lib/rvc/fs.rb
Constant Summary collapse
- MARK_PATTERN =
/^~(?:([\d\w]*|~|@))$/
- REGEX_PATTERN =
/^%/
- GLOB_PATTERN =
/\*/
Instance Attribute Summary collapse
-
#cur ⇒ Object
readonly
Returns the value of attribute cur.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #cd(dst) ⇒ Object
- #display_path ⇒ Object
-
#initialize(root) ⇒ FS
constructor
A new instance of FS.
- #lookup(path) ⇒ Object
-
#traverse(base, arcs) ⇒ Object
Starting from base, traverse each path element in arcs.
- #traverse_one(cur, arc, first) ⇒ Object
Constructor Details
Instance Attribute Details
#cur ⇒ Object (readonly)
Returns the value of attribute cur.
24 25 26 |
# File 'lib/rvc/fs.rb', line 24 def cur @cur end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
24 25 26 |
# File 'lib/rvc/fs.rb', line 24 def root @root end |
Instance Method Details
#cd(dst) ⇒ Object
40 41 42 43 44 |
# File 'lib/rvc/fs.rb', line 40 def cd dst fail unless dst.is_a? RVC::InventoryObject $shell.session.set_mark '~', [@cur] @cur = dst end |
#display_path ⇒ Object
36 37 38 |
# File 'lib/rvc/fs.rb', line 36 def display_path @cur.rvc_path.map { |arc,obj| arc } * '/' end |
#lookup(path) ⇒ Object
46 47 48 49 50 |
# File 'lib/rvc/fs.rb', line 46 def lookup path arcs, absolute, trailing_slash = Path.parse path base = absolute ? @root : @cur traverse(base, arcs) end |
#traverse(base, arcs) ⇒ Object
Starting from base, traverse each path element in arcs. Since the path may contain wildcards, this function returns a list of matches.
54 55 56 57 58 59 60 61 |
# File 'lib/rvc/fs.rb', line 54 def traverse base, arcs objs = [base] arcs.each_with_index do |arc,i| objs.map! { |obj| traverse_one obj, arc, i==0 } objs.flatten! end objs end |
#traverse_one(cur, arc, first) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rvc/fs.rb', line 63 def traverse_one cur, arc, first case arc when '.' [cur] when '..' [cur.rvc_parent ? cur.rvc_parent : cur] when '...' # XXX shouldnt be nil [(cur.respond_to?(:parent) && cur.parent) ? cur.parent : (cur.rvc_parent || cur)] when MARK_PATTERN if first and objs = $shell.session.get_mark($1) objs else [] end when REGEX_PATTERN regex = Regexp.new($') cur.children.select { |k,v| k =~ regex }.map { |k,v| v.rvc_link(cur, k); v } when GLOB_PATTERN regex = glob_to_regex arc cur.children.select { |k,v| k =~ regex }.map { |k,v| v.rvc_link(cur, k); v } else # XXX check for ambiguous child if first and arc =~ /^\d+$/ and objs = $shell.session.get_mark(arc) objs else if child = cur.traverse_one(arc) child.rvc_link cur, arc [child] else [] end end end end |