1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-06 21:46:17 +01:00
fab-manager/app/models/concerns/openlab_sync.rb

44 lines
940 B
Ruby

# frozen_string_literal: false
# module definition
module OpenlabSync
extend ActiveSupport::Concern
included do
after_save :openlab_create_or_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_create_or_update
return unless published?
if state_was == 'draft' || state_was.nil?
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