Class: RhetButler::Stasis::ResourceMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/rhet-butler/stasis/resource-mapping.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_uriObject



11
12
13
# File 'lib/rhet-butler/stasis/resource-mapping.rb', line 11

def default_uri
  Addressable::URI.parse(@default_uri)
end

Instance Method Details

#absolute_uri(uri) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rhet-butler/stasis/resource-mapping.rb', line 15

def absolute_uri(uri)
  uri = default_uri.join(uri)
  if uri == default_uri
    uri = uri.join("index.html")
  end
  return uri
end

#initalize(queue) ⇒ Object



5
6
7
# File 'lib/rhet-butler/stasis/resource-mapping.rb', line 5

def initalize(queue)
  @queue = queue
end

#localized(uri) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rhet-butler/stasis/resource-mapping.rb', line 27

def localized(uri)
  return "/index.html" if uri == "/"

  uri = relative_uri(uri)

  if uri.relative?
    return uri.to_s
  end

  query_values = uri.query_values(Array)
  [
    [uri.host, uri.port, uri.user, uri.scheme == 'http' ? nil : uri.scheme].compact.join("-"),
    uri.path,
    (query_values ? query_values.map{|pair| pair.join("=")}.join(",") : nil)
  ].compact.map do |part|
    part.sub(%r{\A/},'').sub(%r{/\Z},'')
  end.join("/")
end

#relative_uri(uri) ⇒ Object



23
24
25
# File 'lib/rhet-butler/stasis/resource-mapping.rb', line 23

def relative_uri(uri)
  default_uri.route_to(absolute_uri(uri))
end

#storage_for(uri) ⇒ Object



46
47
48
# File 'lib/rhet-butler/stasis/resource-mapping.rb', line 46

def storage_for(uri)
  localized(uri).sub(%r{^/},'')
end


50
51
52
# File 'lib/rhet-butler/stasis/resource-mapping.rb', line 50

def target_link_for(uri)
  default_uri.join(storage_for(uri))
end