Files
danbooru/app/logical/application_responder.rb
evazion d0f060d8eb api: refactor api attribute declarations.
Replace the `method_attributes` and `hidden_attributes` methods with
`api_attributes`. `api_attributes` can be used as a class macro:

    # include only the given attributes.
    api_attributes :id, :created_at, :creator_name, ...

    # include all default attributes plus the `creator_name` method.
    api_attributes including: [:creator_name]

or as an instance method:

    def api_attributes
       [:id, :created_at, :creator_name, ...]
    end

By default, all attributes are included except for IP addresses and
tsvector columns.
2019-09-08 23:28:02 -05:00

25 lines
764 B
Ruby

# https://github.com/plataformatec/responders
# https://github.com/plataformatec/responders/blob/master/lib/action_controller/responder.rb
class ApplicationResponder < ActionController::Responder
# this is called by respond_with for non-html, non-js responses.
def to_format
params = request.params
if get?
if params["expires_in"]
controller.expires_in(DurationParser.parse(params["expires_in"]))
elsif request.params["expiry"]
controller.expires_in(params["expiry"].to_i.days)
end
end
if format == :xml
options[:root] ||= resource.table_name.dasherize if resource.respond_to?(:table_name)
end
options[:only] ||= params["only"].scan(/\w+/).map(&:to_sym) if params["only"]
super
end
end