class ActiveFedora::Fedora

Constants

BLANK
SLASH

Public Class Methods

instance() click to toggle source
# File lib/active_fedora/fedora.rb, line 11
def instance
  register unless ActiveFedora::RuntimeRegistry.fedora_connection

  ActiveFedora::RuntimeRegistry.fedora_connection
end
new(config) click to toggle source
# File lib/active_fedora/fedora.rb, line 22
def initialize(config)
  @config = config

  validate_options
end
register(options = {}) click to toggle source
# File lib/active_fedora/fedora.rb, line 7
def register(options = {})
  ActiveFedora::RuntimeRegistry.fedora_connection = Fedora.new(ActiveFedora.fedora_config.credentials.merge(options))
end
reset!() click to toggle source
# File lib/active_fedora/fedora.rb, line 17
def reset!
  ActiveFedora::RuntimeRegistry.fedora_connection = nil
end

Public Instance Methods

authorized_connection() click to toggle source
# File lib/active_fedora/fedora.rb, line 88
def authorized_connection
  options = {}
  options[:ssl] = ssl_options if ssl_options
  options[:request] = request_options if request_options
  Faraday.new(host, options) do |conn|
    conn.response :encoding # use Faraday::Encoding middleware
    conn.adapter Faraday.default_adapter # net/http
    if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('2')
      conn.request :basic_auth, user, password
    else
      conn.request :authorization, :basic, user, password
    end
  end
end
base_path() click to toggle source
# File lib/active_fedora/fedora.rb, line 32
def base_path
  @config[:base_path] || SLASH
end
base_uri() click to toggle source
# File lib/active_fedora/fedora.rb, line 36
def base_uri
  host + base_path.sub(/\/$/, BLANK)
end
build_connection() click to toggle source
# File lib/active_fedora/fedora.rb, line 80
def build_connection
  # The InboundRelationConnection does provide more data, useful for
  # things like ldp:IndirectContainers, but it's imposes a significant
  # performance penalty on every request
  #   @connection ||= InboundRelationConnection.new(caching_connection(omit_ldpr_interaction_model: true))
  InitializingConnection.new(caching_connection(omit_ldpr_interaction_model: true), root_resource_path)
end
build_ntriples_connection() click to toggle source
# File lib/active_fedora/fedora.rb, line 111
def build_ntriples_connection
  ActiveFedora::InitializingConnection.new(ActiveFedora::CachingConnection.new(ntriples_connection, omit_ldpr_interaction_model: true), root_resource_path)
end
caching_connection(options = {}) click to toggle source
# File lib/active_fedora/fedora.rb, line 64
def caching_connection(options = {})
  CachingConnection.new(authorized_connection, options)
end
clean_connection() click to toggle source
# File lib/active_fedora/fedora.rb, line 60
def clean_connection
  @clean_connection ||= CleanConnection.new(connection)
end
connection() click to toggle source
# File lib/active_fedora/fedora.rb, line 56
def connection
  @connection ||= build_connection
end
host() click to toggle source
# File lib/active_fedora/fedora.rb, line 28
def host
  @config[:url].sub(/\/$/, BLANK)
end
ldp_resource_service() click to toggle source
# File lib/active_fedora/fedora.rb, line 68
def ldp_resource_service
  @service ||= LdpResourceService.new(connection)
end
ntriples_connection() click to toggle source
# File lib/active_fedora/fedora.rb, line 107
def ntriples_connection
  authorized_connection.tap { |conn| conn.headers['Accept'] = 'application/n-triples' }
end
password() click to toggle source
# File lib/active_fedora/fedora.rb, line 44
def password
  @config[:password]
end
request_options() click to toggle source
# File lib/active_fedora/fedora.rb, line 52
def request_options
  @config[:request]
end
root_resource_path() click to toggle source

Remove a leading slash from the base_path

# File lib/active_fedora/fedora.rb, line 76
def root_resource_path
  @root_resource_path ||= base_path.sub(SLASH, BLANK)
end
ssl_options() click to toggle source
# File lib/active_fedora/fedora.rb, line 48
def ssl_options
  @config[:ssl]
end
user() click to toggle source
# File lib/active_fedora/fedora.rb, line 40
def user
  @config[:user]
end
validate_options() click to toggle source
# File lib/active_fedora/fedora.rb, line 103
def validate_options
  ActiveFedora::Base.logger.warn "Fedora URL (#{host}) does not end with /rest. This could be a problem. Check your fedora.yml config" unless host.downcase.end_with?("/rest")
end