class Pansophy::Remote::CreateFile
Constants
- ALLOWED_ATTRS
Public Class Methods
new(bucket, path, body)
click to toggle source
# File lib/pansophy/remote/create_file.rb, line 24 def initialize(bucket, path, body) @bucket = bucket @pathname = Pathname.new(path) @body = body end
Public Instance Methods
call(options = {})
click to toggle source
# File lib/pansophy/remote/create_file.rb, line 30 def call(options = {}) prevent_overwrite! unless options[:overwrite] file_attributes = options.slice(*ALLOWED_ATTRS) directory.files.create(file_attributes.merge(key: @pathname.to_s, body: @body.dup)) end
Private Instance Methods
directory()
click to toggle source
# File lib/pansophy/remote/create_file.rb, line 48 def directory ReadDirectory.new(@bucket, @pathname).call end
exist?()
click to toggle source
# File lib/pansophy/remote/create_file.rb, line 38 def exist? directory.files.any? { |file| file.key == @pathname.to_s } end
prevent_overwrite!()
click to toggle source
# File lib/pansophy/remote/create_file.rb, line 42 def prevent_overwrite! return unless exist? fail ArgumentError, "#{@pathname} already exists, pass ':overwrite => true' to overwrite" end