aboutsummaryrefslogblamecommitdiffstats
path: root/actionpack/lib/action_view/path_set.rb
blob: dc26d75ff3f3f11ce9f9e95bd8170bcfcf9825f7 (plain) (tree)
1
2
3
4
5
6
7
8
9
                          
                         
                                




                                                                 
           
            

       

                                                                                     




                                                                                            
                        
                                            




                                                

                          
       
 
           
 

                                  
                                                
                                      
                                              
         
       

     
module ActionView #:nodoc:
  # = Action View PathSet
  class PathSet < Array #:nodoc:
    %w(initialize << concat insert push unshift).each do |method|
      class_eval <<-METHOD, __FILE__, __LINE__ + 1
        def #{method}(*args)
          super
          typecast!
        end
      METHOD
    end

    def find(path, prefix = nil, partial = false, details = {}, keys = [], key = nil)
      template = find_all(path, prefix, partial, details, keys, key).first
      raise MissingTemplate.new(self, "#{prefix}/#{path}", details, partial) unless template
      template
    end

    def find_all(*args)
      each do |resolver|
        templates = resolver.find_all(*args)
        return templates unless templates.empty?
      end
      []
    end

    def exists?(*args)
      find_all(*args).any?
    end

  protected

    def typecast!
      each_with_index do |path, i|
        path = path.to_s if path.is_a?(Pathname)
        next unless path.is_a?(String)
        self[i] = FileSystemResolver.new(path)
      end
    end
  end
end