No commit activity in last 3 years
No release in over 3 years
Easy-to-use handlersocket from existing ActiveRecord Models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 0.2.18
~> 0.9.2.2
~> 2.11.0

Runtime

~> 2.3.12
 Project Readme

active_record_handlersocket

Gem Version Build Status Coverage Status Code Climate active_record_handlersocket API Documentation

HandlerSocket for ActiveRecord; depends handlersocket gem https://github.com/miyucy/handlersocket

Underconstruction

usage

Update your config/database.yml of rails project. (Available to set database same as AR read/write database.)

development_hs_read:
  host:     localhost
  port:     9998
  database: active_record_handler_socket

Define HandlerSocket index setting on your ActiveReocrd Model.

class Person < ActiveRecord::Base
  handlersocket :id, "PRIMARY", %W[id name age]
end

Call hsfind_by_#{key} of hsfind_multi_by_#{key} to get record(s) as ActiveRecord Object.

Person.hsfind_by_id(1)
#=> #<Person id: 1, name: "Bob Marley", age: 36>

Person.hsfind_multi_by_id(1, 2)
#=> [
#   #<Person id: 1, name: "Bob Marley", age: 36>,
#   #<Person id: 2, name: "Pharrell Wiiliams", age: 41>
# ]

development

Dev dependencies

bundle install --path=vendor

if handlersocket gem cannot install via bundle (using rbenv, etc..), do like following.

bundle config build.handlersocket --with-opt-include=/usr/local/include/handlersocket
bundle install --path=vendor

Prepare DB

rake db:prepare

create following items on MySQL.

key value
user rails
database (dev) active_record_handler_socket
database (test) active_record_handler_socket_test
tables people, hobbies

Try example on console

bundle exec irb
require 'examples/init'
#=> true

Person.create(:name => "Bob Marley", :age => 36, :status => false)

Person.find_by_id(1)
#=> #<Person id: 1, name: "Bob Marley", age: 36, status: false>
Person.hsfind_by_id(1)
#=> #<Person id: 1, name: "Bob Marley", age: 36, status: false>