Class: ActiveFedora::Fedora

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

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Fedora

Returns a new instance of Fedora.



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

def initialize(config)
  @config = config

  validate_options
end

Class Method Details

.instanceObject



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

def instance
  register unless ActiveFedora::RuntimeRegistry.fedora_connection

  ActiveFedora::RuntimeRegistry.fedora_connection
end

.register(options = {}) ⇒ Object



7
8
9
# 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!Object



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

def reset!
  ActiveFedora::RuntimeRegistry.fedora_connection = nil
end

Instance Method Details

#authorized_connectionObject



90
91
92
93
94
95
96
97
98
99
# File 'lib/active_fedora/fedora.rb', line 90

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
    conn.basic_auth(user, password)
  end
end

#base_pathObject



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

def base_path
  @config[:base_path] || SLASH
end

#base_uriObject



36
37
38
# File 'lib/active_fedora/fedora.rb', line 36

def base_uri
  host + base_path.sub(/\/$/, BLANK)
end

#build_connectionObject



82
83
84
85
86
87
88
# File 'lib/active_fedora/fedora.rb', line 82

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

#caching_connection(options = {}) ⇒ Object



66
67
68
# File 'lib/active_fedora/fedora.rb', line 66

def caching_connection(options = {})
  CachingConnection.new(authorized_connection, options)
end

#clean_connectionObject



62
63
64
# File 'lib/active_fedora/fedora.rb', line 62

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

#connectionObject



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

def connection
  @connection ||= begin
    build_connection
  end
end

#hostObject



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

def host
  @config[:url].sub(/\/$/, BLANK)
end

#ldp_resource_serviceObject



70
71
72
# File 'lib/active_fedora/fedora.rb', line 70

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

#passwordObject



44
45
46
# File 'lib/active_fedora/fedora.rb', line 44

def password
  @config[:password]
end

#request_optionsObject



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

def request_options
  @config[:request]
end

#root_resource_pathObject

Remove a leading slash from the base_path



78
79
80
# File 'lib/active_fedora/fedora.rb', line 78

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

#ssl_optionsObject



48
49
50
# File 'lib/active_fedora/fedora.rb', line 48

def ssl_options
  @config[:ssl]
end

#userObject



40
41
42
# File 'lib/active_fedora/fedora.rb', line 40

def user
  @config[:user]
end

#validate_optionsObject



101
102
103
104
105
# File 'lib/active_fedora/fedora.rb', line 101

def validate_options
  unless 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
end