Module: RubySync::Connectors::ConnectorEventProcessing
- Included in:
- BaseConnector
- Defined in:
- lib/ruby_sync/connectors/connector_event_processing.rb
Overview
This is included into BaseConnector.
Instance Method Summary collapse
- #associated_path(event) ⇒ Object
- #clean ⇒ Object
- #delete_from_mirror(path) ⇒ Object
-
#perform_add(event) ⇒ Object
Add a record to the connected store.
- #perform_delete(event) ⇒ Object
- #perform_modify(event) ⇒ Object
- #process(event) ⇒ Object
- #update_mirror(path) ⇒ Object
Instance Method Details
#associated_path(event) ⇒ Object
93 94 95 |
# File 'lib/ruby_sync/connectors/connector_event_processing.rb', line 93 def associated_path event (is_vault?)? path_for_association(event.association) : path_for_own_association_key(event.association.key) end |
#clean ⇒ Object
88 89 90 91 |
# File 'lib/ruby_sync/connectors/connector_event_processing.rb', line 88 def clean remove_associations if respond_to? :remove_associations remove_mirror if respond_to? :remove_mirror end |
#delete_from_mirror(path) ⇒ Object
85 86 |
# File 'lib/ruby_sync/connectors/connector_event_processing.rb', line 85 def delete_from_mirror path end |
#perform_add(event) ⇒ Object
Add a record to the connected store. If acting as vault, also associate with the attached association key for later retrieval. This implementation assumes that the target path is used. Connectors that make up their own key on creation of a record will need to override this.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruby_sync/connectors/connector_event_processing.rb', line 38 def perform_add event log.info "Adding '#{event.target_path}' to '#{name}'" raise Exception.new("#{name}: Entry with path '#{event.target_path}' already exists, add failing.") if self[event.target_path] if is_vault? && event.association && path_for_association(event.association) log.warn("#{name}: Removing obsolete association (#{event.association.to_s}) found for non-existent #{event.target_path}.") self.remove_association(event.association) end # call_if_exists(:target_transform, event) if add(event.target_path, event.payload) log.info "Add succeeded" update_mirror event.target_path if is_vault? if event.association associate(event.association, event.target_path) else raise Exception.new("#{name}: No association key supplied to add.") end else return own_association_key_for(event.target_path) end else log.warn "Failed to add '#{event.target_path}' to '#{name}'" return false end end |
#perform_delete(event) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/ruby_sync/connectors/connector_event_processing.rb', line 64 def perform_delete event raise Exception.new("#{name}: Delete of unassociated object. No action taken.") unless event.association path = associated_path event log.info "Deleting '#{path}' from '#{name}'" delete(path) or log.warn("#{name}: Attempted to delete non-existent entry '#{path}'\nMay be an echo of a delete from this connector, ignoring.") delete_from_mirror path return nil # don't want to create any new associations end |
#perform_modify(event) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/ruby_sync/connectors/connector_event_processing.rb', line 73 def perform_modify event path = associated_path event raise Exception.new("#{name}: Attempted to modify non-existent entry '#{path}'") unless self[path] #call_if_exists(:target_transform, event) modify path, event.payload update_mirror path return (is_vault?)? nil : own_association_key_for(event.target_path) end |
#process(event) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_sync/connectors/connector_event_processing.rb', line 24 def process(event) perform_transform(:target_transform, event, name) case event.type when :add then return perform_add(event) when :delete then return perform_delete(event) when :modify then return perform_modify(event) else raise Exception.new("#{name}: Unknown event type '#{event.type}' received") end end |
#update_mirror(path) ⇒ Object
82 83 |
# File 'lib/ruby_sync/connectors/connector_event_processing.rb', line 82 def update_mirror path end |