Sha256: a27dcb5d7eb7e20b7de18ec053229fe4916d1ab723d597993c1e9934f1d310cb

Contents?: true

Size: 1.07 KB

Versions: 3

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_accessor :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

3 entries across 3 versions & 1 rubygems

Version Path
storage-0.3.2 lib/storage/config.rb
storage-0.3.1 lib/storage/config.rb
storage-0.3.0 lib/storage/config.rb