Class: Synced::Strategies::Full
- Inherits:
-
Object
- Object
- Synced::Strategies::Full
- Includes:
- AttributesAsHash
- Defined in:
- lib/synced/strategies/full.rb
Overview
This strategy performs full synchronization. It takes all the objects from the API and
- creates missing in the local database
- removes local objects which are missing the API
- updates local objects which are changed in the API
This is the base synchronization strategy.
Direct Known Subclasses
Defined Under Namespace
Classes: MissingAPIClient
Instance Method Summary collapse
-
#initialize(model_class, options = {}) ⇒ Full
constructor
Initializes new Full sync strategy.
- #perform ⇒ Object
- #reset_synced ⇒ Object
Methods included from AttributesAsHash
Constructor Details
#initialize(model_class, options = {}) ⇒ Full
Initializes new Full sync strategy
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/synced/strategies/full.rb', line 50 def initialize(model_class, = {}) @model_class = model_class @synced_endpoint = [:synced_endpoint] @scope = [:scope] @id_key = [:id_key] @data_key = [:data_key] @only_updated = [:only_updated] @include = [:include] @local_attributes = synced_attributes_as_hash([:local_attributes]) @api = [:api] @mapper = [:mapper].respond_to?(:call) ? [:mapper].call : [:mapper] @fields = [:fields] @remove = [:remove] @associations = Array.wrap([:associations]) @association_sync = [:association_sync] @perform_request = [:remote].nil? && !@association_sync @remote_objects = Array.wrap([:remote]) unless @perform_request @globalized_attributes = synced_attributes_as_hash([:globalized_attributes]) @query_params = [:query_params] @auto_paginate = [:auto_paginate] @transaction_per_page = [:transaction_per_page] @handle_processed_objects_proc = [:handle_processed_objects_proc] @remote_objects_ids = [] end |
Instance Method Details
#perform ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/synced/strategies/full.rb', line 76 def perform instrument("perform.synced", model: @model_class) do processed_objects = instrument("sync_perform.synced", model: @model_class) do process_remote_objects(remote_objects_persistor) end relation_scope.transaction do instrument("remove_perform.synced", model: @model_class) do remove_relation.send(remove_strategy) if @remove end end processed_objects end end |
#reset_synced ⇒ Object
90 91 92 |
# File 'lib/synced/strategies/full.rb', line 90 def reset_synced RuntimeError.new("Full strategy does not support reset_synced functionality") end |