123456789_123456789_123456789_123456789_123456789_

Class: Sinatra::Request::MimeTypeEntry

Relationships & Source Files
Inherits: Object
Defined in: lib/sinatra/base.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(entry) ⇒ MimeTypeEntry

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 137

def initialize(entry)
  params = entry.scan(HEADER_PARAM).map! do |s|
    key, value = s.strip.split('=', 2)
    value = value[1..-2].gsub(/\\(.)/, '\1') if value.start_with?('"')
    [key, value]
  end

  @type   = entry[/[^;]+/].delete(' ')
  @params = params.to_h
end

Instance Attribute Details

#params (readonly)

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 135

attr_reader :params

Instance Method Details

#accepts?(entry) ⇒ Boolean

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 148

def accepts?(entry)
  File.fnmatch(entry, self) && matches_params?(entry.params)
end

#matches_params?(params) ⇒ Boolean

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 156

def matches_params?(params)
  return true if @params.empty?

  params.all? { |k, v| !@params.key?(k) || @params[k] == v }
end

#to_str

[ GitHub ]

  
# File 'lib/sinatra/base.rb', line 152

def to_str
  @type
end