Sha256: e0e5e32faf5286be15d0bdb6186c1b96efe961808aa4480a289009b0d2875bcf

Contents?: true

Size: 805 Bytes

Versions: 15

Compression:

Stored size: 805 Bytes

Contents

module Pansophy
  module Remote
    class CreateFile
      include Adamantium::Flat

      def initialize(bucket, path, body)
        @bucket   = bucket
        @pathname = Pathname.new(path)
        @body     = body
      end

      def call(options = {})
        prevent_overwrite! unless options[:overwrite]
        directory.files.create(key: @pathname.to_s, body: @body.dup)
      end

      private

      def exist?
        directory.files.any? { |file| file.key == @pathname.to_s }
      end

      def prevent_overwrite!
        return unless exist?
        fail ArgumentError,
             "#{@pathname} already exists, pass ':overwrite => true' to overwrite"
      end

      def directory
        ReadDirectory.new(@bucket, @pathname).call
      end
      memoize :directory
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pansophy-0.5.5 lib/pansophy/remote/create_file.rb
pansophy-0.5.4 lib/pansophy/remote/create_file.rb
pansophy-0.5.3 lib/pansophy/remote/create_file.rb
pansophy-0.5.2 lib/pansophy/remote/create_file.rb
pansophy-0.5.1 lib/pansophy/remote/create_file.rb
pansophy-0.5.0 lib/pansophy/remote/create_file.rb
pansophy-0.4.0 lib/pansophy/remote/create_file.rb
pansophy-0.3.0 lib/pansophy/remote/create_file.rb
pansophy-0.2.6 lib/pansophy/remote/create_file.rb
pansophy-0.2.5 lib/pansophy/remote/create_file.rb
pansophy-0.2.4 lib/pansophy/remote/create_file.rb
pansophy-0.2.3 lib/pansophy/remote/create_file.rb
pansophy-0.2.1 lib/pansophy/remote/create_file.rb
pansophy-0.2.0 lib/pansophy/remote/create_file.rb
pansophy-0.1.0 lib/pansophy/remote/create_file.rb