Class: Prez::Files::Paths

Inherits:
Object
  • Object
show all
Defined in:
lib/prez/files.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extension_alias, extensions, dirname, options = {}) ⇒ Paths

Returns a new instance of Paths.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/prez/files.rb', line 12

def initialize(extension_alias, extensions, dirname, options = {})
  @extension_alias = extension_alias
  @extensions = extensions
  @binary = options.fetch :binary, false

  @paths = [].tap do |paths|
    paths << File.expand_path(".")
    paths << File.expand_path(File.join(".", dirname))
    paths << File.expand_path(File.join("../../../vendor", dirname), __FILE__)
  end
end

Instance Attribute Details

#extension_aliasObject (readonly)

Returns the value of attribute extension_alias.



10
11
12
# File 'lib/prez/files.rb', line 10

def extension_alias
  @extension_alias
end

#extensionsObject (readonly)

Returns the value of attribute extensions.



10
11
12
# File 'lib/prez/files.rb', line 10

def extensions
  @extensions
end

#pathsObject (readonly)

Returns the value of attribute paths.



10
11
12
# File 'lib/prez/files.rb', line 10

def paths
  @paths
end

Instance Method Details

#binary?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/prez/files.rb', line 44

def binary?
  @binary
end

#find(name) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/prez/files.rb', line 24

def find(name)
  paths.each do |path|
    extensions.each do |extension|
      files = [File.join(path, "#{name}.#{extension}")]

      if name.end_with?(".#{extension}")
        files << File.join(path, name)
      end

      files.each do |file|
        if File.exists?(file)
          return file
        end
      end
    end
  end

  raise Prez::Files::MissingError.new(name, extension_alias)
end