Class: IOStreams::BasePath

Inherits:
Object
  • Object
show all
Defined in:
lib/io_streams/base_path.rb

Direct Known Subclasses

File::Path, S3::Path

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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

#deleteObject

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.

Raises:

  • (NotImplementedError)


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

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

#mkdirObject

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`

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/io_streams/base_path.rb', line 37

def mkdir
  raise NotImplementedError
end

#mkpathObject

Removes the last element of the path, the file name, before creating the entire path. Returns self

Raises:

  • (NotImplementedError)


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

#sizeObject

Returns [Integer] size of the file

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/io_streams/base_path.rb', line 47

def size
  raise NotImplementedError
end

#to_sObject



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