Sha256: 373115ab8482b07b411c17ab4c8adcdce5e9b2cd1381602189f21a6ce71fdc90

Contents?: true

Size: 810 Bytes

Versions: 2

Compression:

Stored size: 810 Bytes

Contents

require 'aws-sdk'

module S3Repo
  ##
  # AWS API client
  class Client
    def initialize(params = {})
      @api = Aws::S3::Client.new
      @defaults = params
    end

    def respond_to?(method, include_all = false)
      @api.respond_to?(method, include_all) || super
    end

    private

    def method_missing(method, *args, &block)
      return super unless @api.respond_to?(method)
      define_singleton_method(method) do |*singleton_args|
        params = build_params(singleton_args)
        @api.send(method, params)
      end
      send(method, args.first)
    end

    def build_params(args)
      fail 'Too many arguments given' if args.size > 1
      params = args.first || {}
      fail 'Argument must be a hash' unless params.is_a? Hash
      @defaults.dup.merge!(params)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
s3repo-0.0.3 lib/s3repo/client.rb
s3repo-0.0.2 lib/s3repo/client.rb