Class: Stylo::Response
- Inherits:
-
Object
- Object
- Stylo::Response
- Defined in:
- lib/stylo/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #build ⇒ Object
- #each(&block) ⇒ Object
- #extension ⇒ Object
- #has_content? ⇒ Boolean
-
#initialize(path) ⇒ Response
constructor
A new instance of Response.
- #set_body(content, content_type) ⇒ Object
- #set_header(name, value) ⇒ Object
Constructor Details
#initialize(path) ⇒ Response
Returns a new instance of Response.
3 4 5 6 |
# File 'lib/stylo/response.rb', line 3 def initialize(path) @headers = {} @path = path end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
8 9 10 |
# File 'lib/stylo/response.rb', line 8 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
8 9 10 |
# File 'lib/stylo/response.rb', line 8 def headers @headers end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/stylo/response.rb', line 8 def path @path end |
Instance Method Details
#build ⇒ Object
36 37 38 |
# File 'lib/stylo/response.rb', line 36 def build [200, headers, self] end |
#each(&block) ⇒ Object
40 41 42 |
# File 'lib/stylo/response.rb', line 40 def each(&block) block.call(body) end |
#extension ⇒ Object
14 15 16 |
# File 'lib/stylo/response.rb', line 14 def extension File.extname @path end |
#has_content? ⇒ Boolean
10 11 12 |
# File 'lib/stylo/response.rb', line 10 def has_content? !body.nil? end |
#set_body(content, content_type) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/stylo/response.rb', line 18 def set_body(content, content_type) @body = content set_header 'Content-Length', content.length.to_s set_header "Content-Type", case content_type when :css 'text/css' when :javascript 'text/javascript' else raise "Unknown content type #{content_type}" end end |
#set_header(name, value) ⇒ Object
32 33 34 |
# File 'lib/stylo/response.rb', line 32 def set_header(name, value) @headers[name] = value end |