Class: RubySMB::Server::Share::Provider::VirtualDisk::VirtualStaticFile

Inherits:
VirtualPathname
  • Object
show all
Defined in:
lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb

Overview

A static file is one whose contents are known at creation time and do not change.

Since:

  • 3.1.1

Constant Summary

Constants inherited from VirtualPathname

RubySMB::Server::Share::Provider::VirtualDisk::VirtualPathname::SEPARATOR

Instance Attribute Summary collapse

Attributes inherited from VirtualPathname

#virtual_disk

Instance Method Summary collapse

Methods inherited from VirtualPathname

#<=>, #==, #absolute?, #basename, basename, #children, #cleanpath, cleanpath, dirname, #dirname, #entries, #exist?, #extname, #join, #relative?, #split, #stat, #to_s

Constructor Details

#initialize(disk, path, content, stat: nil) ⇒ VirtualStaticFile

Returns a new instance of VirtualStaticFile.

Parameters:

  • disk (Hash)

    The mapping of paths to objects representing the virtual file system.

  • path (String)

    The path of this entry.

  • content (String)

    The static content of this file.

  • stat (File::Stat) (defaults to: nil)

    An explicit stat object describing the file.

Raises:

  • (ArgumentError)

Since:

  • 3.1.1



36
37
38
39
40
41
42
# File 'lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb', line 36

def initialize(disk, path, content, stat: nil)
  stat = stat || VirtualStat.new(file?: true, size: content.size)
  raise ArgumentError.new('stat is not a file') unless stat.file?

  @content = content
  super(disk, path, stat: stat)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RubySMB::Server::Share::Provider::VirtualDisk::VirtualPathname

Instance Attribute Details

#contentObject (readonly)

Since:

  • 3.1.1



49
50
51
# File 'lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb', line 49

def content
  @content
end

Instance Method Details

#open(mode = 'r', &block) ⇒ Object

Since:

  • 3.1.1



44
45
46
47
# File 'lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb', line 44

def open(mode = 'r', &block)
  file = StringIO.new(@content)
  block_given? ? block.call(file) : file
end