1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-11 22:24:21 +01:00
fab-manager/app/models/concerns/openlab_sync.rb
2022-12-21 14:12:14 +01:00

45 lines
964 B
Ruby

# frozen_string_literal: false
# module definition
module OpenlabSync
extend ActiveSupport::Concern
included do
after_create :openlab_create, if: :openlab_sync_active?
after_update :openlab_update, if: :openlab_sync_active?
after_destroy :openlab_destroy, if: :openlab_sync_active?
def openlab_create
OpenlabWorker.perform_in(2.seconds, :create, id) if published?
end
def openlab_update
return unless published?
if state_was == 'draft'
OpenlabWorker.perform_async(:create, id)
else
OpenlabWorker.perform_async(:update, id)
end
end
def openlab_destroy
OpenlabWorker.perform_async(:destroy, id)
end
def openlab_attributes
OpenLabService.to_hash(self)
end
def openlab_sync_active?
self.class.openlab_sync_active?
end
end
class_methods do
def openlab_sync_active?
Setting.get('openlab_app_secret').present?
end
end
end