Module: Deface::Search::ClassMethods

Included in:
Override
Defined in:
lib/deface/search.rb

Instance Method Summary collapse

Instance Method Details

#find(details) ⇒ Object

finds all applicable overrides for supplied template



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/deface/search.rb', line 7

def find(details)
  return [] if self.all.empty? || details.empty?

  virtual_path = details[:virtual_path].dup
  return [] if virtual_path.nil?

  [/^\//, /\.\w+\z/].each { |regex| virtual_path.gsub!(regex, '') }

  result = []
  result << self.all[virtual_path.to_sym].try(:values)

  result.flatten.compact.sort_by &:sequence
end

#find_using(virtual_path) ⇒ Object

finds all overrides that are using a template / parital as there source



23
24
25
26
27
28
29
# File 'lib/deface/search.rb', line 23

def find_using(virtual_path)
  self.all.map do |key, overrides_by_name|
    overrides_by_name.values.select do |override|
      [:template, :partial].include?(override.source_argument) && override.args[override.source_argument] == virtual_path
    end
  end.flatten
end