Class: EacTemplates::Searcher

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_templates/searcher.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject



10
11
12
# File 'lib/eac_templates/searcher.rb', line 10

def default
  @default ||= new
end

Instance Method Details

#included_pathsObject



37
38
39
# File 'lib/eac_templates/searcher.rb', line 37

def included_paths
  @included_paths ||= ::Set.new
end

#template(subpath, required = true) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/eac_templates/searcher.rb', line 15

def template(subpath, required = true)
  path = template_path(subpath)
  if path.blank?
    return nil unless required

    raise_template_not_found(subpath)
  end
  return ::EacTemplates::File.new(path) if ::File.file?(path)
  return ::EacTemplates::Directory.new(path) if ::File.directory?(path)

  raise 'Invalid branching'
end

#template_path(subpath) ⇒ Object

Returns The absolute path of template if found, nil otherwise.

Returns:

  • The absolute path of template if found, nil otherwise.



29
30
31
32
33
34
35
# File 'lib/eac_templates/searcher.rb', line 29

def template_path(subpath)
  included_paths.each do |included_path|
    r = search_template_in_included_path(included_path, subpath)
    return r if r
  end
  nil
end