Per @rafaelfranca I should post this here ( 
was https://github.com/rails/rails/issues/12411 )

require_dependency should allow Pathname, not just String

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

underlying Rails 
code<https://github.com/rails/rails/blob/master/activesupport/lib/active_support/dependencies.rb#L201>

      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)

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to