title: bin stub - missing dependencies from gem (executing rake tasks within gem)
body: <p>I've written a gem <a href="https://github.com/alienfast/elastic-beanstalk" rel="nofollow noreferrer">elastic-beanstalk</a> which is to be used inside a rails project file structure, as well as in a standalone CI environment where the rails dir and files are not available (without unzipping etc).  i.e. the Bamboo build process running <code>eb:package</code> will yield one primary artifact <code>app.zip</code> where the deploy plan at a later time and perhaps on another agent can take over and execute <code>eb:deploy</code>.  </p>
  
  <h3>The goal</h3>
  
  <p>This is all running fine when inside a rails project structure, so my goal here is to also get this running for the standalone CI environment. </p>
  
  <h3>Given</h3>
  
  <p>an empty dir (CI environment) with just the <code>app.zip</code>, <code>eb.yml</code>, binstubs created, and the gem is available</p>
  
  <h3>When</h3>
  
  <p>I run <code>elastic-beanstalk eb:deploy</code> </p>
  
  <h3>Then</h3>
  
  <p>it should run the equivalent of <code>rake eb:deploy</code> using this gem's dependencies and lib files.</p>
  
  <h2>Update - Bin Stub</h2>
  
  <p>It appears that a bin stub may be what I'm looking for.  Exploring <a href="https://stackoverflow.com/questions/13858495/ruby-accessing-rake-task-from-a-gem-without-rails?rq=1">another SO post</a>, I have tried (to no avail so far) <code>bin/elastic-beanstalk</code>:</p>
  
  <pre><code>gem_dir = File.expand_path('..',File.dirname(__FILE__))
  $LOAD_PATH.unshift gem_dir# Look in gem directory for resources first.
  
  lib = File.expand_path('lib', gem_dir)
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
  
  require 'elastic/beanstalk'
  require 'rake'
  require 'pp'
  
  pwd=Dir.pwd
  Dir.chdir("#{gem_dir}/bin") # We'll load rakefile from the gem's bin dir.
  Rake.application.init
  Rake.application.load_rakefile
  Dir.chdir(pwd) # Revert to original pwd for any path args passed to task.
  
  Rake.application.invoke_task(ARGV[0])
  </code></pre>
  
  <p>So this runs, but is still failing with the same dependency problem I began with <code>undefined method 'safe_load_file' for Psych:Module (NoMethodError)</code>.  While I think a binstub is the way to go:</p>
  
  <h2>How can I resolve the dependency problem with the bin stub?</h2>