Class: SfxUrl

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/sfx_url.rb

Overview

Just an indexed list of URLs extracted from SFX, urls we believe are sfx-controlled. Kind of an ugly hack, kind of duplicates the local journal index if in use, but we need it to suppress catalog URLs if they duplicate what SFX ought to control.

Class Method Summary collapse

Class Method Details

.sfx_controls_url?(url) ⇒ Boolean

Pass in a string, we tell you if we think SFX controls this URL– that is, if the SFX KB handles resources at this URL, or not. It's really just a guess for a bunch of reasons, but best we can do. We just check hostname, which could create false positives. Checking entire URL won't work. Lots of things in SFX could create false negatives.

Returns:

  • (Boolean)

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/sfx_url.rb', line 13

def self.sfx_controls_url?(url)
  ActiveRecord::Base.connection_pool.with_connection do
    # Does it match any of our supplementary configged strings or regexps?
    UmlautController.umlaut_config.lookup!("sfx.additional_sfx_controlled_urls", []).each do |test|
      # '===' will match a regexp or equality on a string
      return true if test === url
    end
    
    begin
      uri = URI.parse(url)
    rescue
      # Bad uri in catalog? Fine, we don't know SFX controls it. 
      return false;
    end
    host = uri.host    
    
    # If URI was malformed, just punt and say no.
    return false unless host    
    
    return SfxUrl.where(:url => host).count > 0
  end
end