<commit_before>class ManagerRefresh::InventoryCollectionDefault::CloudManager < ManagerRefresh::InventoryCollectionDefault
  class << self
    def vms(extra_attributes = {})
      attributes = {
        :model_class          => ::ManageIQ::Providers::CloudManager::Vm,
        :association          => :vms,
        :delete_method        => :disconnect_inv,
        :attributes_blacklist => [:genealogy_parent]
      }

      attributes.merge!(extra_attributes)
    end

    def miq_templates(extra_attributes = {})
      attributes = {
        :model_class   => ::ManageIQ::Providers::CloudManager::Template,
        :association   => :miq_templates,
        :delete_method => :disconnect_inv,
      }

      attributes.merge!(extra_attributes)
    end

    def availability_zones(extra_attributes = {})
      attributes = {
        :model_class => ::AvailabilityZone,
        :association => :availability_zones,
      }

      attributes.merge!(extra_attributes)
    end

    def flavors(extra_attributes = {})
      attributes = {
        :model_class => ::Flavor,
        :association => :flavors,
      }

      attributes.merge!(extra_attributes)
    end

    def key_pairs(extra_attributes = {})
      attributes = {
        :model_class => ::ManageIQ::Providers::CloudManager::AuthKeyPair,
        :manager_ref => [:name],
        :association => :key_pairs
      }

      attributes.merge!(extra_attributes)
    end

    def hardwares(extra_attributes = {})
      attributes = {
        :model_class => ::Hardware,
        :manager_ref => [:vm_or_template],
        :association => :hardwares
      }

      case extra_attributes[:strategy]
      when :local_db_cache_all
        attributes[:custom_manager_uuid] = lambda do |hardware|
          [hardware.vm_or_template.ems_ref]
        end
      when :find_missing_in_local_db
        attributes[:custom_db_finder] = lambda do |inventory_collection, hash_uuid_by_ref|
          inventory_collection.parent.send(inventory_collection.association).references(:vm_or_template).where(
            :vms => {:ems_ref => hash_uuid_by_ref[:vm_or_template]}
          ).first
        end
      end

      attributes.merge!(extra_attributes)
    end

    def disks(extra_attributes = {})
      attributes = {
        :model_class => ::Disk,
        :manager_ref => [:hardware, :device_name],
        :association => :disks
      }

      if extra_attributes[:strategy] == :local_db_cache_all
        attributes[:custom_manager_uuid] = lambda do |disk|
          [disk.hardware.vm_or_template.ems_ref, disk.device_name]
        end
      end

      attributes.merge!(extra_attributes)<commit_msg>Custom db finder using a selection<commit_after>class ManagerRefresh::InventoryCollectionDefault::CloudManager < ManagerRefresh::InventoryCollectionDefault
  class << self
    def vms(extra_attributes = {})
      attributes = {
        :model_class          => ::ManageIQ::Providers::CloudManager::Vm,
        :association          => :vms,
        :delete_method        => :disconnect_inv,
        :attributes_blacklist => [:genealogy_parent]
      }

      attributes.merge!(extra_attributes)
    end

    def miq_templates(extra_attributes = {})
      attributes = {
        :model_class   => ::ManageIQ::Providers::CloudManager::Template,
        :association   => :miq_templates,
        :delete_method => :disconnect_inv,
      }

      attributes.merge!(extra_attributes)
    end

    def availability_zones(extra_attributes = {})
      attributes = {
        :model_class => ::AvailabilityZone,
        :association => :availability_zones,
      }

      attributes.merge!(extra_attributes)
    end

    def flavors(extra_attributes = {})
      attributes = {
        :model_class => ::Flavor,
        :association => :flavors,
      }

      attributes.merge!(extra_attributes)
    end

    def key_pairs(extra_attributes = {})
      attributes = {
        :model_class => ::ManageIQ::Providers::CloudManager::AuthKeyPair,
        :manager_ref => [:name],
        :association => :key_pairs
      }

      attributes.merge!(extra_attributes)
    end

    def hardwares(extra_attributes = {})
      attributes = {
        :model_class => ::Hardware,
        :manager_ref => [:vm_or_template],
        :association => :hardwares
      }

      attributes[:custom_manager_uuid] = lambda do |hardware|
        [hardware.vm_or_template.ems_ref]
      end

      attributes[:custom_db_finder] = lambda do |inventory_collection, selection, _projection |
        relation = inventory_collection.parent.send(inventory_collection.association).
          includes(:vm_or_template).
          references(:vm_or_template)
        relation = relation.where(:vms => {:ems_ref => selection[:vm_or_template]}) unless selection.blank?
        relation
      end

      attributes.merge!(extra_attributes)
    end

    def disks(extra_attributes = {})
      attributes = {
        :model_class => ::Disk,
        :manager_ref => [:hardware, :device_name],
        :association => :disks
      }

      if extra_attributes[:strategy] == :local_db_cache_all
        attributes[:custom_manager_uuid] = lambda do |disk|
          [disk.hardware.vm_or_template.ems_ref, disk.device_name]
        end
      end

      attributes.merge!(extra_attributes)
{'fraction_non_alphanumeric': 0.1111111111111111, 'fraction_numerical': 0.0, 'mean_word_length': 2.7185080928923293, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5833282', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1506, 'n_words': 234}