class ROM::Files::Connection
Attributes
data[R]
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
search(patterns, path: self.path, exclude_patterns: EMPTY_ARRAY, sorting: nil, directories: false)
click to toggle source
@param patterns [Array<String>] @param path [Pathname] @param exclude_patterns [Array<String>] @param sorting [#to_proc, nil] @param directories [Boolean] @return [Array<Pathname>]
# File lib/rom/files/connection.rb, line 67 def search(patterns, path: self.path, exclude_patterns: EMPTY_ARRAY, sorting: nil, directories: false) files = patterns.inject([]) do |result, pattern| result + Pathname.glob(path_for(pattern, path: path)).map { |found| found.relative_path_from(path) } end files = files.reject(&:directory?) unless directories files = files.reject do |match| exclude_patterns.any? do |pattern| match.fnmatch(pattern, File::FNM_EXTGLOB) end end files = files.sort_by(&sorting) if sorting files 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