Class: Roadie::FilesystemProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/roadie/filesystem_provider.rb

Overview

Asset provider that looks for files on your local filesystem.

It will be locked to a specific path and it will not access files above that directory.

Defined Under Namespace

Classes: InsecurePathError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = Dir.pwd) ⇒ FilesystemProvider

Returns a new instance of FilesystemProvider.



15
16
17
# File 'lib/roadie/filesystem_provider.rb', line 15

def initialize(path = Dir.pwd)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/roadie/filesystem_provider.rb', line 13

def path
  @path
end

Instance Method Details

#find_stylesheet(name) ⇒ Stylesheet?

Returns:



20
21
22
23
24
25
# File 'lib/roadie/filesystem_provider.rb', line 20

def find_stylesheet(name)
  file_path = build_file_path(name)
  if File.exist? file_path
    Stylesheet.new file_path, File.read(file_path)
  end
end

#find_stylesheet!(name) ⇒ Stylesheet

Returns:

Raises:

  • InsecurePathError



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/roadie/filesystem_provider.rb', line 29

def find_stylesheet!(name)
  file_path = build_file_path(name)
  if File.exist? file_path
    Stylesheet.new file_path, File.read(file_path)
  else
    basename = File.basename file_path
    raise CssNotFound.new(
      css_name: basename,
      message: %{#{file_path} does not exist. (Original name was "#{name}")},
      provider: self
    )
  end
end

#inspectObject



47
48
49
# File 'lib/roadie/filesystem_provider.rb', line 47

def inspect
  "#<#{self.class} #{@path}>"
end

#to_sObject



43
44
45
# File 'lib/roadie/filesystem_provider.rb', line 43

def to_s
  inspect
end