Class: Apish::FormatResolver
- Inherits:
-
Object
- Object
- Apish::FormatResolver
- Defined in:
- lib/apish/format_resolver.rb
Instance Attribute Summary collapse
-
#accept ⇒ Object
readonly
Returns the value of attribute accept.
-
#current_format ⇒ Object
readonly
Returns the value of attribute current_format.
Class Method Summary collapse
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(accept, current_format = nil) ⇒ FormatResolver
constructor
A new instance of FormatResolver.
Constructor Details
#initialize(accept, current_format = nil) ⇒ FormatResolver
Returns a new instance of FormatResolver.
10 11 12 13 |
# File 'lib/apish/format_resolver.rb', line 10 def initialize( accept, current_format=nil ) @accept = accept || '' @current_format = current_format end |
Instance Attribute Details
#accept ⇒ Object (readonly)
Returns the value of attribute accept.
7 8 9 |
# File 'lib/apish/format_resolver.rb', line 7 def accept @accept end |
#current_format ⇒ Object (readonly)
Returns the value of attribute current_format.
7 8 9 |
# File 'lib/apish/format_resolver.rb', line 7 def current_format @current_format end |
Class Method Details
.format_regex ⇒ Object
31 32 33 |
# File 'lib/apish/format_resolver.rb', line 31 def self.format_regex /application\/vnd.#{Apish.configuration.mime_types_base}-v\d+\+(\w*)/ end |
Instance Method Details
#format ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/apish/format_resolver.rb', line 15 def format if current_format == Mime::ALL || current_format.to_s.include?( "application/vnd.#{Apish.configuration.mime_types_base}-v" ) matches = accept.match( self.class.format_regex ) mime_type_str = matches.nil? ? current_format : matches[1] mime_type = Mime[mime_type_str] return mime_type.symbol.to_s unless mime_type.blank? elsif current_format.nil? matches = accept.match( self.class.format_regex ) mime_type_str = matches.nil? ? current_format : matches[1] mime_type = Mime[mime_type_str] return mime_type.symbol.to_s unless mime_type.blank? end current_format.try( :symbol ).try :to_s end |