module Railsful::Interceptors::Include
This interceptors implements the “include” functionality for a given record or a relation.
Public Instance Methods
include_options(options)
click to toggle source
# File lib/railsful/interceptors/include.rb, line 12 def include_options(options) # Check if include key should be merged into options hash. return options unless should_include? # Deep merge include options, so we do not override existing # include options. options.deeper_merge(include: includes) end
includes()
click to toggle source
Fetch the list of all includes.
@return [Array] The list of all include options.
# File lib/railsful/interceptors/include.rb, line 33 def includes params.fetch(:include, nil).to_s.split(',') end
render(options)
click to toggle source
Calls superclass method
# File lib/railsful/interceptors/include.rb, line 8 def render(options) super(include_options(options)) end
should_include?()
click to toggle source
Check if options should contain includes.
@return [Boolean] The answer.
# File lib/railsful/interceptors/include.rb, line 24 def should_include? # Only GET requests should have the "include" functionality, # since it may be a parameter in a create or update action. method == 'GET' && includes.any? end