title: Ruby: Circular Dependancy autoloading
body: <p>I am trying to patch a <a href="http://projects.theforeman.org/issues/14160" rel="nofollow">foreman bug</a> where they don't disable network boot after build and turn it back on when you want to rebuild a host. It looks like I just need to add some code to the "built" method in:</p>
  
  <p>./app/controllers/unattended_controller.rb</p>
  
  <pre><code>def built
      logger.info "#{controller_name}: #{@host.name} is Built!"
      update_ip if Setting[:update_ip_from_built_request]
      head(@host.built ? :created : :conflict)
   end
  </code></pre>
  
  <p>and the "setBuild" method in:</p>
  
  <p>./app/models/host/managed.rb</p>
  
  <pre><code>def setBuild
    self.build = true
    self.save
    errors.empty?
  end
  </code></pre>
  
  <p>Borrowing from line 79 of <a href="https://github.com/theforeman/foreman_bootdisk/blob/master/lib/foreman_bootdisk/engine.rb" rel="nofollow">foreman_bootdisk.rb</a> and <a href="https://github.com/fog/fog-vsphere/blob/master/lib/fog/vsphere/requests/compute/modify_vm_cdrom.rb" rel="nofollow">modify_vm_cdrom.rb</a> for inspiration,
   I have come up with something along the lines of: </p>
  
  <pre><code>def setBuild
    load '/usr/share/foreman/app/models/compute_resources/foreman/model/vmware.rb'
    if ComputeResources::Foreman::Model::Vmware.available?
        vm_reconfig_hardware('instance_uuid' =&gt; params[:token], 'hardware_spec' =&gt; {'bootOptions'=&gt;['network', 'disk']})
    end
    self.build = true
    self.save
    errors.empty?
  end
  </code></pre>
  
  <p>The problem is that I get the error,</p>
  
  <blockquote>
    <p>Oops, we're sorry but something went wrong Circular dependency detected while autoloading constant ComputeResources::Foreman::Model::Vmware</p>
  </blockquote>
  
  <p>I have done some reading on this and hear that the problem is probably with rail's autoload, but I have tried fixing this with load and require (I was trying to avoid the autoload function which I hear is <a href="https://bugs.ruby-lang.org/issues/5653" rel="nofollow">deprecated</a>), but despite having tried both, I continue to get this error and I am unsure why. What am i doing differently than  the coders of foreman_bootdisk.rb to get this error that they aren't? Whey doesn't <a href="https://github.com/iNecas/foreman-build/blob/master/lib/foreman/model/vmware.rb" rel="nofollow">vmware.rb</a> seem to want to load?</p>