Sha256: df94d2b01e8fc73e81a8e3247a2d27595a720926eafa8834f3d798f92cb6d758

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

module Storage
  class Config
    class << self
      # Set a storage strategy based on its registered name.
      #
      #   Storage::Config.strategy = :s3
      #
      attr_reader :strategy

      # Set a storage class.
      #
      #   Storage::Config.strategy_class = Storage::Strategies::S3
      #
      attr_accessor :strategy_class

      # Set the S3 default bucket.
      attr_accessor :bucket

      # Set the S3 access key.
      attr_accessor :access_key

      # Set the S3 secret key.
      attr_accessor :secret_key

      # Set the S3 region.
      attr_accessor :region

      # Set the FileSystem storage path.
      attr_accessor :path
    end

    # Override setter so we can automatically define the strategy class
    # based on its registered name.
    def self.strategy=(strategy)
      @strategy_class = get_class_for_strategy(strategy)
      @strategy = strategy
    end

    def self.get_class_for_strategy(strategy)
      Storage::Strategies::STRATEGIES[strategy].split('::')
        .reduce(Object) {|ns, class_name| ns.const_get(class_name) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
storage-0.3.3 lib/storage/config.rb