Sha256: 96af8c2bb9a0145d8f1f376015c1302d657080849c51c216ada2920779ed530b

Contents?: true

Size: 917 Bytes

Versions: 5

Compression:

Stored size: 917 Bytes

Contents

module Cans
  class Historian
    attr_accessor :enabled
    attr_accessor :history
    def initialize
      self.history = Set.new
      self.enabled = false
      try_history
      try_bugging_rails
    end

    def delve
      return unless enabled
      merge_history
      reload_history
    end

    def record
      merge_history
    end

    private
    def merge_history
      history.merge ActiveSupport::Dependencies.history
    end

    def reload_history
      history.each { |f| require_or_load f }
    end

    def try_history
      ActiveSupport::Dependencies.history
      self.enabled = true
    rescue
    end

    def try_bugging_rails
      this_historian = self
      ApplicationController.instance_eval do
        after_filter :save_history
        define_method :save_history do
          this_historian.record
        end
      end
      self.enabled = true
    rescue => e
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cans-0.2.3 lib/cans/historian.rb
cans-0.2.2 lib/cans/historian.rb
cans-0.2.1 lib/cans/historian.rb
cans-0.2.0 lib/cans/historian.rb
cans-0.1.2 lib/cans/historian.rb