Class: FileSystem::Traverser
- Inherits:
-
Object
- Object
- FileSystem::Traverser
- 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
-
#dir_stack ⇒ Object
Returns the value of attribute dir_stack.
-
#dirs_only ⇒ Object
Returns the value of attribute dirs_only.
-
#options ⇒ Object
Returns the value of attribute options.
-
#reference_hash ⇒ Object
Returns the value of attribute reference_hash.
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
Instance Method Summary collapse
- #current_dir ⇒ Object
-
#initialize(root_dir, options = {}) ⇒ Traverser
constructor
A new instance of Traverser.
- #leave_dir ⇒ Object
- #traverse(obj, &blk) ⇒ Object
- #visit_dir(name) ⇒ Object
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, = {}) @root_dir ||= root_dir @dir_stack = [] @options = @dirs_only = false end |
Instance Attribute Details
#dir_stack ⇒ Object
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_only ⇒ Object
Returns the value of attribute dirs_only.
7 8 9 |
# File 'lib/file_system/traverser.rb', line 7 def dirs_only @dirs_only end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/file_system/traverser.rb', line 7 def @options end |
#reference_hash ⇒ Object
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_dir ⇒ Object
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_dir ⇒ Object
33 34 35 |
# File 'lib/file_system/traverser.rb', line 33 def current_dir File.join(root_dir, dir_stack.join('/')) end |
#leave_dir ⇒ Object
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 |