Sha256: e5564e8cfe8295c4e8f875a0d65b761d3953cac5d6546ba6028230377dad089c

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

module RailsConnector

  class DictStorage #:nodoc: all

    class << self

      def configure(config)
        @config = config.present? ? config.symbolize_keys : {}
      end

      def get(spec)
        storage.get(spec)
      end

      private

      attr_reader :config

      def storage
        @storage ||=
            case config[:type]
            when "s3"
              s3_storage(config)
            when "file"
              file_storage(config)
            else
              raise "Unsupported dict storage type #{config[:type]}"
            end
      end

      def s3_storage(config)
        if config && !config.key?("s3_endpoint") && !config.key?(:s3_endpoint)
          config = config.merge(:s3_endpoint => "s3-eu-west-1.amazonaws.com")
        end

        bucket = AWS::S3.new(config).buckets[config[:bucket_name]]
        Kvom::Storage::S3Storage.new({
          :bucket => bucket,
          :bucket_prefix => "dict",
          :cache => s3_storage_cache,
          :cache_prefix => "dict.",
        })
      end

      def s3_storage_cache
        Rails.cache
      end

      def file_storage(config)
        Kvom::Storage::FileSystemStorage.new(config)
      end

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.8.0.beta.200.883.f5f063b lib/rails_connector/dict_storage.rb
infopark_cloud_connector-6.8.0.beta.200.884.4bd86e6 lib/rails_connector/dict_storage.rb
infopark_cloud_connector-6.8.0.beta.200.869.9609b39 lib/rails_connector/dict_storage.rb
infopark_cloud_connector-6.8.0.beta.200.856.8c0fec5 lib/rails_connector/dict_storage.rb
infopark_cloud_connector-6.8.0.beta.200.809.bdfa8c3 lib/rails_connector/dict_storage.rb
infopark_cloud_connector-6.8.0.beta.200.785.05d4af9 lib/rails_connector/dict_storage.rb
infopark_cloud_connector-6.8.0.beta.200.744.99f67fc lib/rails_connector/dict_storage.rb