Let's say I have I have the following file in my lib directory of my rails application:
#lib/proxy.rb
module SomeService
class ServiceProxy
def do_something
end
end
end
If I want to use ServiceProxy in a model, I can use it like so:
#app/models/product.rb
require 'proxy'
class Product < ActiveRecord::Base
def do_something
proxy = SomeService::ServiceProxy.new
proxy.do_something
end
end
This works, but I noticed if I want to use ServiceProxy in another model, I do not need "require 'proxy'" in the second model file. It seems having "require 'proxy'" once in any model will add it to the lookup path.
Can someone explain this behavior and the best practice surrounding it in a rails app?
Thanks!
UPDATE: Based on floyd's answer below, if my ServiceProxy file was saved as so,
#lib/some_service/service_proxy.rb
then I would not have to explicitly require the file.