Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Refactoring: responder implementation has been moved to a nested module. #92

Merged
merged 1 commit into from

2 participants

@bkon

That makes it friendly to another useful 'responders' gem, allowing to combine responders:

responders ActsAsApi::Responder::Module, Responders::Pagination

The change is backwards-compatible, so you still can use original way of changing responder using

self.responder = ActsAsApi::Responder

No new tests, as no new functionality was added.

@fabrik42 fabrik42 merged commit d4b0ec5 into fabrik42:master

1 check passed

Details default The Travis CI build passed
@fabrik42
Owner

Very cool, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 9, 2014
  1. @bkon

    Refactoring: responder implementation has been moved to a nested module

    bkon authored
    friendly to 'responders' gem.
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 17 deletions.
  1. +11 −17 lib/acts_as_api/responder.rb
View
28 lib/acts_as_api/responder.rb
@@ -20,26 +20,20 @@ module ActsAsApi
# The `:api_template` parameter is required so the responder knows which api template it should render.
class Responder < ActionController::Responder
+ module Module
+ # Overrides the base implementation of display, replacing it with
+ # the render_for_api method whenever api_template is specified.
+ def display(resource, given_options={})
+ api_template = options[:api_template]
- # Should be specified as an option to the `respond_with` call
- attr_reader :api_template
-
- # Grabs the required :api_template parameter, then hands control back to
- # the base ActionController::Responder initializer.
- def initialize(controller, resources, options={})
- @api_template = options.delete(:api_template)
- super(controller, resources, options)
- end
-
- # Overrides the base implementation of display, replacing it with
- # the render_for_api method whenever api_template is specified.
- def display(resource, given_options={})
- if api_template.nil? || !resource.respond_to?(:as_api_response)
- controller.render given_options.merge!(options).merge!(format => resource)
- else
- controller.render_for_api api_template, given_options.merge!(options).merge!(format => resource)
+ if api_template.nil? || !resource.respond_to?(:as_api_response)
+ controller.render given_options.merge!(options).merge!(format => resource)
+ else
+ controller.render_for_api api_template, given_options.merge!(options).merge!(format => resource)
+ end
end
end
+ include Module
end
end
Something went wrong with that request. Please try again.