Sha256: a15a914bfea1d4cd52f2c4cfe7a222e056a82bdfaf3cc0fd7cefb6648489fca8

Contents?: true

Size: 1.88 KB

Versions: 10

Compression:

Stored size: 1.88 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 attribute
        CmsRestApi.post(
          endpoint('attributes'),
          :attribute => {
            :name => attribute_name,
            :type => :text,
          }
        )

        # Create obj class
        CmsRestApi.post(
          endpoint('obj_classes'),
          :obj_class => {
            :name => obj_class_name,
            :attributes => [attribute_name],
            :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)
        "revisions/#{Workspace.current.revision_id}/#{path}"
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.9.0.3.197272233 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-6.8.3.174.51542603 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-6.8.3.115.227021242 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-6.8.3.73.75172665 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-6.8.3.2.153416031 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-6.8.3.67.110847540 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-6.8.3.1.23895778 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-6.8.2.36.82613853 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-6.8.2.7.128454143 lib/rails_connector/migrations/cms_backend.rb
infopark_cloud_connector-6.8.1.26.236500544 lib/rails_connector/migrations/cms_backend.rb