class Garage::HypermediaFilter

Constants

MIME_DICT

Attributes

controller[R]

Public Class Methods

before(controller) click to toggle source
# File lib/garage/hypermedia_filter.rb, line 5
def self.before(controller)
  helper = new(controller)
  controller.representation = helper.dictionary_representation if helper.has_dictionary_mime_type?
  controller.request.format = helper.dictionary_request_format if helper.has_dictionary_mime_type?
  controller.field_selector = helper.field_selector
rescue Garage::NestedFieldQuery::InvalidQuery
  raise Garage::BadRequest, "Invalid query in ?fields="
end
new(controller) click to toggle source
# File lib/garage/hypermedia_filter.rb, line 16
def initialize(controller)
  @controller = controller
end

Public Instance Methods

dictionary_match_data() click to toggle source
# File lib/garage/hypermedia_filter.rb, line 40
def dictionary_match_data
  @dictionary_match_data ||= controller.request.format.to_s.match(MIME_DICT)
end
dictionary_representation() click to toggle source
# File lib/garage/hypermedia_filter.rb, line 28
def dictionary_representation
  :dictionary
end
dictionary_request_format() click to toggle source
# File lib/garage/hypermedia_filter.rb, line 32
def dictionary_request_format
  dictionary_match_data[1].sub(/^x-/, "").to_sym
end
field_selector() click to toggle source
# File lib/garage/hypermedia_filter.rb, line 20
def field_selector
  Garage::NestedFieldQuery::Selector.build(fields_param)
end
fields_param() click to toggle source
# File lib/garage/hypermedia_filter.rb, line 24
def fields_param
  controller.params[:fields]
end
has_dictionary_mime_type?() click to toggle source
# File lib/garage/hypermedia_filter.rb, line 36
def has_dictionary_mime_type?
  dictionary_match_data
end