Class: RubyApp::Response
- Inherits:
-
Rack::Response
- Object
- Rack::Response
- RubyApp::Response
- Extended by:
- Mixins::ConfigurationMixin, Mixins::DelegateMixin
- Defined in:
- lib/ruby_app/response.rb
Class Method Summary collapse
Instance Method Summary collapse
- #content_for(element, format, name, value = nil, &block) ⇒ Object
- #get_content(element, format, name) ⇒ Object
- #rendered(element, template) ⇒ Object
- #rendered?(element, template) ⇒ Boolean
- #write_from_cache(element, format) ⇒ Object
Methods included from Mixins::DelegateMixin
Methods included from Mixins::ConfigurationMixin
Class Method Details
.create! ⇒ Object
60 61 62 |
# File 'lib/ruby_app/response.rb', line 60 def self.create! Thread.current[:_response] = RubyApp::Response.new end |
.destroy! ⇒ Object
64 65 66 |
# File 'lib/ruby_app/response.rb', line 64 def self.destroy! Thread.current[:_response] = nil end |
.get ⇒ Object
56 57 58 |
# File 'lib/ruby_app/response.rb', line 56 def self.get return Thread.current[:_response] end |
.get_content_type(format) ⇒ Object
68 69 70 |
# File 'lib/ruby_app/response.rb', line 68 def self.get_content_type(format) return ( mime_type = MIME::Types.type_for(format)[0] ) ? mime_type.content_type : 'text/plain' end |
Instance Method Details
#content_for(element, format, name, value = nil, &block) ⇒ Object
23 24 25 26 |
# File 'lib/ruby_app/response.rb', line 23 def content_for(element, format, name, value = nil, &block) @content[element] ||= {} @content[element][name] = block_given? ? block : String.interpolate { value } end |
#get_content(element, format, name) ⇒ Object
28 29 30 31 |
# File 'lib/ruby_app/response.rb', line 28 def get_content(element, format, name) @content[element] ||= {} return @content[element][name] end |
#rendered(element, template) ⇒ Object
19 20 21 |
# File 'lib/ruby_app/response.rb', line 19 def rendered(element, template) @templates.push(template) if element.is_a?(Class) unless @templates.include?(template) end |
#rendered?(element, template) ⇒ Boolean
15 16 17 |
# File 'lib/ruby_app/response.rb', line 15 def rendered?(element, template) return element.is_a?(Class) && @templates.include?(template) end |
#write_from_cache(element, format) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ruby_app/response.rb', line 33 def write_from_cache(element, format) if RubyApp::Response.configuration.cache.formats.include?(format) cache = element.get_cache(format) if RubyApp::Response.configuration.cache.read? && File.exists?(cache) #RubyApp::Log.debug("#{RubyApp::Log.prefix(self, __method__)} READ #{cache.inspect}") self.write(File.read(cache)) else content = element.render(format) if RubyApp::Response.configuration.cache.write? && !File.exists?(cache) FileUtils.mkdir_p(File.dirname(cache)) #RubyApp::Log.debug("#{RubyApp::Log.prefix(self, __method__)} WRITE #{cache.inspect}") File.open(cache, 'w') do |file| file.write(content) file.flush end end self.write(content) end else self.write(element.render(format)) end end |