class CatTree::Observer::ArBase

Attributes

callers[R]
count[R]

Public Class Methods

new(object) click to toggle source
# File lib/cat_tree/observer/target_set/ar_base.rb, line 6
def initialize(object)
  return unless object_valid?(object)
  @valid = true

  @model = object.class.name
  @model_id = object.id
  @count = 1
  @callers = []

  record_backtrace if CatTree::Config.backtrace
end

Public Instance Methods

==(other) click to toggle source
# File lib/cat_tree/observer/target_set/ar_base.rb, line 24
def ==(other)
  key == other.key
end
key() click to toggle source
# File lib/cat_tree/observer/target_set/ar_base.rb, line 28
def key
  [@model, @model_id]
end
merge(other) click to toggle source
# File lib/cat_tree/observer/target_set/ar_base.rb, line 18
def merge(other)
  @count += other.count
  @callers.concat(other.callers)
  self
end
title() click to toggle source
# File lib/cat_tree/observer/target_set/ar_base.rb, line 36
def title
  "#{@model}(id:#{@model_id})"
end
valid?() click to toggle source
# File lib/cat_tree/observer/target_set/ar_base.rb, line 32
def valid?
  !!@valid
end

Private Instance Methods

backtrace_in_rails() click to toggle source
# File lib/cat_tree/observer/target_set/ar_base.rb, line 50
def backtrace_in_rails
  root_path = Rails.root.to_s
  root_path += "/" unless root_path.last == "/"
  caller.select{|c| c =~ %r!#{root_path}(app|lib)/!}
end
object_valid?(object) click to toggle source
# File lib/cat_tree/observer/target_set/ar_base.rb, line 42
def object_valid?(object)
  object.is_a?(ActiveRecord::Base) && !object.new_record?
end
record_backtrace() click to toggle source
# File lib/cat_tree/observer/target_set/ar_base.rb, line 46
def record_backtrace
  @callers << (defined?(Rails) ? backtrace_in_rails : caller)
end