Sha256: 75a37ba0e4a2a7c49511b6f0a7e44be5e49713cb10e876e36748b684ce0f6a78

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require 'rails'
require 'paper_trail'

begin
  require 'will_paginate'
rescue LoadError
  begin
    require 'kaminari'
  rescue LoadError
    raise LoadError.new('will_paginate or kaminari must be in Gemfile or load_path')
  end
end

class PaperTrailManager < Rails::Engine
  initializer "paper_trail_manager.pagination" do
    if defined?(WillPaginate)
      ::ActionView::Base.send(:alias_method, :paginate, :will_paginate)
    end
  end

  @@whodunnit_name_method = :name
  cattr_accessor :whodunnit_class, :whodunnit_name_method, :route_helpers, :layout, :base_controller

  self.base_controller = "ApplicationController"

  (Pathname(__FILE__).dirname + '..').tap do |base|
    paths["app/controller"] = base + 'app/controllers'
    paths["app/view"] = base + 'app/views'
  end

  def self._allow_set(action, block)
    send(:class_variable_set, "@@allow_#{action}_block", block)
  end

  def self._allow_check(action, *args)
    begin
      block = send(:class_variable_get, "@@allow_#{action}_block")
    rescue NameError => e
      return true
    end

    return block.call(*args)
  end

  def self.allow_index_when(&block)
    _allow_set(:index, block)
  end

  def self.allow_index?(controller)
    _allow_check(:index, controller)
  end

  def self.allow_show_when(&block)
    _allow_set(:show, block)
  end

  def self.allow_show?(controller, version)
    _allow_check(:index, controller, version)
  end

  # Describe when to allow reverts. Call this with a block that accepts
  # arguments for +controller+ and +version+.
  def self.allow_revert_when(&block)
    _allow_set(:revert, block)
  end

  # Allow revert given the +controller+ and +version+? If no
  # ::allow_revert_when was specified, always return +true+.
  def self.allow_revert?(controller, version)
    _allow_check(:revert, controller, version)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
paper_trail_manager-0.5.0 lib/paper_trail_manager.rb