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, #initialize, #method, #option_defaults, #set

Constructor Details

This class inherits a constructor from Invoicing::ClassInfo::Base

Instance Method Details

#fetch_predecessorsObject



375
376
377
378
379
380
381
382
383
384
385
# File 'lib/invoicing/time_dependent.rb', line 375

def fetch_predecessors
  _predecessors = {}
  for record in model_class.all
    id = get(record, :replaced_by_id)
    unless id.nil?
      _predecessors[id] ||= []
      _predecessors[id] << record
    end
  end
  _predecessors
end

#predecessors(record) ⇒ Object

:nodoc:



368
369
370
371
372
373
# File 'lib/invoicing/time_dependent.rb', line 368

def predecessors(record)
  # @predecessors is a hash of an ID pointing to the list of all objects which have that ID
  # as replaced_by_id value
  @predecessors ||= fetch_predecessors
  @predecessors[get(record, :id)] || []
end