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
 - #build_ntriples_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
 - #ntriples_connection ⇒ 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
      88 89 90 91 92 93 94 95 96 97 98 99 100 101  | 
    
      # File 'lib/active_fedora/fedora.rb', line 88 def = {} [:ssl] = if [:request] = if Faraday.new(host, ) do |conn| conn.response :encoding # use Faraday::Encoding middleware conn.adapter Faraday.default_adapter # net/http if Gem::Version.new(Faraday::VERSION) < Gem::Version.new('2') conn.request :basic_auth, user, password else conn.request :authorization, :basic, user, password end 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
      80 81 82 83 84 85 86  | 
    
      # File 'lib/active_fedora/fedora.rb', line 80 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  | 
  
#build_ntriples_connection ⇒ Object
      111 112 113  | 
    
      # File 'lib/active_fedora/fedora.rb', line 111 def build_ntriples_connection ActiveFedora::InitializingConnection.new(ActiveFedora::CachingConnection.new(ntriples_connection, omit_ldpr_interaction_model: true), root_resource_path) end  | 
  
#caching_connection(options = {}) ⇒ Object
      64 65 66  | 
    
      # File 'lib/active_fedora/fedora.rb', line 64 def caching_connection( = {}) CachingConnection.new(, ) end  | 
  
#clean_connection ⇒ Object
      60 61 62  | 
    
      # File 'lib/active_fedora/fedora.rb', line 60 def clean_connection @clean_connection ||= CleanConnection.new(connection) end  | 
  
#connection ⇒ Object
      56 57 58  | 
    
      # File 'lib/active_fedora/fedora.rb', line 56 def connection @connection ||= build_connection 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
      68 69 70  | 
    
      # File 'lib/active_fedora/fedora.rb', line 68 def ldp_resource_service @service ||= LdpResourceService.new(connection) end  | 
  
#ntriples_connection ⇒ Object
      107 108 109  | 
    
      # File 'lib/active_fedora/fedora.rb', line 107 def ntriples_connection .tap { |conn| conn.headers['Accept'] = 'application/n-triples' } 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
      76 77 78  | 
    
      # File 'lib/active_fedora/fedora.rb', line 76 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
      103 104 105  | 
    
      # File 'lib/active_fedora/fedora.rb', line 103 def ActiveFedora::Base.logger.warn "Fedora URL (#{host}) does not end with /rest. This could be a problem. Check your fedora.yml config" unless host.downcase.end_with?("/rest") end  |