class ROM::Files::Connection

Attributes

data[R]

Dataset registry

@return [Concurrent::Hash]

@api private

path[R]

@return [Pathname]

Public Class Methods

new(path = Pathname.pwd) click to toggle source

@param path [Pathname, to_s]

# File lib/rom/files/connection.rb, line 13
def initialize(path = Pathname.pwd)
  @path = Pathname(path).expand_path
  @data = Concurrent::Hash.new
end

Public Instance Methods

binread(id) click to toggle source

@param id [Pathname, to_s] @return [String]

# File lib/rom/files/connection.rb, line 96
def binread(id)
  path_for(id).binread
end
binwrite(id, contents) click to toggle source

@param id [Pathname, to_s] @param contents [String, to_s] @return [String]

# File lib/rom/files/connection.rb, line 103
def binwrite(id, contents)
  path_for(id).binwrite(contents)
end
build_dataset(options) click to toggle source
# File lib/rom/files/connection.rb, line 52
def build_dataset(options)
  Dataset.new([], options.merge(connection: self))
end
create_dataset(name) click to toggle source

@param name [String, Symbol] @return [Dataset]

# File lib/rom/files/connection.rb, line 43
def create_dataset(name)
  mime_type = MIME::Types[name].first
  @data[name] = if mime_type
                  build_dataset(mime_type: mime_type)
                else
                  build_dataset(inside_paths: [name])
                end
end
delete(id) click to toggle source

@param id [Pathname, to_s]

# File lib/rom/files/connection.rb, line 108
def delete(id)
  path_for(id).delete
end
key?(name) click to toggle source

@return [Boolean]

# File lib/rom/files/connection.rb, line 57
def key?(name)
  MIME::Types[name].any? || path_for(name).exist?
end
read(id) click to toggle source

@param id [Pathname, to_s] @return [String]

# File lib/rom/files/connection.rb, line 83
def read(id)
  path_for(id).read
end
write(id, contents) click to toggle source

@param id [Pathname, to_s] @param contents [String, to_s] @return [String]

# File lib/rom/files/connection.rb, line 90
def write(id, contents)
  path_for(id).write(contents.to_s)
end

Private Instance Methods

path_for(name, path: self.path) click to toggle source

@return [Pathname]

# File lib/rom/files/connection.rb, line 115
def path_for(name, path: self.path)
  path.join(name.to_s)
end