Class: FileSystem::Traverser

Inherits:
Object
  • Object
show all
Defined in:
lib/file_system/traverser.rb

Constant Summary collapse

ONLY_DIRS =
'ONLY_DIRS'
REVERT =
'REVERT'
ALIAS =
'ALIAS'
REF =
'REF'
DIR =
'DIR'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_dir, options = {}) ⇒ Traverser

Returns a new instance of Traverser.



15
16
17
18
19
20
# File 'lib/file_system/traverser.rb', line 15

def initialize(root_dir, options = {})
  @root_dir ||= root_dir
  @dir_stack = []
  @options = options
  @dirs_only = false
end

Instance Attribute Details

#dir_stackObject

Returns the value of attribute dir_stack.



7
8
9
# File 'lib/file_system/traverser.rb', line 7

def dir_stack
  @dir_stack
end

#dirs_onlyObject

Returns the value of attribute dirs_only.



7
8
9
# File 'lib/file_system/traverser.rb', line 7

def dirs_only
  @dirs_only
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/file_system/traverser.rb', line 7

def options
  @options
end

#reference_hashObject

Returns the value of attribute reference_hash.



7
8
9
# File 'lib/file_system/traverser.rb', line 7

def reference_hash
  @reference_hash
end

#root_dirObject

Returns the value of attribute root_dir.



7
8
9
# File 'lib/file_system/traverser.rb', line 7

def root_dir
  @root_dir
end

Instance Method Details

#current_dirObject



33
34
35
# File 'lib/file_system/traverser.rb', line 33

def current_dir
  File.join(root_dir, dir_stack.join('/'))
end

#leave_dirObject



41
42
43
# File 'lib/file_system/traverser.rb', line 41

def leave_dir
  dir_stack.pop
end

#traverse(obj, &blk) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/file_system/traverser.rb', line 22

def traverse(obj, &blk)
  case obj
  when Hash
    handle_hash(obj, &blk)
  when Array
    handle_list(obj, &blk)
  else
    handle_single(obj, &blk)
  end
end

#visit_dir(name) ⇒ Object



37
38
39
# File 'lib/file_system/traverser.rb', line 37

def visit_dir(name)
  dir_stack.push name
end