title: uninitialized constant when initializing module
body: <p>Lately have been seeing the following error:</p>
  
  <pre><code>A NameError occurred in new_hire_onboarding#index:
  uninitialized constant BambooHR
  app/models/company.rb:97:in `bamboo_api'
  </code></pre>
  
  <p>Line 97 of company.rb is</p>
  
  <pre><code>@bamboo_api ||= ::BambooHR.new(bamboo_api_key, bamboo_subdomain, logging)
  </code></pre>
  
  <p>I rescued the exception and logged what constants had been loaded and got the following list</p>
  
  <pre><code>hese have been loaded: [:GeneratedFeatureMethods, :Object, :Module, :Class, :BasicObject, :Kernel, :NilClass, :NIL, :Data, :TrueClass, :TRUE, :FalseClass, :FALSE, :Encoding, :Comparable, :Enumerable, :String, :Symbol, :Exception, :SystemExit, :SignalException, :Interrupt, :StandardError, :TypeError, :ArgumentError, :IndexError, :KeyError, :RangeError, :ScriptError, :SyntaxError, :LoadError, :NotImplementedError, :NameError, :NoMethodError, :RuntimeError, :SecurityError, :NoMemoryError, :EncodingError, :SystemCallError, :Errno, :ZeroDivisionError, :FloatDomainError, :Numeric, :Integer, :Fixnum, :Float, :Bignum, :Array, :Hash, :ENV, :Struct, :RegexpError, :Regexp, :MatchData, :Marshal, :Range, :IOError, :EOFError, :IO, :STDIN, :STDOUT, :ARGF, :FileTest, :File, :Dir, :Time, :Random, :Signal, :Process, :Proc, :LocalJumpError, :SystemStackError, :Method, :UnboundMethod, :Binding, :Math, :GC, :ObjectSpace, :Enumerator, :StopIteration, :RubyVM, :Thread, :TOPLEVEL_BINDING, :ThreadGroup, :Mutex, :ThreadError, :Fiber, :FiberError, :Rational, :Complex, :RUBY_VERSION, :RUBY_RELEASE_DATE, :RUBY_PLATFORM, :RUBY_PATCHLEVEL, :RUBY_REVISION, :RUBY_DESCRIPTION, :RUBY_COPYRIGHT, :RUBY_ENGINE, :ARGV, :Gem, :RbConfig, :Config, :CROSS_COMPILING, :BasicSocket, :Socket, :SocketError, :IPSocket, :TCPSocket, :TCPServer, :UDPSocket, :UNIXSocket, :UNIXServer, :Addrinfo, :SERVER_SOCKET_FD, :OWNER_SOCKET_FD, :PhusionPassenger, :ConditionVariable, :Queue, :SizedQueue, :Pathname, :Etc, :Fcntl, :Delegator, :SimpleDelegator, :FileUtils, :Tempfile, :Timeout, :TimeoutError, :StringIO, :IN_PHUSION_PASSENGER, :ERB, :StringScanner, :ScanError, :Date, :Bundler, :Psych, :DateTime, :Syck, :YAML, :Digest, :Set, :SortedSet, :URI, :Zlib, :OptionParser, :TSort, :Forwardable, :SingleForwardable, :Rack, :OpenSSL, :SecureRandom, :ActiveSupport, :Logger, :MonitorMixin, :Monitor, :Rails, :I18n, :Base64, :ActionPack, :ActiveModel, :ActionDispatch, :Arel, :BigDecimal, :BigMath, :ActiveRecord, :Benchmark, :REXML, :AbstractController, :ActionController, :ActionView, :HTML, :MissingSourceFile, :ActionMailer, :ActiveResource, :Sprockets, :Mysql2, :Mongo, :BSON, :CBson, :SocketUtil, :CGI, :Redis, :HashWithIndifferentAccess, :Ancestry, :QualifiedConstUtils, :Singleton, :MultiJson, :JSON, :OpenStruct, :RailsConfig, :DeepMerge, :PrettyPrint, :PP, :ExceptionNotifier, :Mail, :Shellwords, :Net, :MIME, :Treetop, :IntervalSkipList, :Mime, :Erubis, :Jquery, :Haml, :Tilt, :NewRelic, :DependencyDetection, :Resolv, :Rollbar, :Ratchetio, :MultiXml, :HTTParty, :Builder, :XmlFu, :OAuth, :RightSignature, :Faraday, :Addressable, :Podio, :ActivePodio, :Omniauth, :OmniAuth, :OAuth2, :HTTPAuth, :Hashie, :AWS, :SendGrid, :OrmAdapter, :Devise, :Warden, :Journey, :Racc, :ParseError, :Whenever, :Nokogiri, :CompositeReadIO, :UploadIO, :Parts, :Multipartable, :HTTMultiParty, :Delayed, :Sinatra, :DelayedJobWeb, :UnicodeUtils, :Carmen, :Daemons, :Daemonize, :CurrentProcess, :StateMachine, :IS_JRUBY, :IS_CYGWIN, :GraphViz, :AttributeException, :Find, :Dot2Ruby, :BoolException, :DoubleException, :RectException, :SplineTypeException, :ColorException, :PDFKit, :Paperclip, :Cocaine, :ClimateControl, :OpenURI, :StripAttributes, :MetaSearch, :Polyamorous, :Bourbon, :Thor, :SASS_BEGUN_TO_LOAD, :Sass, :Kaminari, :Formtastic, :Responders, :InheritedResources, :Arbre, :ActiveAdmin, :MethodOrProcHelper, :AssignsWithIndifferentAccessHelper, :RailsEmailPreview, :Backops, :RAILS_CACHE, :TZInfo, :Hike, :S3, :BUCKET, :CSV, :Sendgridder, :User, :BCrypt, :UserAssignmentsAssociationExtension, :UserRolesAssociationExtension, :PermissionsSubQuery, :AuthorizationRules, :PermissionsHelper, :ApplicationController, :ApplicationHelper, :Clientonboarding, :DashboardHelper, :DeviseHelper, :EmailHelper, :GeneralHelper, :HrHelper, :PayportalHelper, :QuickbooksHelper, :RolesHelper, :Authorization, :Company, :PermissionsScopable, :CompanyAssignmentsAssociationExtension, :Admin, :Dashboard, :CommentsController, :DeviseController, :AssignmentsController, :CompaniesController, :Hr, :GeneralController, :CurrencyNormalizer, :Rightsignatureable, :Payportal, :Validators, :ProfilesController, :QuickbooksController, :RolesController, :StaticController, :Taskinator, :WelcomeController, :BaseMailer, :UserMailer, :ApiLog, :CacheKey, :ChartOfAccounts, :ContactForm, :Industry, :IndustryAccountName, :STDERR, :BillDotComAPI, :ExpensifyAPI, :BambooHR, :ClassMethods, :ConnectionSpecification, :COLUMNS, :Statements, :TableDefinition, :CommandRecorder, :AttachmentContentTypeValidator, :HelperMethods, :AttachmentPresenceValidator, :AttachmentSizeValidator, :Defining, :Running, :TransactionError, :MacroReflection, :AggregateReflection, :AssociationReflection, :ThroughReflection, :Serializer, :ASSOCIATION_TYPES, :AssociationBuilderExtension, :TooManyRecords, :UNASSIGNABLE_KEYS, :InstanceMethodsOnActivation, :Middleware, :BelongsToPolymorphicAssociation, :HasAndBelongsToManyAssociation, :HasOneAssociation, :HasOneThroughAssociation, :JoinDependency, :JoinHelper, :CollectionProxy, :Association, :CollectionAssociation, :HasManyAssociation, :HasManyThroughAssociation, :ThroughAssociation, :AssociationScope, :AliasTracker, :Preloader, :SingularAssociation, :BelongsToAssociation, :CALLBACKS, :Attribute, :ATTRIBUTE_TYPES_CACHED_BY_DEFAULT, :Read, :Write, :BeforeTypeCast, :Query, :PrimaryKey, :TimeZoneConversion, :Dirty, :Serialization, :DeprecatedUnderscoreRead, :NAME_COMPILABLE_REGEXP, :CALL_COMPILABLE_REGEXP, :AssociatedValidator, :UniquenessValidator, :Callbacks, :AcceptanceValidator, :ConfirmationValidator, :ExclusionValidator, :FormatValidator, :InclusionValidator, :LengthValidator, :NumericalityValidator, :PresenceValidator, :WithValidator, :Callback, :CallbackChain, :PermissionSet, :WhiteList, :BlackList, :Sanitizer, :LoggerSanitizer, :StrictSanitizer, :Error, :Default, :Named]
  </code></pre>
  
  <p>The same method is called in other areas of the codebase and they do not throw this error. The method call that is triggering this error is inside a Rails.cache.fetch block (we use redis-store for the cache)</p>
  
  <p>The following backtrace is given with the error</p>
  
  <pre><code>app/models/company.rb:97:in `bamboo_api'
  app/models/company.rb:65:in `employees'
  app/controllers/hr/new_hire_onboarding_controller.rb:167:in `block (3 levels) in        collect_company_employees'
  activesupport (3.2.12) lib/active_support/cache.rb:297:in `block in fetch'
  activesupport (3.2.12) lib/active_support/cache.rb:520:in `instrument'
  activesupport (3.2.12) lib/active_support/cache.rb:296:in `fetch'
  app/controllers/hr/new_hire_onboarding_controller.rb:166:in `block (2 levels) in collect_company_employees'
  </code></pre>