Sha256: 447bca05e87513d4f0f6dd0a6e03b07f1cf15a8cb50dd292a3f48d3bf07a494e

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

require 'json'
require 'rest_client'
require 'uri'

module Rhoconnect
  # register the adapter as pre-defined
  Rhoconnect.register_predefined_source('RhoInternalBenchmarkAdapter')
  
  class RhoInternalBenchmarkAdapter < Rhoconnect::SourceAdapter
     def initialize(source) 
       super(source)
     end

     def login
       true
     end

    def query(params=nil)
      Rhoconnect::Store.lock(lock_name,1) do
        @result = Rhoconnect::Store.get_data(db_name)
      end
      @result
    end

    def create(create_hash)
      id = create_hash['mock_id']
      Rhoconnect::Store.lock(lock_name,1) do
        Rhoconnect::Store.put_data(db_name,{id=>create_hash},true) if id
      end
      id
    end

    def update(update_hash)
      id = update_hash.delete('id')
      return unless id
      Rhoconnect::Store.lock(lock_name,1) do
        data = Rhoconnect::Store.get_data(db_name)
        return unless data and data[id]
        update_hash.each do |attrib,value|
          data[id][attrib] = value
        end
        Rhoconnect::Store.put_data(db_name,data)
      end
    end

    def delete(delete_hash)
      id = delete_hash.delete('id')
      Rhoconnect::Store.lock(lock_name,1) do
        Rhoconnect::Store.delete_data(db_name,{id=>delete_hash}) if id
      end
    end

    def db_name
      "test_db_storage:#{@source.app_id}:#{@source.user_id}"
    end

    def lock_name
      "lock:#{db_name}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rhoconnect-3.1.1 lib/rhoconnect/predefined_adapters/bench_adapter.rb
rhoconnect-3.1.0 lib/rhoconnect/predefined_adapters/bench_adapter.rb
rhoconnect-3.1.0.beta2 lib/rhoconnect/predefined_adapters/bench_adapter.rb
rhoconnect-3.1.0.beta1 lib/rhoconnect/predefined_adapters/bench_adapter.rb