Class: HaveAPI::OutputFormatter
- Inherits:
- 
      Object
      
        - Object
- HaveAPI::OutputFormatter
 
- Defined in:
- lib/haveapi/output_formatter.rb
Class Attribute Summary collapse
- 
  
    
      .formatters  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    Returns the value of attribute formatters. 
Class Method Summary collapse
Instance Method Summary collapse
- #content_type ⇒ Object
- #error(msg) ⇒ Object
- #format(status, response, message = nil, errors = nil, version: true) ⇒ Object
- #supports?(types) ⇒ Boolean
Class Attribute Details
.formatters ⇒ Object (readonly)
Returns the value of attribute formatters.
| 8 9 10 | # File 'lib/haveapi/output_formatter.rb', line 8 def formatters @formatters end | 
Class Method Details
.register(klass) ⇒ Object
| 10 11 12 13 | # File 'lib/haveapi/output_formatter.rb', line 10 def register(klass) @formatters ||= [] @formatters << klass end | 
Instance Method Details
#content_type ⇒ Object
| 43 44 45 | # File 'lib/haveapi/output_formatter.rb', line 43 def content_type @formatter.content_type end | 
#error(msg) ⇒ Object
| 39 40 41 | # File 'lib/haveapi/output_formatter.rb', line 39 def error(msg) @formatter.format(header(false, nil, msg)) end | 
#format(status, response, message = nil, errors = nil, version: true) ⇒ Object
| 35 36 37 | # File 'lib/haveapi/output_formatter.rb', line 35 def format(status, response, = nil, errors = nil, version: true) @formatter.format(header(status, response, , errors, version)) end | 
#supports?(types) ⇒ Boolean
| 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # File 'lib/haveapi/output_formatter.rb', line 16 def supports?(types) @formatter = nil if types.empty? return @formatter = self.class.formatters.first.new end types.each do |type| self.class.formatters.each do |f| if f.handle?(type) @formatter = f.new break end end end @formatter.nil? ? false : true end |