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
14 15 16 |
# File 'lib/db/sync/model.rb', line 14 def self.include_id? attribute_names.include?('id') end |
.ordered_attributes ⇒ Object
26 27 28 |
# File 'lib/db/sync/model.rb', line 26 def self.ordered_attributes pkey + (attribute_names - pkey).sort end |
.pkey ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/db/sync/model.rb', line 18 def self.pkey if include_id? ['id'] else attribute_names.sort end end |
.records ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/db/sync/model.rb', line 30 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
8 9 10 11 12 |
# File 'lib/db/sync/model.rb', line 8 def compare_unique_data(other) self.class.pkey.each do |key| attributes[key] <=> other[key] end end |
#unique_data ⇒ Object
4 5 6 |
# File 'lib/db/sync/model.rb', line 4 def unique_data attributes.slice(*self.class.pkey) end |