Class: ActiveSync::Sync
- Inherits:
-
Object
- Object
- ActiveSync::Sync
- Defined in:
- app/models/active_sync/sync.rb
Class Method Summary collapse
- .sync_associations(record, args) ⇒ Object
- .sync_attributes(model, args) ⇒ Object
-
.sync_record(record, args) ⇒ Object
Hash used in all general sync communication for a given model.
Class Method Details
.sync_associations(record, args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/active_sync/sync.rb', line 31 def self.sync_associations record, args args.reduce([]) do |associations, option| case option when :all_attributes_and_associations, :all_attributes associations + record.class.reflect_on_all_associations.map { |a| a.name } when ->(option){ option.is_a?(Hash) } associations + option[:associations] else raise "Unknown sync associations option #{option.inspect}" end associations end end |
.sync_attributes(model, args) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/models/active_sync/sync.rb', line 4 def self.sync_attributes model, args @@sync_attributes ||= args.reduce([]) do |array, option| case option when :all_attributes_and_associations, :all_attributes array + model.column_names.map(&:to_sym) when ->(option){ option.is_a?(Hash) } array + option[:attributes] else raise "Unknown sync record option #{option.inspect}" end end end |
.sync_record(record, args) ⇒ Object
Hash used in all general sync communication for a given model.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/active_sync/sync.rb', line 18 def self.sync_record record, args args.reduce({}) do |hash, option| case option when :all_attributes_and_associations, :all_attributes hash.merge(record.attributes) when ->(option){ option.is_a?(Hash) } option[:attributes]&.reduce(hash) { |h, attr| h[attr] = record.call(attr) } else raise "Unknown sync record option #{option.inspect}" end end end |