Sha256: 7a0f791c96a81513c541f6fe587b4ba9063d34da330a0530eaebfc6c00ba8f4a
Contents?: true
Size: 1002 Bytes
Versions: 1
Compression:
Stored size: 1002 Bytes
Contents
module ActionController module Exportation extend ActiveSupport::Concern included do class_attribute :_exportation_scope self._exportation_scope = :current_user end module ClassMethods def exportation_scope(scope) self._exportation_scope = scope end end ActiveModel::Exporter::TYPES.each do |type| [:_render_option_, :_render_with_renderer_json].each do |prefix| define_method "#{prefix}#{type}" do |resource, options| exporter = build_exporter(resource, options) exporter ? super(exporter, options) : super end end end private def exportation_scope scope = self.class._exportation_scope send(scope) if scope && respond_to?(scope, true) end def build_exporter(resource, options) if exporter = ActiveModel::Exporter.exporter_for(resource) options[:scope] ||= exportation_scope exporter.new(resource, options) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
active_model_exporters-0.3.0 | lib/action_controller/exportation.rb |