Class: Ramaze::Files

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

Overview

Class that makes it possible to easily use multiple public directories in your Ramaze application.

Author:

Since:

Instance Method Summary (collapse)

Constructor Details

- (Files) initialize(*roots)

Creates a new instance of the class, stores the given root directories and syncs the changes with Rack::Cascade.

Parameters:

  • roots (Array)

    A set of root directories that contain a number of public directories.

Author:

  • Michael Fellinger

Since:

  • 14-03-2009



19
20
21
22
# File 'lib/ramaze/files.rb', line 19

def initialize(*roots)
  @roots = roots.flatten.map{|root| File.expand_path(root.to_s) }
  sync
end

Instance Method Details

- (Object) <<(path)

Adds a new path to the list of root directories.

Parameters:

  • path (String)

    The path to add to the existing root directories.

Author:

  • Michael Fellinger

Since:

  • 14-03-2009



42
43
44
45
46
# File 'lib/ramaze/files.rb', line 42

def <<(path)
  @roots << File.expand_path(path.to_s)
  @roots.uniq!
  sync
end

- (Object) call(env)

Allows this class to be called as a Rack middleware.

Parameters:

  • env (Hash)

    Hash containing all the environment details.

Author:

  • Michael Fellinger

Since:

  • 14-03-2009



31
32
33
# File 'lib/ramaze/files.rb', line 31

def call(env)
  @cascade.call(env)
end

- (Object) sync

Syncs the class with Rack::Cascade.

Author:

  • Michael Fellinger

Since:

  • 14-03-2009



54
55
56
57
# File 'lib/ramaze/files.rb', line 54

def sync
  file_apps = @roots.map { |root| Rack::File.new(root) }
  @cascade  = Rack::Cascade.new(file_apps)
end