Class: LoadPath::PathHelper
- Inherits:
-
Object
- Object
- LoadPath::PathHelper
- Defined in:
- lib/path_builder.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
Instance Method Summary collapse
-
#child_directory(*directory_list) ⇒ Object
Construct a child relative to the root by name.
- #file_path(file_name = nil) ⇒ Object
-
#initialize(root_dir, expand_path = false) ⇒ PathHelper
constructor
Construct with a root.
-
#parent_directory(directory_name, levels_up = {up: 1}) ⇒ Object
Construct a parent relative to the root by name.
-
#sibling_directory(directory_name) ⇒ Object
Construct a sibling relative to the root by name.
Constructor Details
#initialize(root_dir, expand_path = false) ⇒ PathHelper
Construct with a root
11 12 13 14 15 16 17 |
# File 'lib/path_builder.rb', line 11 def initialize(root_dir, =false) if () @root_dir = File.(root_dir) else @root_dir = root_dir end end |
Instance Attribute Details
#root_dir ⇒ Object
Returns the value of attribute root_dir.
8 9 10 |
# File 'lib/path_builder.rb', line 8 def root_dir @root_dir end |
Instance Method Details
#child_directory(*directory_list) ⇒ Object
Construct a child relative to the root by name
26 27 28 |
# File 'lib/path_builder.rb', line 26 def child_directory(*directory_list) File.join(root_dir, directory_list) end |
#file_path(file_name = nil) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/path_builder.rb', line 35 def file_path(file_name=nil) if (file_name) File.join(root_dir, file_name) else root_dir end end |
#parent_directory(directory_name, levels_up = {up: 1}) ⇒ Object
Construct a parent relative to the root by name
20 21 22 23 |
# File 'lib/path_builder.rb', line 20 def parent_directory(directory_name, levels_up={up: 1}) levels_up = levels_up[:up].to_i + 1 File.join(root_dir, levels_up.times.map { |_| '..' }, directory_name) end |
#sibling_directory(directory_name) ⇒ Object
Construct a sibling relative to the root by name
31 32 33 |
# File 'lib/path_builder.rb', line 31 def sibling_directory(directory_name) parent_directory(directory_name, up: 0) end |