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

implement alias_attribute #81

Open catmando opened 6 years ago

mpantel commented 6 years ago

Also support Model#load for aliased attributes like:

module ActiveRecord
  module InstanceMethods
    def load(*attributes, &block)
      first_time = true
      ReactiveRecord.load do
        results = attributes.collect { |attr| send("#{model._dealias_attribute(attr)}#{'!' if first_time}") }
        results = yield(*results) if block
        first_time = false
        block.nil? && results.count == 1 ? results.first : results
      end
    end
  end
end