Class: ActiveFedora::Fedora
- Inherits:
-
Object
- Object
- ActiveFedora::Fedora
- Defined in:
- lib/active_fedora/fedora.rb
Constant Summary collapse
- SLASH =
'/'.freeze
- BLANK =
''.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #authorized_connection ⇒ Object
- #base_path ⇒ Object
- #base_uri ⇒ Object
- #build_connection ⇒ Object
- #caching_connection(options = {}) ⇒ Object
- #clean_connection ⇒ Object
- #connection ⇒ Object
- #host ⇒ Object
-
#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
- #validate_options ⇒ Object
Constructor Details
#initialize(config) ⇒ Fedora
Returns a new instance of Fedora.
19 20 21 22 23 |
# File 'lib/active_fedora/fedora.rb', line 19 def initialize(config) @config = config end |
Class Method Details
.instance ⇒ Object
8 9 10 11 12 |
# File 'lib/active_fedora/fedora.rb', line 8 def instance register unless ActiveFedora::RuntimeRegistry.fedora_connection ActiveFedora::RuntimeRegistry.fedora_connection end |
.register(options = {}) ⇒ Object
4 5 6 |
# File 'lib/active_fedora/fedora.rb', line 4 def register( = {}) ActiveFedora::RuntimeRegistry.fedora_connection = Fedora.new(ActiveFedora.fedora_config.credentials.merge()) end |
.reset! ⇒ Object
14 15 16 |
# File 'lib/active_fedora/fedora.rb', line 14 def reset! ActiveFedora::RuntimeRegistry.fedora_connection = nil end |
Instance Method Details
#authorized_connection ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/active_fedora/fedora.rb', line 83 def = {} [:ssl] = if connection = Faraday.new(host, ) connection.basic_auth(user, password) connection end |
#base_path ⇒ Object
29 30 31 |
# File 'lib/active_fedora/fedora.rb', line 29 def base_path @config[:base_path] || SLASH end |
#base_uri ⇒ Object
33 34 35 |
# File 'lib/active_fedora/fedora.rb', line 33 def base_uri host + base_path.sub(/\/$/, BLANK) end |
#build_connection ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/active_fedora/fedora.rb', line 75 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
59 60 61 |
# File 'lib/active_fedora/fedora.rb', line 59 def caching_connection( = {}) CachingConnection.new(, ) end |
#clean_connection ⇒ Object
55 56 57 |
# File 'lib/active_fedora/fedora.rb', line 55 def clean_connection @clean_connection ||= CleanConnection.new(connection) end |
#connection ⇒ Object
49 50 51 52 53 |
# File 'lib/active_fedora/fedora.rb', line 49 def connection @connection ||= begin build_connection end end |
#host ⇒ Object
25 26 27 |
# File 'lib/active_fedora/fedora.rb', line 25 def host @config[:url].sub(/\/$/, BLANK) end |
#ldp_resource_service ⇒ Object
63 64 65 |
# File 'lib/active_fedora/fedora.rb', line 63 def ldp_resource_service @service ||= LdpResourceService.new(connection) end |
#password ⇒ Object
41 42 43 |
# File 'lib/active_fedora/fedora.rb', line 41 def password @config[:password] end |
#root_resource_path ⇒ Object
Remove a leading slash from the base_path
71 72 73 |
# File 'lib/active_fedora/fedora.rb', line 71 def root_resource_path @root_resource_path ||= base_path.sub(SLASH, BLANK) end |
#ssl_options ⇒ Object
45 46 47 |
# File 'lib/active_fedora/fedora.rb', line 45 def @config[:ssl] end |
#user ⇒ Object
37 38 39 |
# File 'lib/active_fedora/fedora.rb', line 37 def user @config[:user] end |
#validate_options ⇒ Object
91 92 93 94 95 |
# File 'lib/active_fedora/fedora.rb', line 91 def 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 |