Sha256: 3fe36d0cf8cd918c874020a656608b4d3ad557d9f5b6c976a52fc0e9fa52f752

Contents?: true

Size: 1.57 KB

Versions: 149

Compression:

Stored size: 1.57 KB

Contents

module ActionView #:nodoc:
  # = Action View PathSet
  class PathSet #:nodoc:
    include Enumerable

    attr_reader :paths

    def initialize(paths = [])
      @paths = typecast paths
    end

    def initialize_copy(other)
      @paths = other.paths.dup
      self
    end

    def [](i)
      paths[i]
    end

    def to_ary
      paths.dup
    end

    def include?(item)
      paths.include? item
    end

    def pop
      paths.pop
    end

    def size
      paths.size
    end

    def each(&block)
      paths.each(&block)
    end

    def compact
      PathSet.new paths.compact
    end

    def +(array)
      PathSet.new(paths + array)
    end

    %w(<< concat push insert unshift).each do |method|
      class_eval <<-METHOD, __FILE__, __LINE__ + 1
        def #{method}(*args)
          paths.#{method}(*typecast(args))
        end
      METHOD
    end

    def find(*args)
      find_all(*args).first || raise(MissingTemplate.new(self, *args))
    end

    def find_all(path, prefixes = [], *args)
      prefixes = [prefixes] if String === prefixes
      prefixes.each do |prefix|
        paths.each do |resolver|
          templates = resolver.find_all(path, prefix, *args)
          return templates unless templates.empty?
        end
      end
      []
    end

    def exists?(path, prefixes, *args)
      find_all(path, prefixes, *args).any?
    end

    private

    def typecast(paths)
      paths.map do |path|
        case path
        when Pathname, String
          OptimizedFileSystemResolver.new path.to_s
        else
          path
        end
      end
    end
  end
end

Version data entries

149 entries across 110 versions & 18 rubygems

Version Path
actionpack-3.2.22.1 lib/action_view/path_set.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_view/path_set.rb
actionpack-3.2.22 lib/action_view/path_set.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/actionpack-3.2.12/lib/action_view/path_set.rb
actionpack-3.2.21 lib/action_view/path_set.rb
actionpack-3.2.20 lib/action_view/path_set.rb
actionpack-3.2.19 lib/action_view/path_set.rb
actionpack-3.2.18 lib/action_view/path_set.rb
actionpack-3.2.17 lib/action_view/path_set.rb
actionpack-3.2.16 lib/action_view/path_set.rb
actionpack-3.2.15 lib/action_view/path_set.rb
actionpack-3.2.15.rc3 lib/action_view/path_set.rb
actionpack-3.2.15.rc2 lib/action_view/path_set.rb
actionpack-3.2.15.rc1 lib/action_view/path_set.rb
actionpack-3.2.14 lib/action_view/path_set.rb
actionpack-3.2.14.rc2 lib/action_view/path_set.rb
actionpack-3.2.14.rc1 lib/action_view/path_set.rb
swipe-rails-0.0.5 vendor/bundle/gems/actionpack-3.2.13/lib/action_view/path_set.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_view/path_set.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_view/path_set.rb