Sha256: 0767fa6c146b5a0e357130b36e173049b962efef8df1d943bd952ae729423c59

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

module ReactiveRecord
  # inspection_details is used by client side ActiveRecord::Base
  # runs down the possible states of a backing record and returns
  # the appropriate string.  The order of execution is important!
  module BackingRecordInspector
    def inspection_details
      return error_details    unless errors.empty?
      return new_details      if new?
      return destroyed_details if destroyed
      return loading_details  unless attributes.key? primary_key
      return dirty_details    unless changed_attributes.empty?
      "[loaded id: #{id}]"
    end

    def error_details
      id_str = "id: #{id} " unless new?
      "[errors #{id_str}#{errors.messages}]"
    end

    def new_details
      "[new #{attributes.select { |attr| column_type(attr) }}]"
    end

    def destroyed_details
      "[destroyed id: #{id}]"
    end

    def loading_details
      "[loading #{vector}]"
    end

    def dirty_details
      changes = Hash[changed_attributes.collect do |attr|
        [attr, [@synced_attributes[attr], attributes[attr]]] if column_type(attr)
      end.compact]
      "[changed id: #{id} #{changes}]"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hyper-mesh-1.0.0.lap27 lib/reactive_record/active_record/reactive_record/backing_record_inspector.rb