Class: Db::Sync::Model
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Db::Sync::Model
- Defined in:
- lib/db/sync/model.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.include_id? ⇒ Boolean
16 17 18 |
# File 'lib/db/sync/model.rb', line 16 def self.include_id? attribute_names.include?('id') end |
.ordered_attributes ⇒ Object
28 29 30 |
# File 'lib/db/sync/model.rb', line 28 def self.ordered_attributes pkey + (attribute_names - pkey).sort end |
.pkey ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/db/sync/model.rb', line 20 def self.pkey if include_id? ['id'] else attribute_names.sort end end |
.records ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/db/sync/model.rb', line 32 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 |
Instance Method Details
#compare_unique_data(other) ⇒ Object
10 11 12 13 14 |
# File 'lib/db/sync/model.rb', line 10 def compare_unique_data(other) self.class.pkey.each do |key| attributes[key] <=> other[key] end end |
#unique_data ⇒ Object
6 7 8 |
# File 'lib/db/sync/model.rb', line 6 def unique_data attributes.slice(*self.class.pkey) end |