Class: ActiveFedora::Fedora

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/fedora.rb

Constant Summary collapse

SLASH =
'/'.freeze
BLANK =
''.freeze

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Fedora

Returns a new instance of Fedora.



3
4
5
6
# File 'lib/active_fedora/fedora.rb', line 3

def initialize(config)
  @config = config
  init_base_path
end

Instance Method Details

#authorized_connectionObject



56
57
58
59
60
# File 'lib/active_fedora/fedora.rb', line 56

def authorized_connection
  connection = Faraday.new(host)
  connection.basic_auth(user, password)
  connection
end

#base_pathObject



12
13
14
# File 'lib/active_fedora/fedora.rb', line 12

def base_path
  @config[:base_path] || '/'
end

#clean_connectionObject



28
29
30
# File 'lib/active_fedora/fedora.rb', line 28

def clean_connection
  @clean_connection ||= CleanConnection.new(connection)
end

#connectionObject



24
25
26
# File 'lib/active_fedora/fedora.rb', line 24

def connection
  @connection ||= InboundRelationConnection.new(CachingConnection.new(authorized_connection))
end

#hostObject



8
9
10
# File 'lib/active_fedora/fedora.rb', line 8

def host
  @config[:url]
end

#init_base_pathObject

Call this to create a Container Resource to act as the base path for this connection



40
41
42
43
44
45
46
47
48
49
# File 'lib/active_fedora/fedora.rb', line 40

def init_base_path
  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
  false
rescue Ldp::NotFound
  if !host.downcase.end_with?("/rest")
    ActiveFedora::Base.logger.warn "Fedora URL (#{host}) does not end with /rest. This could be a problem. Check your fedora.yml config"
  end
  connection.put(root_resource_path, BLANK).success?
end

#ldp_resource_serviceObject



32
33
34
# File 'lib/active_fedora/fedora.rb', line 32

def ldp_resource_service
  @service ||= LdpResourceService.new(connection)
end

#passwordObject



20
21
22
# File 'lib/active_fedora/fedora.rb', line 20

def password
  @config[:password]
end

#root_resource_pathObject

Remove a leading slash from the base_path



52
53
54
# File 'lib/active_fedora/fedora.rb', line 52

def root_resource_path
  @root_resource_path ||= base_path.sub(SLASH, BLANK)
end

#userObject



16
17
18
# File 'lib/active_fedora/fedora.rb', line 16

def user
  @config[:user]
end