Sha256: f44bda8a95b5624a8783a9bb0fb60f47b44dff8853ef4c3d0dba5a22cb70b9b3

Contents?: true

Size: 1.78 KB

Versions: 4

Compression:

Stored size: 1.78 KB

Contents

module RailsConnector
  module Migrations
    class CmsBackend
      def read
        obj = find_migration_store_obj

        if obj
          obj[attribute_name]
        else
          initial_value
        end
      end

      def save(value)
        CmsRestApi.put(
          endpoint("objs/#{migration_store_obj.id}"),
          :obj => {
            attribute_name => value
          }
        )
      end

      private

      def create
        # Create obj class
        CmsRestApi.post(
          endpoint('obj_classes'),
          :obj_class => {
            :name => obj_class_name,
            :attributes => [
              {
                :name => attribute_name,
                :type => :text,
              },
            ],
            :type => :publication,
            :title => obj_class_name,
          }
        )

        # Create obj
        CmsRestApi.post(
          endpoint('objs'),
          :obj => {
            :_path => path,
            :_obj_class => obj_class_name,
            attribute_name => initial_value,
          }
        )

        # Deactivate obj class
        CmsRestApi.put(
          endpoint("obj_classes/#{obj_class_name}"),
          :obj_class => {
            :is_active => false,
          }
        )
      end

      def migration_store_obj
        unless find_migration_store_obj
          create
        end

        find_migration_store_obj
      end

      def find_migration_store_obj
        Obj.find_by_path(path)
      end

      def attribute_name
        'versions'
      end

      def obj_class_name
        'MigrationStore'
      end

      def path
        '/_internal/migration-store'
      end

      def initial_value
        ''
      end

      def endpoint(path)
        "workspaces/#{Workspace.current.id}/#{path}"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
infopark_cloud_connector-7.1.0 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-7.0.2 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-7.0.1 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-7.0.0 lib/rails_connector/migrations/cms_backend.rb