Sha256: ebca58a76d8bd391b5b456d873979d23b061dcff55728ce39111161f6b367b52

Contents?: true

Size: 1.14 KB

Versions: 10

Compression:

Stored size: 1.14 KB

Contents

module AdminIt
  module Controller
    def self.included(base)
      base.class_eval do
        include Pundit if AdminIt::Env.pundit?

        attr_reader :context
        helper_method :context, :resource
        helper AdminIt::Helpers
        helper AdminIt::Engine.routes.url_helpers

        if AdminIt::Env.pundit?
          collections = @resource.collections.map(&:context_name)
          after_action :verify_authorized, except: collections
          after_action :verify_policy_scoped, only: collections
        end
      end
    end

    def resource
      self.class.instance_variable_get(:@resource)
    end

    def redirect_to_default
      redirect_to(resource[resource.default_context].path)
    end

    private

    def load_context(context_class)
      @context = context_class.new(self)
      yield if block_given?
      layout = ['admin_it', params[:layout]].compact.join('_')
      if !performed?
        if layout == 'admin_it' && !request.query_parameters.empty?
          redirect_to request.path
        else
          render template: "admin_it/#{context.name}", layout: layout
        end
      end
      @context.save
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
admin_it-1.0.11 lib/admin_it/controller.rb
admin_it-1.0.10 lib/admin_it/controller.rb
admin_it-1.0.9 lib/admin_it/controller.rb
admin_it-1.0.8 lib/admin_it/controller.rb
admin_it-1.0.7 lib/admin_it/controller.rb
admin_it-1.0.6 lib/admin_it/controller.rb
admin_it-1.0.5 lib/admin_it/controller.rb
admin_it-1.0.4 lib/admin_it/controller.rb
admin_it-1.0.3 lib/admin_it/controller.rb
admin_it-1.0.2 lib/admin_it/controller.rb