Class: ActionView::PathSet

Inherits:
Object show all
Includes:
Enumerable
Defined in:
actionview/lib/action_view/path_set.rb

Overview

Action View PathSet

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#as_json, #exclude?, #index_by, #many?, #sum

Constructor Details

#initialize(paths = []) ⇒ PathSet

Returns a new instance of PathSet.



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

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

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths



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

def paths
  @paths
end

Instance Method Details

#+(array) ⇒ Object



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

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

#compactObject



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

def compact
  PathSet.new paths.compact
end

#exists?(path, prefixes, *args) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'actionview/lib/action_view/path_set.rb', line 60

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

#find(*args) ⇒ Object



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

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

#find_all(path, prefixes = [], *args) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'actionview/lib/action_view/path_set.rb', line 49

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

#initialize_copy(other) ⇒ Object



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

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

#to_aryObject



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

def to_ary
  paths.dup
end