module Mumuki::Domain::Syncable
Mixin for objects that may be treated as `Mumukit::Sync` resources
`Syncable` objects also get `Mumukit::Platform::Notifiable` by free
Public Instance Methods
:warning: This method is required by `Mumukit::Platform::Notifiable#notify!`
# File lib/mumuki/domain/syncable.rb, line 35 def platform_class_name sync_key_kind.as_module_name end
Generates a sync key
:warning: This method is required by `Mumukit::Sync::Syncer#import!`
# File lib/mumuki/domain/syncable.rb, line 12 def sync_key Mumukit::Sync.key sync_key_kind, sync_key_id end
Private Instance Methods
# File lib/mumuki/domain/syncable.rb, line 85 def extract_sync_key_id(resource_h) resource_h[sync_key_id_field] end
Locates and imports a resource, extracting its key directly from the resource-hash.
This class-message is not required by `Mumukit::Sync` but it is exposed for convenience when needing to import resources for whom we already have a resource-hash representation and we don't need to fetch them from a `Mumukit::Sync::Store`.
# File lib/mumuki/domain/syncable.rb, line 79 def import_from_resource_h!(resource_h) locate_resource(extract_sync_key_id(resource_h)).tap do |it| it.import_from_resource_h! resource_h end end
`locate!` is similar to `locate`, but fails instead of creating a a new object when not found
This method is not required by `Mumukit::Sync`
# File lib/mumuki/domain/syncable.rb, line 66 def locate!(sync_key_id) find_by! sync_key_id_field => sync_key_id rescue ActiveRecord::RecordNotFound raise ActiveRecord::RecordNotFound, "Couldn't find #{self.name} with #{sync_key_id_field}: #{sync_key_id}" end
:warning: This method is required by
-
`Mumukit::Sync::Syncer#import_all!`
-
`Mumukit::Sync::Syncer#locate_and_import!`
-
`Mumukit::Sync::Syncer#locate_and_export!`
# File lib/mumuki/domain/syncable.rb, line 58 def locate_resource(sync_key_id) find_or_initialize_by sync_key_id_field => sync_key_id end
# File lib/mumuki/domain/syncable.rb, line 45 def sync_key_id self[self.class.sync_key_id_field] end
# File lib/mumuki/domain/syncable.rb, line 41 def sync_key_kind self.class end