Sha256: da9c5f6816cad5fb871a2aceadd96f1bd94a08c2bc27aadf1c31487aa2b21046

Contents?: true

Size: 1.69 KB

Versions: 9

Compression:

Stored size: 1.69 KB

Contents

module Dynamoid
  module Adapter
    module Local
      extend self
      # Gimpy hash that should be somewhat equivalent to what Amazon's actual DynamoDB, for offline development.
    
      def data
        @data ||= {}
      end
    
      def reset_data
        self.data.each {|k, v| v[:data] = {}}
      end
    
      # BatchGetItem
      def batch_get_item(options)
        Hash.new { |h, k| h[k] = Array.new }.tap do |hash|
          options.each do |table_name, keys|
            table = data[table_name]
            Array(keys).each do |key|
              hash[table_name] << table[:data][key]
            end
          end
        end
      end
    
      # CreateTable
      def create_table(table_name, key)
        data[table_name] = {:id => key, :data => {}}
      end
    
      # DeleteItem
      def delete_item(table_name, key)
        data[table_name][:data].delete(key)
      end
    
      # DeleteTable
      def delete_table(table_name)
        data.delete(table_name)
      end
    
      # DescribeTable
    
      # GetItem
      def get_item(table_name, key)
        data[table_name][:data][key]
      end
    
      # ListTables
      def list_tables
        data.keys
      end
    
      # PutItem
      def put_item(table_name, object)
        table = data[table_name]
        table[:data][object[table[:id]]] = object
      end
    
      # Query
      def query(table_name, id)
        get_item(table_name, id)
      end
    
      # Scan
      def scan(table_name, scan_hash)
        return [] if data[table_name].nil?
        data[table_name][:data].values.select{|d| scan_hash.all?{|k, v| !d[k].nil? && d[k] == v}}
      end
    
      # UpdateItem
    
      # UpdateTable
    
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
dynamoid-0.1.1 lib/dynamoid/adapter/local.rb
dynamoid-0.1.0 lib/dynamoid/adapter/local.rb
dynamoid-0.0.7 lib/dynamoid/adapter/local.rb
dynamoid-0.0.6 lib/dynamoid/adapter/local.rb
dynamoid-0.0.5 lib/dynamoid/adapter/local.rb
dynamoid-0.0.4 lib/dynamoid/adapter/local.rb
dynamoid-0.0.3 lib/dynamoid/adapter/local.rb
dynamoid-0.0.2 lib/dynamoid/adapter/local.rb
Dynamoid-0.0.1 lib/dynamoid/adapter/local.rb