Sha256: c67f9f55394060bc78b7b42b7bbac5b4f8b6d24cb7a9977ae38b399d9e6722cb

Contents?: true

Size: 708 Bytes

Versions: 9

Compression:

Stored size: 708 Bytes

Contents

class Db::Sync::Model < ActiveRecord::Base
  @abstract_class = true

  def unique_data
    attributes.slice(*self.class.pkey)
  end

  def compare_unique_data(other)
    self.class.pkey.each do |key|
      attributes[key] <=> other[key]
    end
  end

  def self.include_id?
    attribute_names.include?('id')
  end

  def self.pkey
    if include_id?
      ['id']
    else
      attribute_names.sort
    end
  end

  def self.ordered_attributes
    pkey + (attribute_names - pkey).sort
  end

  def self.records
    attributes_order = ordered_attributes
    order(pkey).map do |record|
      res = {}
      attributes_order.each do |key|
        res[key] = record[key]
      end
      res
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
db-sync-0.0.13 lib/db/sync/model.rb
db-sync-0.0.12 lib/db/sync/model.rb
db-sync-0.0.11 lib/db/sync/model.rb
db-sync-0.0.10 lib/db/sync/model.rb
db-sync-0.0.9 lib/db/sync/model.rb
db-sync-0.0.8 lib/db/sync/model.rb
db-sync-0.0.7 lib/db/sync/model.rb
db-sync-0.0.6 lib/db/sync/model.rb
db-sync-0.0.5 lib/db/sync/model.rb