123456789_123456789_123456789_123456789_123456789_

Class: ActionView::PathSet

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: actionview/lib/action_view/path_set.rb

Overview

This class is used to store and access paths in Action View. A number of operations are defined so that you can search among the paths in this set and also perform operations on other PathSet objects.

A LookupContext will use a PathSet to store the paths in its context.

Class Method Summary

Instance Attribute Summary

::Enumerable - Included

#many?

Returns true if the enumerable has more than 1 element.

Instance Method Summary

::Enumerable - Included

#compact_blank

Returns a new ::Array without the blank items.

#exclude?

The negative of the Enumerable#include?.

#excluding

Returns a copy of the enumerable excluding the specified elements.

#in_order_of

Returns a new ::Array where the order has been set to that provided in the series, based on the key of the objects in the original enumerable.

#including

Returns a new array that includes the passed elements.

#index_by

Convert an enumerable to a hash, using the block result as the key and the element as the value.

#index_with

Convert an enumerable to a hash, using the element as the key and the block result as the value.

#maximum

Calculates the maximum from the extracted elements.

#minimum

Calculates the minimum from the extracted elements.

#pick

Extract the given key from the first element in the enumerable.

#pluck

Extract the given key from each element in the enumerable.

#sole

Returns the sole item in the enumerable.

#without
#as_json

::ActiveSupport::EnumerableCoreExt::Constants - Included

Constructor Details

.new(paths = []) ⇒ PathSet

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 18

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

Instance Attribute Details

#each (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 16

delegate :[], :include?, :size, :each, to: :paths

#paths (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 14

attr_reader :paths

#size (readonly)

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 16

delegate :[], :include?, :size, :each, to: :paths

Instance Method Details

#+(other)

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 35

def +(other)
  array = Array === other ? other : other.paths
  PathSet.new(paths + array)
end

#[]

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 16

delegate :[], :include?, :size, :each, to: :paths

#compact

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 31

def compact
  PathSet.new paths.compact
end

#exists?(path, prefixes, partial, details, details_key, locals) ⇒ Boolean

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 53

def exists?(path, prefixes, partial, details, details_key, locals)
  find_all(path, prefixes, partial, details, details_key, locals).any?
end

#find(path, prefixes, partial, details, details_key, locals)

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 40

def find(path, prefixes, partial, details, details_key, locals)
  find_all(path, prefixes, partial, details, details_key, locals).first ||
    raise(MissingTemplate.new(self, path, prefixes, partial, details, details_key, locals))
end

#find_all(path, prefixes, partial, details, details_key, locals)

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 45

def find_all(path, prefixes, partial, details, details_key, locals)
  search_combinations(prefixes) do |resolver, prefix|
    templates = resolver.find_all(path, prefix, partial, details, details_key, locals)
    return templates unless templates.empty?
  end
  []
end

#include?Boolean

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 16

delegate :[], :include?, :size, :each, to: :paths

#initialize_copy(other)

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 22

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

#search_combinations(prefixes) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 58

def search_combinations(prefixes)
  prefixes = Array(prefixes)
  prefixes.each do |prefix|
    paths.each do |resolver|
      yield resolver, prefix
    end
  end
end

#to_ary

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 27

def to_ary
  paths.dup
end

#typecast(paths) (private)

[ GitHub ]

  
# File 'actionview/lib/action_view/path_set.rb', line 67

def typecast(paths)
  paths.map do |path|
    case path
    when Pathname, String
      # This path should only be reached by "direct" users of
      # ActionView::Base (not using the ViewPaths or Renderer modules).
      # We can't cache/de-dup the file system resolver in this case as we
      # don't know which compiled_method_container we'll be rendering to.
      FileSystemResolver.new(path)
    when Resolver
      path
    else
      raise TypeError, "#{path.inspect} is not a valid path: must be a String, Pathname, or Resolver"
    end
  end
end