mwunsch / weary

A framework and DSL for building RESTful web service clients
MIT License
482 stars 23 forks source link

prefer `require` to `autoload` #39

Open mwunsch opened 11 years ago

mwunsch commented 11 years ago

I need to

  1. Understand the side-effects of autoload, particularly where thread-safety is concerned.
  2. Test the implications of changing autoload to require, specifically for loading "multi_json", even thought we might not always parse json.
manuelmeurer commented 10 years ago

Just ran into a problem where autoload doesn't seem to work properly:

class MyApp::Thing
  class << self
    def client
      MyApp::Client.new
    end

    def list(options = {})
      response = client.list_things(options).perform
      response.parse['results'].map do |attrs|
        self.new attrs
      end
    end
  end

  def initialize(attrs)
    @attrs = attrs
  end
end
> MyApp::Thing.list
cannot load such file -- multi_json
/Users/manuel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/weary-1.1.3/lib/weary/response.rb:59:in `parse'
/Users/manuel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/promise-0.3.0/lib/promise.rb:89:in `method_missing'
/Users/manuel/code/myapp/lib/my_app/thing.rb:9:in `list'
manuelmeurer commented 10 years ago

Adding require 'multi_json' to the top of MyApp::Thing makes the error disappear.