Sha256: ed2196e719dbc6e460c423877c4bef5b5eb6d8d1351546a18a58fa83842b8eb2

Contents?: true

Size: 858 Bytes

Versions: 2

Compression:

Stored size: 858 Bytes

Contents

# encoding: utf-8
module Dynamoid #:nodoc:

  module Adapter
    extend self
    
    def adapter
      reconnect! unless @adapter
      @adapter
    end
    
    def reconnect!
      require "dynamoid/adapter/#{Dynamoid::Config.adapter}" unless Dynamoid::Adapter.const_defined?(Dynamoid::Config.adapter.camelcase)
      @adapter = Dynamoid::Adapter.const_get(Dynamoid::Config.adapter.camelcase)
      @adapter.connect! if @adapter.respond_to?(:connect!)
    end
    
    def method_missing(method, *args)
      if @adapter.respond_to?(method)
        start = Time.now
        result = @adapter.send(method, *args)
        Dynamoid.logger.info "((#{((Time.now - start) * 1000.0).round(2)} ms) #{method.to_s.split('_').collect(&:upcase).join(' ')}#{ " - #{args.join(',')}" unless args.empty? }"
        return result
      end
      super
    end
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dynamoid-0.0.4 lib/dynamoid/adapter.rb
dynamoid-0.0.3 lib/dynamoid/adapter.rb