Class: Invoicing::TimeDependent::ClassInfo

Inherits:
ClassInfo::Base show all
Defined in:
lib/invoicing/time_dependent.rb

Overview

Stores state in the ActiveRecord class object

Instance Attribute Summary

Attributes inherited from ClassInfo::Base

#all_args, #all_options, #current_args, #current_options, #model_class, #new_args, #previous_info

Instance Method Summary collapse

Methods inherited from ClassInfo::Base

#get, #method, #option_defaults, #set

Constructor Details

#initialize(model_class, previous_info, args) ⇒ ClassInfo

:nodoc:


369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/invoicing/time_dependent.rb', line 369

def initialize(model_class, previous_info, args)
  super  # @predecessors is a hash of an ID pointing to the list of all objects which have that ID
  # as replaced_by_id value

  @predecessors = {}
  for record in model_class.cached_record_list
    id = get(record, :replaced_by_id)
    unless id.nil?
      @predecessors[id] ||= []
      @predecessors[id] << record
    end
  end
end

Instance Method Details

#predecessors(record) ⇒ Object


383
384
385
# File 'lib/invoicing/time_dependent.rb', line 383

def predecessors(record)
  @predecessors[get(record, :id)] || []
end