Class: ActiveFedora::Fedora
- Inherits:
-
Object
- Object
- ActiveFedora::Fedora
- Defined in:
- lib/active_fedora/fedora.rb
Constant Summary collapse
- SLASH =
'/'.freeze
- BLANK =
''.freeze
Instance Method Summary collapse
- #authorized_connection ⇒ Object
- #base_path ⇒ Object
- #build_connection ⇒ Object
- #clean_connection ⇒ Object
- #connection ⇒ Object
- #host ⇒ Object
-
#init_base_path ⇒ Object
Call this to create a Container Resource to act as the base path for this connection.
-
#initialize(config) ⇒ Fedora
constructor
A new instance of Fedora.
- #ldp_resource_service ⇒ Object
- #password ⇒ Object
-
#root_resource_path ⇒ Object
Remove a leading slash from the base_path.
- #ssl_options ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(config) ⇒ Fedora
Returns a new instance of Fedora.
3 4 5 |
# File 'lib/active_fedora/fedora.rb', line 3 def initialize(config) @config = config end |
Instance Method Details
#authorized_connection ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/active_fedora/fedora.rb', line 74 def = {} [:ssl] = if connection = Faraday.new(host, ) connection.basic_auth(user, password) connection end |
#base_path ⇒ Object
11 12 13 |
# File 'lib/active_fedora/fedora.rb', line 11 def base_path @config[:base_path] || '/' end |
#build_connection ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/active_fedora/fedora.rb', line 66 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(CachingConnection.new(authorized_connection)) CachingConnection.new(, omit_ldpr_interaction_model: true) end |
#clean_connection ⇒ Object
34 35 36 |
# File 'lib/active_fedora/fedora.rb', line 34 def clean_connection @clean_connection ||= CleanConnection.new(connection) end |
#connection ⇒ Object
27 28 29 30 31 32 |
# File 'lib/active_fedora/fedora.rb', line 27 def connection @connection ||= begin init_base_path build_connection end end |
#host ⇒ Object
7 8 9 |
# File 'lib/active_fedora/fedora.rb', line 7 def host @config[:url] end |
#init_base_path ⇒ Object
Call this to create a Container Resource to act as the base path for this connection
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/active_fedora/fedora.rb', line 46 def init_base_path return if @initialized connection = build_connection 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 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 @initialized = connection.put(root_resource_path, BLANK).success? end |
#ldp_resource_service ⇒ Object
38 39 40 |
# File 'lib/active_fedora/fedora.rb', line 38 def ldp_resource_service @service ||= LdpResourceService.new(connection) end |
#password ⇒ Object
19 20 21 |
# File 'lib/active_fedora/fedora.rb', line 19 def password @config[:password] end |
#root_resource_path ⇒ Object
Remove a leading slash from the base_path
62 63 64 |
# File 'lib/active_fedora/fedora.rb', line 62 def root_resource_path @root_resource_path ||= base_path.sub(SLASH, BLANK) end |
#ssl_options ⇒ Object
23 24 25 |
# File 'lib/active_fedora/fedora.rb', line 23 def @config[:ssl] end |
#user ⇒ Object
15 16 17 |
# File 'lib/active_fedora/fedora.rb', line 15 def user @config[:user] end |