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
10 11 12 13 14 15 16 |
# File 'lib/path_builder.rb', line 10 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.
7 8 9 |
# File 'lib/path_builder.rb', line 7 def root_dir @root_dir end |
Instance Method Details
#child_directory(*directory_list) ⇒ Object
Construct a child relative to the root by name
25 26 27 |
# File 'lib/path_builder.rb', line 25 def child_directory(*directory_list) File.join(root_dir, directory_list) end |
#file_path(file_name = nil) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/path_builder.rb', line 34 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
19 20 21 22 |
# File 'lib/path_builder.rb', line 19 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
30 31 32 |
# File 'lib/path_builder.rb', line 30 def sibling_directory(directory_name) parent_directory(directory_name, up: 0) end |