Example use case
require_dependency Rails.root.join('lib','null_logger') # raises exception # ArgumentError: the file name must be a String -- you passed #<Pathname:/path/to/app/lib/null_logger>
I would argue require_dependency should also accept a pathname, just like require does.
I think the workaround proves this point: require_dependency Rails.root.join('lib','null_logger').to_s
def require_dependency(file_name, message = "No such file to load -- %s") unless file_name.is_a?(String) raise ArgumentError, "the file name must be a String -- you passed #{file_name.inspect}" end Dependencies.depend_on(file_name, message) end
I'm happy to make a PR for this if Rails core approves.
The PR would be something like
def require_dependency(file_name, message = "No such file to load -- %s") file_name = file_name.to_path if file_name.respond_to?(:to_path) unless file_name.is_a?(String)
On Mon, Sep 30, 2013 at 08:16:27PM +0200, Xavier Noria wrote:Do we even need to check? Won't it eventually get required, and Ruby
> Agreed. I believe that if the argument is not a string we should check if
> it responds to #to_path.
will blow up?
On Mon, Sep 30, 2013 at 08:16:27PM +0200, Xavier Noria wrote:Do we even need to check? Won't it eventually get required, and Ruby
> Agreed. I believe that if the argument is not a string we should check if
> it responds to #to_path.
will blow up?
def require_or_load(file_name, const_path = nil)
file_name = file_name.to_path if file_name.respond_to?(:to_path)
def require pathpath = path.to_path if path.respond_to?(:to_path)RUBYGEMS_ACTIVATION_MONITOR.enter
Well, I see there are relatively soon calls to File.expand_path (that checks #to_path). Maybe technically a few #to_s calls here and there could make it succeed, but relying on the fact that the implementation passes through expand_path at some point seems obscure to me.
--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/ESAONvNYZL4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-co...@googlegroups.com.
So, is current thought, thenActiveSupport::Dependenciesdef require_or_load(file_name, const_path = nil)file_name = file_name.to_path if file_name.respond_to?(:to_path)
Kernel extension #not sure if this is necessary. vanilla ruby appears to be okay with requiring a pathname
| def test_tracking_loaded_files | ||
| require_dependency 'dependencies/service_one' | ||
| - require_dependency 'dependencies/service_two' | ||
| + require_dependency Pathname('dependencies/service_two') |