Class: JsSpec::Resources::File

Inherits:
Object
  • Object
show all
Defined in:
lib/js_spec/resources/file.rb

Direct Known Subclasses

Dir

Constant Summary collapse

MIME_TYPES =
{
'.js' => 'text/javascript',
'.css' => 'text/css',
'.png' => 'image/png',
'.jpg' => 'image/jpeg',
'.jpeg' => 'image/jpeg',
'.gif' => 'image/gif',
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(absolute_path, relative_path) ⇒ File

Returns a new instance of File.



15
16
17
18
# File 'lib/js_spec/resources/file.rb', line 15

def initialize(absolute_path, relative_path)
  @absolute_path = absolute_path
  @relative_path = relative_path
end

Instance Attribute Details

#absolute_pathObject (readonly)

Returns the value of attribute absolute_path.



13
14
15
# File 'lib/js_spec/resources/file.rb', line 13

def absolute_path
  @absolute_path
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



13
14
15
# File 'lib/js_spec/resources/file.rb', line 13

def relative_path
  @relative_path
end

Instance Method Details

#==(other) ⇒ Object



26
27
28
29
# File 'lib/js_spec/resources/file.rb', line 26

def ==(other)
  return false unless other.class == self.class
  absolute_path == other.absolute_path && relative_path == other.relative_path
end

#get(request, response) ⇒ Object



20
21
22
23
24
# File 'lib/js_spec/resources/file.rb', line 20

def get(request, response)
  extension = ::File.extname(absolute_path)
  response.headers['Content-Type'] = MIME_TYPES[extension] || 'text/html'
  response.body = ::File.read(absolute_path)
end