Sha256: 5356e1cb5b406f034465746f49df9654fd69442993748be2b1761aa54bd1904a

Contents?: true

Size: 914 Bytes

Versions: 59

Compression:

Stored size: 914 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.exists?(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

59 entries across 59 versions & 1 rubygems

Version Path
scrivito_sdk-1.5.5 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.5.rc1 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.4.3 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.4 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.4.rc1 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.3 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.3.rc1 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.2 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.2.rc1 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.1 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.1.rc2 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.1.rc1 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.0 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.0.rc2 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.5.0.rc1 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.4.2 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.4.1 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.4.1.rc1 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.4.0 lib/scrivito/migrations/workspace_lock.rb
scrivito_sdk-1.4.0.rc2 lib/scrivito/migrations/workspace_lock.rb