Class: CatTree::Observer::ArBase

Inherits:
Object
  • Object
show all
Defined in:
lib/cat_tree/observer/target_set/ar_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ ArBase

Returns a new instance of ArBase.



6
7
8
9
10
11
12
13
14
15
16
# 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

Instance Attribute Details

#callersObject (readonly)

Returns the value of attribute callers.



4
5
6
# File 'lib/cat_tree/observer/target_set/ar_base.rb', line 4

def callers
  @callers
end

#countObject (readonly)

Returns the value of attribute count.



4
5
6
# File 'lib/cat_tree/observer/target_set/ar_base.rb', line 4

def count
  @count
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
# File 'lib/cat_tree/observer/target_set/ar_base.rb', line 24

def ==(other)
  key == other.key
end

#keyObject



28
29
30
# File 'lib/cat_tree/observer/target_set/ar_base.rb', line 28

def key
  [@model, @model_id]
end

#merge(other) ⇒ Object



18
19
20
21
22
# File 'lib/cat_tree/observer/target_set/ar_base.rb', line 18

def merge(other)
  @count += other.count
  @callers.concat(other.callers)
  self
end

#titleObject



36
37
38
# File 'lib/cat_tree/observer/target_set/ar_base.rb', line 36

def title
  "#{@model}(id:#{@model_id})"
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cat_tree/observer/target_set/ar_base.rb', line 32

def valid?
  !!@valid
end