Class: Sinatra::Soxer::UrlReader

Inherits:
Object
  • Object
show all
Defined in:
lib/soxer/main.rb

Overview

The UrlReader class

UrlReader simply checks if the URL recieved can be matched to a file. Currelntly it either matches a file path (ending with .yaml) from origin (the default is “content” directory within application root) or a directory path with index.yaml

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, settings) ⇒ UrlReader

Returns a new instance of UrlReader.



92
93
94
# File 'lib/soxer/main.rb', line 92

def initialize url, settings
  @url, @s = url, settings
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



90
91
92
# File 'lib/soxer/main.rb', line 90

def url
  @url
end

Instance Method Details

#get_contentObject

Creates a FileReader instance, maps the url to either yaml file or index.yaml within a directory represented by url.



98
99
100
101
102
103
104
105
# File 'lib/soxer/main.rb', line 98

def get_content
  fn = case true
       when File.exist?( f = File.join( @s.origin, @url+'.yaml' ) ) then f
       when File.exist?( f = File.join( @s.origin, @url+'/index.yaml' ) ) then f
       else throw :halt, [404, "Document not found"]
       end
  FileReader.new(fn, @s).get_content
end