class WhoAmI::Function::ResolveActiveRecord

Public Instance Methods

call(object_space) click to toggle source
# File lib/who_am_i/function/resolve_active_record.rb, line 6
def call(object_space)
  tree = {}
  object_space.each do |_class_name, extracted_class|
    superclass = extracted_class.resolved_superclass

    tree[superclass] ||= Set.new
    tree[superclass].add(extracted_class)
  end

  activerecord_family =
    gather_family(object_space["::ActiveRecord::Base"], tree)

  activerecord_family.each do |individual|
    individual.activerecord = true
  end

  object_space.values - [object_space[""], object_space["::ActiveRecord::Base"]]
end

Private Instance Methods

gather_family(node, tree) click to toggle source
# File lib/who_am_i/function/resolve_active_record.rb, line 27
def gather_family(node, tree)
  gather_family_helper(node, tree).flatten
end
gather_family_helper(node, tree) click to toggle source
# File lib/who_am_i/function/resolve_active_record.rb, line 31
def gather_family_helper(node, tree)
  if tree[node].nil?
    return node
  end

  [node] + tree[node].map { |child| gather_family_helper(child, tree) }
end