Sha256: 8b4a26645118f14bff616c5fd8a72f01cf04db89d28d9f0a66e09587e5ddd01b

Contents?: true

Size: 913 Bytes

Versions: 51

Compression:

Stored size: 913 Bytes

Contents

require 'singleton'

module Scrivito
  module Migrations
    class WorkspaceLock
      include Singleton

      def get
        if exists?
          begin
            Workspace.find(workspace_id)
          rescue Scrivito::ResourceNotFound
            create_workspace
          end
        else
          create_workspace
        end
      end

      def remove
        if exists?
          File.delete(filename)
        end
      end

      def exists?
        File.exist?(filename)
      end

      private

      def create_workspace
        Workspace.create(title: 'Migration Working Copy').tap do |workspace|
          write(workspace)
        end
      end

      def write(workspace)
        File.write(filename, workspace.id)
      end

      def workspace_id
        File.read(filename)
      end

      def filename
        File.join(Rails.root, 'tmp/migration_store.lock')
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
scrivito_sdk-1.18.0 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.18.0.rc1 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.17.0 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.17.0.rc3 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.17.0.rc2 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.17.0.rc1 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.16.0 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.16.0.rc2 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.16.0.rc1 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.15.0 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.15.0.rc2 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.15.0.rc1 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.14.0 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.14.0.rc3 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.14.0.rc2 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.14.0.rc1 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.13.0 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.13.0.rc2 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.13.0.rc1 app/cms/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.12.0 app/cms/scrivito/migrations/workspace_lock.rb