Class: Sass::Importers::HTTP

Inherits:
Base
  • Object
show all
Defined in:
lib/sassmagic/remote.rb

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ HTTP

Returns a new instance of HTTP.



19
20
21
22
23
24
25
# File 'lib/sassmagic/remote.rb', line 19

def initialize root
  @root = URI.parse root

  unless scheme_allowed? @root
    raise ArgumentError, "Absolute HTTP URIs only"
  end
end

Instance Method Details

#find(uri, options) ⇒ Object



30
31
32
# File 'lib/sassmagic/remote.rb', line 30

def find uri, options
  _find @root + uri, options
end

#find_relative(uri, base, options) ⇒ Object



27
28
29
# File 'lib/sassmagic/remote.rb', line 27

def find_relative uri, base, options
  _find @root + base + uri, options
end

#key(uri, options) ⇒ Object



51
52
53
# File 'lib/sassmagic/remote.rb', line 51

def key(uri, options)
  [self.class.name, uri]
end

#mtime(uri, options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sassmagic/remote.rb', line 34

def mtime uri, options
  uri = URI.parse uri
  return unless scheme_allowed? uri
  Net::HTTP.start(uri.host, uri.port) do |http|
    response = http.head uri.request_uri

    if response.is_a?(Net::HTTPOK) && response['Last-Modified']
      Time.parse response['Last-Modified']
    elsif response.is_a? Net::HTTPOK
      # we must assume that it just changed
      Time.now
    else
      nil
    end
  end
end

#to_sObject



55
56
57
# File 'lib/sassmagic/remote.rb', line 55

def to_s
  @root.to_s
end