module Cylons::RPC

Public Instance Methods

all() click to toggle source

need to wrap because to_a will leak connections otherwise

# File lib/cylons/rpc.rb, line 8
def all
  ::ActiveRecord::Base.connection_pool.with_connection do
    execute(:all).to_a
  end
end
create(params) click to toggle source
# File lib/cylons/rpc.rb, line 14
def create(params)
  execute(:create, params)
end
destroy(id) click to toggle source
# File lib/cylons/rpc.rb, line 18
def destroy(id)
  execute(:destroy, id)
end
execute(rpc_method, *args) click to toggle source
# File lib/cylons/rpc.rb, line 22
def execute(rpc_method, *args)
  puts Thread.current.object_id

  ::ActiveRecord::Base.connection_pool.with_connection do
    puts ::ActiveRecord::Base.connection_pool.instance_variable_get("@connections").size
    begin
      if args.any?
        @last_response = self.class.model.send(rpc_method.to_sym, *args)
      else
        @last_response = self.class.model.send(rpc_method.to_sym)
      end

      @last_response
    rescue => e
      puts e.inspect
      @last_response = {:error => e.message}
    end
  end
end
find(id) click to toggle source
# File lib/cylons/rpc.rb, line 42
def find(id)
  execute(:find, id)
end
first() click to toggle source
# File lib/cylons/rpc.rb, line 46
def first
  execute(:first)
end
first_or_create(params) click to toggle source
# File lib/cylons/rpc.rb, line 50
def first_or_create(params)
  execute(:first_or_create, params)
end
last() click to toggle source
# File lib/cylons/rpc.rb, line 54
def last
  execute(:last)
end
save(id = nil, attributes) click to toggle source
# File lib/cylons/rpc.rb, line 66
def save(id = nil, attributes)
  if(id)
    execute(:update, id, attributes)
  else
    execute(:create, attributes)
  end
end
scope_by(params) click to toggle source
# File lib/cylons/rpc.rb, line 62
def scope_by(params)
  execute(:scope_by, params)
end
update(attributes) click to toggle source
# File lib/cylons/rpc.rb, line 74
def update(attributes)
  execute(:update, attributes.keys, attributes.values)
end