1

I am working in irb and trying to clean up some code I downloaded.

I am running this:

require '/Users/alexgenadinik/projects/cmply/cmply-app/lib/app/social/linkedin/linkedin.rb'

and it works fine. That file contains this:

require File.join(File.expand_path("../",__FILE__),"init")
require 'oauth'

module LinkedIn
  puts "helllllooooo"

  class << self

    #logger.debug "....teeest"
    attr_accessor :token, :secret, :default_profile_fields

    # config/initializers/linkedin.rb (for instance)
    #
    # LinkedIn.configure do |config|
    #   config.token = 'consumer_token'
    #   config.secret = 'consumer_secret'
    #   config.default_profile_fields = ['education', 'positions']
    # end
    #
    # elsewhere
    #
    # client = LinkedIn::Client.new
    def configure
      yield self
      true
    end
  end

  #root_path = File.expand_path("../../../../../",__FILE__)

  autoload :Api,     File.join(LINKED_IN_LOAD_PATH,"linked_in/api.rb") #"linked_in/api"
  autoload :Client,  File.join(LINKED_IN_LOAD_PATH,"linked_in/client.rb") #"linked_in/client"
  autoload :Mash,    File.join(LINKED_IN_LOAD_PATH,"linked_in/mash.rb") #"linked_in/mash"
  autoload :Errors,  File.join(LINKED_IN_LOAD_PATH,"linked_in/errors.rb") #"linked_in/errors"
  autoload :Helpers, File.join(LINKED_IN_LOAD_PATH,"linked_in/helpers.rb") #"linked_in/helpers"
  autoload :Search,  File.join(LINKED_IN_LOAD_PATH,"linked_in/search.rb") #"linked_in/search"

end

But when I try to run a command like this:

client = LinkedIn::Client.new('key', 'key')

I get this error:

LoadError: no such file to load -- linked_in/helpers/authorization
    from /Users/alexgenadinik/projects/cmply/cmply-app/lib/app/social/linkedin/linked_in/helpers/authorization.rb:4
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
    from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require'
    from /Users/alexgenadinik/projects/cmply/cmply-app/lib/app/social/linkedin/linked_in/client.rb:2
    from (irb):2

so it points to line 2 of client.rb which starts like this:

require 'cgi'
require File.join(LINKED_IN_LOAD_PATH, "linked_in","helpers/authorization")

and line 4 of authorization.rb which starts like this:

module LinkedIn
  module Helpers

    module Authorization

By the way, should I read the error message from the top, or should I start reading from the bottom to see where the error appeared first?

Help much appreciated. I am not sure why it is giving the error.

1
  • try changing all the autoload to require just to see if it's a dependency not being picked up, not sure if autoload can work if there is a require client.rb, kind of a guess. Commented May 14, 2012 at 19:19

1 Answer 1

1

The dir your file is in is "linkedin", but the dirs you are requiring from are "linked_in", you should change the name of the actual dir to linked_in, since that aligns with naming conventions.

That aside, I'm pretty sure Rails adds all directories under app into the load path. So you should be able to just say require 'linked_in/linked_in' (assuming you change both the dir and file names) and then you can probably do the same thing with all the autoloads, and get rid of the File.expand_path ... stuff.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks ...little confused..which is the file in which I should add the require 'linked_in/linked_in' ?
I haven't tried this, but I'm pretty sure where you use autoload, you can replace the expanded paths like autoload :Api, File.join(LINKED_IN_LOAD_PATH,"linked_in/api.rb") with autoload :Api, "linked_in/api.rb"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.