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
active_mailer-0.0.4 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.3 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.12 lib/action_view/path_set.rb
graphael-on-rails-0.5.1 vendor/bundle/gems/actionpack-3.2.11/lib/action_view/path_set.rb
graphael-on-rails-0.0.1 vendor/bundle/gems/actionpack-3.2.11/lib/action_view/path_set.rb
challah-0.9.1.beta.3 vendor/bundle/gems/actionpack-3.2.11/lib/action_view/path_set.rb
devise_sociable-0.1.0 vendor/bundle/gems/actionpack-3.2.11/lib/action_view/path_set.rb
backbone-queryparams-rails-0.0.1 vendor/bundle/gems/actionpack-3.2.11/lib/action_view/path_set.rb
railscast-assets-0.0.2 vendor/bundle/gems/backbone-forms-on-rails-0.10.0/vendor/bundle/gems/actionpack-3.2.11/lib/action_view/path_set.rb
railscast-assets-0.0.2 vendor/bundle/gems/actionpack-3.2.11/lib/action_view/path_set.rb
backbone-forms-on-rails-0.10.0 vendor/bundle/gems/backbone-forms-on-rails-0.10.0/vendor/bundle/gems/actionpack-3.2.11/lib/action_view/path_set.rb
backbone-forms-on-rails-0.10.0 vendor/bundle/gems/actionpack-3.2.11/lib/action_view/path_set.rb
backbone-deep-rails-0.0.1 vendor/bundle/gems/actionpack-3.2.11/lib/action_view/path_set.rb
challah-0.9.1.beta vendor/bundle/gems/actionpack-3.2.11/lib/action_view/path_set.rb
actionpack-3.2.11 lib/action_view/path_set.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.10/lib/action_view/path_set.rb
challah-0.9.0 vendor/bundle/gems/actionpack-3.2.9/lib/action_view/path_set.rb
actionpack-3.2.10 lib/action_view/path_set.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/actionpack-3.2.9/lib/action_view/path_set.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/actionpack-3.2.9/lib/action_view/path_set.rb