Sha256: fb04c355c7846e0455d92a8050d6037cbc38ec598b74477166353f0512ae293f

Contents?: true

Size: 1.25 KB

Versions: 22

Compression:

Stored size: 1.25 KB

Contents

module ActiveFedora
  class InitializingConnection < Delegator
    attr_reader :connection, :root_resource_path

    def initialize(connection, root_resource_path)
      super(connection)
      @connection = connection
      @root_resource_path = root_resource_path
      @initialized = false
    end

    def __getobj__
      @connection
    end

    def __setobj__(connection)
      @connection = connection
    end

    def head(*)
      init_base_path
      super
    end

    def get(*)
      init_base_path
      super
    end

    def delete(*)
      init_base_path
      super
    end

    def post(*)
      init_base_path
      super
    end

    def put(*)
      init_base_path
      super
    end

    def patch(*)
      init_base_path
      super
    end

    private

      # Call this to create a Container Resource to act as the base path for this connection
      def init_base_path
        return if @initialized

        connection.head(root_resource_path)
        ActiveFedora::Base.logger.info "Attempted to init base path `#{root_resource_path}`, but it already exists" if ActiveFedora::Base.logger
        @initialized = true
        false
      rescue Ldp::NotFound
        @initialized = connection.put(root_resource_path, '').success?
      end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
active-fedora-10.3.0 lib/active_fedora/initializing_connection.rb
active-fedora-11.0.1 lib/active_fedora/initializing_connection.rb
active-fedora-11.0.0 lib/active_fedora/initializing_connection.rb
active-fedora-10.3.0.rc2 lib/active_fedora/initializing_connection.rb
active-fedora-11.0.0.rc7 lib/active_fedora/initializing_connection.rb
active-fedora-10.3.0.rc1 lib/active_fedora/initializing_connection.rb
active-fedora-11.0.0.rc6 lib/active_fedora/initializing_connection.rb
active-fedora-10.2.1 lib/active_fedora/initializing_connection.rb
active-fedora-11.0.0.rc5 lib/active_fedora/initializing_connection.rb
active-fedora-11.0.0.rc4 lib/active_fedora/initializing_connection.rb
active-fedora-10.2.0 lib/active_fedora/initializing_connection.rb
active-fedora-11.0.0.rc3 lib/active_fedora/initializing_connection.rb
active-fedora-11.0.0.rc2 lib/active_fedora/initializing_connection.rb
active-fedora-11.0.0.rc1 lib/active_fedora/initializing_connection.rb
active-fedora-10.1.0 lib/active_fedora/initializing_connection.rb
active-fedora-10.1.0.rc1 lib/active_fedora/initializing_connection.rb
active-fedora-10.0.0 lib/active_fedora/initializing_connection.rb
active-fedora-10.0.0.beta4 lib/active_fedora/initializing_connection.rb
active-fedora-10.0.0.beta3 lib/active_fedora/initializing_connection.rb
active-fedora-10.0.0.beta2 lib/active_fedora/initializing_connection.rb