ruby-hyperloop / hyper-mesh

The project has moved to Hyperstack!! - Synchronization of active record models across multiple clients using Pusher, ActionCable, or Polling
https://hyperstack.org/
MIT License
22 stars 12 forks source link

add ActiveRecord::Base.finder_method #12

Closed catmando closed 7 years ago

catmando commented 7 years ago
class Foo < ActiveRecord::Base
  finder_method :random do # will accept params
    offset(rand(Thing.count)).first
  end
end

on client:

Foo.random # returns a random Foo
Foo.random! # returns the last random Foo, and gets a new one

easy brute force implementation

  1. create a scope called random on server that returns the result of the block wrapped in a array
  2. on client automatically add the .first back to the scope