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
- #request_options ⇒ 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.
22 23 24 25 26 |
# File 'lib/active_fedora/fedora.rb', line 22 def initialize(config) @config = config end |
Class Method Details
.instance ⇒ Object
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( = {}) ActiveFedora::RuntimeRegistry.fedora_connection = Fedora.new(ActiveFedora.fedora_config.credentials.merge()) 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_connection ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/active_fedora/fedora.rb', line 90 def = {} [:ssl] = if [:request] = if Faraday.new(host, ) do |conn| conn.response :encoding # use Faraday::Encoding middleware conn.adapter Faraday.default_adapter # net/http conn.basic_auth(user, password) end end |
#base_path ⇒ Object
32 33 34 |
# File 'lib/active_fedora/fedora.rb', line 32 def base_path @config[:base_path] || SLASH end |
#base_uri ⇒ Object
36 37 38 |
# File 'lib/active_fedora/fedora.rb', line 36 def base_uri host + base_path.sub(/\/$/, BLANK) end |
#build_connection ⇒ Object
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( = {}) CachingConnection.new(, ) end |
#clean_connection ⇒ Object
62 63 64 |
# File 'lib/active_fedora/fedora.rb', line 62 def clean_connection @clean_connection ||= CleanConnection.new(connection) end |
#connection ⇒ Object
56 57 58 59 60 |
# File 'lib/active_fedora/fedora.rb', line 56 def connection @connection ||= begin build_connection end end |
#host ⇒ Object
28 29 30 |
# File 'lib/active_fedora/fedora.rb', line 28 def host @config[:url].sub(/\/$/, BLANK) end |
#ldp_resource_service ⇒ Object
70 71 72 |
# File 'lib/active_fedora/fedora.rb', line 70 def ldp_resource_service @service ||= LdpResourceService.new(connection) end |
#password ⇒ Object
44 45 46 |
# File 'lib/active_fedora/fedora.rb', line 44 def password @config[:password] end |
#request_options ⇒ Object
52 53 54 |
# File 'lib/active_fedora/fedora.rb', line 52 def @config[:request] end |
#root_resource_path ⇒ Object
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_options ⇒ Object
48 49 50 |
# File 'lib/active_fedora/fedora.rb', line 48 def @config[:ssl] end |
#user ⇒ Object
40 41 42 |
# File 'lib/active_fedora/fedora.rb', line 40 def user @config[:user] end |
#validate_options ⇒ Object
101 102 103 104 105 |
# File 'lib/active_fedora/fedora.rb', line 101 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 |