Sha256: 1d54978b89965b8ae134fce0fd0acec1a74c2f96eaa01a105b264a0b92f00ae7

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

# encoding: UTF-8


# storage :s3 do |config|
#   config[:provider] = "AWS",
#   config[:aws_access_key_id] = "key",
#   config[:aws_secret_access_key] = "secret",
#   config[:region] = 'eu-west-1'
#   config[:bucket] => "name_of_bucket"
#   config[:accepts] => "image/*"
# end

# storage :another_local do |config|
#   config.update({
#     :provider => "Local"
#   })
# end

module Spontaneous::Plugins::Site
  module Storage
    extend ActiveSupport::Concern

    module ClassMethods
      def storage(mimetype = nil)
        instance.storage(mimetype)
      end

      def local_storage
        instance.local_storage
      end
    end # ClassMethods

    def storage(mimetype = nil)
      storage_for_mimetype(mimetype)
    end

    def storage_for_mimetype(mimetype)
      storage_backends.detect { |storage| storage.accepts?(mimetype) }
    end

    def local_storage
      storage_backends.select { |storage| storage.local? }
    end

    def storage_backends
      @storage_backends ||= configure_storage
    end

    def configure_storage
      storage_backends = []
      storage_settings = config[:storage] || []
      storage_settings.each do |name, config|
        backend = Spontaneous::Storage.create(config)
        storage_backends << backend
      end
      storage_backends << default_storage
    end

    def default_storage
      @default_storage ||= Spontaneous::Storage::Local.new(Spontaneous.media_dir, '/media', accepts=nil)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spontaneous-0.2.0.alpha2 lib/spontaneous/plugins/site/storage.rb
spontaneous-0.2.0.alpha1 lib/spontaneous/plugins/site/storage.rb