Sha256: a74617a7fd58e7414d5657e1b3335a63b80b6119a8399a81a05f5da59895f915

Contents?: true

Size: 976 Bytes

Versions: 6

Compression:

Stored size: 976 Bytes

Contents

module WhoAmI
  module Function
    class ResolveActiveRecord
      include ProcParty

      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

      def gather_family(node, tree)
        gather_family_helper(node, tree).flatten
      end

      def gather_family_helper(node, tree)
        if tree[node].nil?
          return node
        end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
who_am_i-0.0.6 lib/who_am_i/function/resolve_active_record.rb
who_am_i-0.0.5 lib/who_am_i/function/resolve_active_record.rb
who_am_i-0.0.4 lib/who_am_i/function/resolve_active_record.rb
who_am_i-0.0.3 lib/who_am_i/function/resolve_active_record.rb
who_am_i-0.0.2 lib/who_am_i/function/resolve_active_record.rb
who_am_i-0.0.1 lib/who_am_i/function/resolve_active_record.rb