Class: RevealCK::Templates::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/reveal-ck/templates/finder.rb

Overview

Public: This class is home to a simple algorithm for looking up files in a series of directories. Directory order matters, and the first match for the file will be returned. It’ll raise if it can’t find the file you’ve asked for.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Finder

Returns a new instance of Finder.



12
13
14
# File 'lib/reveal-ck/templates/finder.rb', line 12

def initialize(args = {})
  @paths = args[:paths] || default_paths
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



10
11
12
# File 'lib/reveal-ck/templates/finder.rb', line 10

def paths
  @paths
end

Instance Method Details

#default_pathsObject



16
17
18
19
20
21
# File 'lib/reveal-ck/templates/finder.rb', line 16

def default_paths
  pwd_templates = File.join Dir.pwd, 'templates'
  reveal_ck_templates =
    RevealCK.template_path('slides')
  [pwd_templates, reveal_ck_templates]
end

#find(template_name) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/reveal-ck/templates/finder.rb', line 23

def find(template_name)
  paths.each do |path|
    glob_pattern = "#{File.join(path, template_name)}*"
    Dir.glob(glob_pattern).each do |match|
      return match unless File.directory? match
    end
  end
  raise "Unable to find #{template_name} in #{paths}"
end