Class: Garage::HypermediaFilter
- Inherits:
-
Object
- Object
- Garage::HypermediaFilter
- Defined in:
- lib/garage/hypermedia_filter.rb
Constant Summary collapse
- MIME_DICT =
%r[application/vnd\.cookpad\.dictionary\+(json|x-msgpack)]
Instance Attribute Summary collapse
-
#controller ⇒ Object
readonly
Returns the value of attribute controller.
Class Method Summary collapse
Instance Method Summary collapse
- #dictionary_match_data ⇒ Object
- #dictionary_representation ⇒ Object
- #dictionary_request_format ⇒ Object
- #field_selector ⇒ Object
- #fields_param ⇒ Object
- #has_dictionary_mime_type? ⇒ Boolean
-
#initialize(controller) ⇒ HypermediaFilter
constructor
A new instance of HypermediaFilter.
Constructor Details
#initialize(controller) ⇒ HypermediaFilter
Returns a new instance of HypermediaFilter.
16 17 18 |
# File 'lib/garage/hypermedia_filter.rb', line 16 def initialize(controller) @controller = controller end |
Instance Attribute Details
#controller ⇒ Object (readonly)
Returns the value of attribute controller.
14 15 16 |
# File 'lib/garage/hypermedia_filter.rb', line 14 def controller @controller end |
Class Method Details
.before(controller) ⇒ Object
5 6 7 8 9 10 11 12 |
# 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 |
Instance Method Details
#dictionary_match_data ⇒ Object
40 41 42 |
# 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 ⇒ Object
28 29 30 |
# File 'lib/garage/hypermedia_filter.rb', line 28 def dictionary_representation :dictionary end |
#dictionary_request_format ⇒ Object
32 33 34 |
# File 'lib/garage/hypermedia_filter.rb', line 32 def dictionary_request_format dictionary_match_data[1].sub(/^x-/, "").to_sym end |
#field_selector ⇒ Object
20 21 22 |
# File 'lib/garage/hypermedia_filter.rb', line 20 def field_selector Garage::NestedFieldQuery::Selector.build(fields_param) end |
#fields_param ⇒ Object
24 25 26 |
# File 'lib/garage/hypermedia_filter.rb', line 24 def fields_param controller.params[:fields] end |
#has_dictionary_mime_type? ⇒ Boolean
36 37 38 |
# File 'lib/garage/hypermedia_filter.rb', line 36 def has_dictionary_mime_type? dictionary_match_data end |