Class: IOStreams::BasePath
- Inherits:
-
Object
- Object
- IOStreams::BasePath
- Defined in:
- lib/io_streams/base_path.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete the file.
-
#exist? ⇒ Boolean
Returns [true|false] whether the file exists.
-
#initialize(path) ⇒ BasePath
constructor
A new instance of BasePath.
-
#join(*elements) ⇒ Object
If elements already contains the current path then it is used as is without adding the current path for a second time.
-
#mkdir ⇒ Object
Assumes the current path does not include a file name, and creates all elements in the path.
-
#mkpath ⇒ Object
Removes the last element of the path, the file name, before creating the entire path.
-
#reader(**args, &block) ⇒ Object
Return a reader for this path.
-
#size ⇒ Object
Returns [Integer] size of the file.
- #to_s ⇒ Object
-
#writer(**args, &block) ⇒ Object
Return a writer for this path.
Constructor Details
#initialize(path) ⇒ BasePath
Returns a new instance of BasePath.
6 7 8 |
# File 'lib/io_streams/base_path.rb', line 6 def initialize(path) @path = path.frozen? ? path : path.dup.freeze end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/io_streams/base_path.rb', line 4 def path @path end |
Instance Method Details
#delete ⇒ Object
Delete the file. Returns self
Notes:
-
No error is raised if the file is not present.
-
Only the file is removed, not any of the parent paths.
57 58 59 |
# File 'lib/io_streams/base_path.rb', line 57 def delete raise NotImplementedError end |
#exist? ⇒ Boolean
Returns [true|false] whether the file exists
42 43 44 |
# File 'lib/io_streams/base_path.rb', line 42 def exist? raise NotImplementedError end |
#join(*elements) ⇒ Object
If elements already contains the current path then it is used as is without adding the current path for a second time
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/io_streams/base_path.rb', line 12 def join(*elements) return self if elements.empty? relative = ::File.join(*elements) if relative.start_with?(path) self.class.new(relative) else self.class.new(::File.join(path, relative)) end end |
#mkdir ⇒ Object
Assumes the current path does not include a file name, and creates all elements in the path. Returns self
Note: Do not call this method if the path contains a file name, see ‘#mkpath`
37 38 39 |
# File 'lib/io_streams/base_path.rb', line 37 def mkdir raise NotImplementedError end |
#mkpath ⇒ Object
Removes the last element of the path, the file name, before creating the entire path. Returns self
29 30 31 |
# File 'lib/io_streams/base_path.rb', line 29 def mkpath raise NotImplementedError end |
#reader(**args, &block) ⇒ Object
Return a reader for this path
62 63 64 |
# File 'lib/io_streams/base_path.rb', line 62 def reader(**args, &block) IOStreams.reader(path, **args, &block) end |
#size ⇒ Object
Returns [Integer] size of the file
47 48 49 |
# File 'lib/io_streams/base_path.rb', line 47 def size raise NotImplementedError end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/io_streams/base_path.rb', line 23 def to_s path end |
#writer(**args, &block) ⇒ Object
Return a writer for this path
67 68 69 |
# File 'lib/io_streams/base_path.rb', line 67 def writer(**args, &block) IOStreams.writer(path, **args, &block) end |