Sha256: 63517c59ef6230f370b6124824aad54d0eea0bb2a2f30d72aaa35c109ae9ee0c
Contents?: true
Size: 1.5 KB
Versions: 22
Compression:
Stored size: 1.5 KB
Contents
module Pansophy module Remote class Directory include Adamantium::Flat def initialize(bucket_name, path = nil) @bucket_name = bucket_name @path = path.to_s end def pathname Pathname.new(@path) end memoize :pathname def files remote_files.map { |file| File.new(file) } end def create(options) remove(options) directory.files.create(key: pathname.cleanpath.to_s + '/') end def create_file(path, body, options = {}) CreateFile.new(@bucket_name, pathname.join(path), body).call(options) end private def directory ReadDirectory.new(@bucket_name, @path).call end memoize :directory def remote_files remote_entries.select { |file| !directory?(file) } end def remote_entries directory.files end def directory?(file) file.key.end_with?('/') end def remote_entry remote_entries.find { |entry| Pathname.new(entry.key).cleanpath == pathname.cleanpath } end memoize :remote_entry def exist? !remote_entry.nil? end def remove(options) return unless exist? prevent_overwrite! unless options[:overwrite] remote_entries.each(&:destroy) end def prevent_overwrite! fail ArgumentError, "#{pathname} already exists, pass ':overwrite => true' to overwrite" end end end end
Version data entries
22 entries across 22 versions & 1 rubygems