Class: Ramaze::App

### Home Classes Methods

### In Files

- lib/ramaze/app.rb

### Parent

Object

### Methods

- ::[]
- ::find_or_create
- ::new
- #call
- #location=
- #map
- #public_roots
- #sync
- #to
- #to_app

### Included Modules

- Innate::Optioned

### Files

- Gemfile
- Rakefile

### Class/Module Index

Quicksearch

- Ramaze
- Ramaze::App
- Ramaze::Bin
- Ramaze::Bin::Create
- Ramaze::Bin::Runner
- Ramaze::Cache
- Ramaze::Cache::LRU
- Ramaze::Cache::LocalMemCache
- Ramaze::Cache::MemCache
- Ramaze::Cache::Redis
- Ramaze::Cache::Sequel
- Ramaze::Controller
- Ramaze::CoreExtensions
- Ramaze::CoreExtensions::Object
- Ramaze::CoreExtensions::String
- Ramaze::Current
- Ramaze::DefaultController
- Ramaze::Files
- Ramaze::Gestalt
- Ramaze::Helper
- Ramaze::Helper::Auth
- Ramaze::Helper::Bench
- Ramaze::Helper::BlueForm
- Ramaze::Helper::BlueForm::Form
- Ramaze::Helper::CSRF
- Ramaze::Helper::Cache
- Ramaze::Helper::Cache::SingletonMethods
- Ramaze::Helper::Email
- Ramaze::Helper::Erector
- Ramaze::Helper::Flash
- Ramaze::Helper::Formatting
- Ramaze::Helper::Gestalt
- Ramaze::Helper::Gravatar
- Ramaze::Helper::Identity
- Ramaze::Helper::Layout
- Ramaze::Helper::Layout::SingletonMethods
- Ramaze::Helper::Link
- Ramaze::Helper::Localize
- Ramaze::Helper::Localize::Dictionary
- Ramaze::Helper::Localize::Parser
- Ramaze::Helper::Markaby
- Ramaze::Helper::Maruku
- Ramaze::Helper::Paginate
- Ramaze::Helper::Paginate::Paginator
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Ramaze::Helper::Paginate::Paginator::DataMapperPager
- Ramaze::Helper::Remarkably
- Ramaze::Helper::RequestAccessor
- Ramaze::Helper::SendFile
- Ramaze::Helper::SimpleCaptcha
- Ramaze::Helper::Stack
- Ramaze::Helper::Thread
- Ramaze::Helper::Upload
- Ramaze::Helper::Upload::ClassMethods
- Ramaze::Helper::Upload::UploadedFile
- Ramaze::Helper::UserHelper
- Ramaze::Helper::UserHelper::Wrapper
- Ramaze::Helper::XHTML
- Ramaze::LRUHash
- Ramaze::Logger
- Ramaze::Logger::Informer
- Ramaze::Logger::LogHub
- Ramaze::Logger::Logger
- Ramaze::Logger::RotatingInformer
- Ramaze::Logger::Syslog
- Ramaze::Logging
- Ramaze::Reloader
- Ramaze::Reloader::Hooks
- Ramaze::Reloader::WatchInotify
- Ramaze::Reloader::WatchStat
- Ramaze::Request
- Ramaze::Response
- Ramaze::SpecLogger
- Ramaze::View
- Ramaze::View::Erector
- Ramaze::View::Erubis
- Ramaze::View::Ezamar
- Ramaze::View::Gestalt
- Ramaze::View::Haml
- Ramaze::View::Liquid
- Ramaze::View::Liquid::Tag
- Ramaze::View::Lokar
- Ramaze::View::Mustache
- Ramaze::View::Mustache::RamazeContext
- Ramaze::View::Nagoro
- Ramaze::View::Remarkably
- Ramaze::View::Sass
- Ramaze::View::Slippers
- Ramaze::View::Tagz
- Ramaze::View::Tagz::Methods
- Ramaze::View::Tenjin
- Innate
- Innate::View
- Innate::View::Slim
- Nagoro
- Nagoro::Pipe
- Nagoro::Pipe::RenderPartial
- Bacon
- Bacon::PrettyOutput
- Erector
- Erector::Widget
- Rack
- Rack::RouteExceptions
- Tenjin
- Tenjin::Template
- BlankSlate
- Controller
- MainController
- Object

No matching classes.

# Ramaze::App

App is the superclass for applications and acts as their prototype when it comes to configuration.

An application consists of options, a location, and a list of objects. The objects are usually {Ramaze::Controller}s.

The options are inherited, the basics are set in Ramaze.options, from there to Ramaze::App.options, and finally into every instance of App.

This allows to collect {Ramaze::Controller}s of your application into a common group that can easily be used in other applications, while retaining the original options.

Every instance of {App} is mapped in {AppMap}, which is the default location to call from Rack.

Additionally, every {App} can have custom locations for root/public/view/layout directories, which allows reuse beyond directory boundaries.

In contrast to Innate, where all Nodes share the same middleware, {App} also has a subset of middleware that handles serving static files, routes and rewrites.

To indicate that a {Ramaze::Controller} belongs to a specific application, you can pass a second argument to {Ramaze::Controller::map}

@example adding Controller to application

    class WikiController < Ramaze::Controller
      map '/', :wiki
    end

The App instance will be created for you and if you don't use any other applications in your code there is nothing else you have to do. Others can now come and simply reuse your code in their own applications.

There is some risk of name collisions if everybody calls their app `:wiki`, but given that you only use one foreign app of this kind might give less reason for concern.

If you still try to use two apps with the same name, you have to be careful, loading one first, renaming it, then loading the second one.

The naming of an App has no influence on any other aspects of dispatching or configuration.

### Constants

APP_LIST

### Attributes

location[R]
name[R]
options[R]
url_map[R]

### Public Class Methods

[](name) click to toggle source

Returns the application for the given name.

@author Michael Fellinger @param [String] name The name of the application. @return [Ramaze::App]

    # File lib/ramaze/app.rb, line 93
    def self.[](name)
      APP_LIST[name.to_sym]
    end

find_or_create(name, location = nil) click to toggle source

Finds or creates an application for the given name and URI.

@author Michael Fellinger @param [String] name The name of the application. @param [String] location The URI to which the app is mapped. @return [Ramaze::App]

    # File lib/ramaze/app.rb, line 81
    def self.find_or_create(name, location = nil)
      location = '/' if location.nil? && name == :pristine
      self[name] || new(name, location)
    end

new(name, location = nil) click to toggle source

Creates a new instance of the application and sets the name and location.

@author Michael Fellinger @since 30-06-2009 @param [String] name The name of the application. @param [String] location The location to which the application is mapped.

    # File lib/ramaze/app.rb, line 105
    def initialize(name, location = nil)
      @name = name.to_sym
      @url_map = Innate::URLMap.new
      self.location = location if location

      APP_LIST[@name] = self

      @options = self.class.options.sub(@name)
    end

### Public Instance Methods

call(env) click to toggle source

Allows the application to be called as a Rack middleware.

@author Michael Fellinger @since 30-06-2009 @param [Hash] env The environment hash.

    # File lib/ramaze/app.rb, line 143
    def call(env)
      to_app.call(env)
    end

location=(location) click to toggle source

Sets the location and syncs the application.

@author Michael Fellinger @since 30-06-2009

    # File lib/ramaze/app.rb, line 131
    def location=(location)
      @location = location.to_str.freeze
      sync
    end

map(location, object) click to toggle source

Maps an object to the given URI.

@author Michael Fellinger @since 30-06-2009 @param [String] location The URI to map the object to. @param [Object] object The object (usually a controller) to map to the

    URI.

    # File lib/ramaze/app.rb, line 169
    def map(location, object)
      url_map.map(location, object)
    end

public_roots() click to toggle source

Returns an array containing all the public directories for each root directory.

@author Michael Fellinger @since 30-06-2009 @return [Array]

    # File lib/ramaze/app.rb, line 193
    def public_roots
      roots, publics = [*options.roots], [*options.publics]
      roots.map{|root| publics.map{|public| ::File.join(root, public) }}.flatten
    end

sync() click to toggle source

Syncs the instance of the current application with Ramaze::AppMap.

@author Michael Fellinger @since 30-06-2009

    # File lib/ramaze/app.rb, line 121
    def sync
      AppMap.map(location, self)
    end

to(object) click to toggle source

Returns a URI to the given object.

@author Michael Fellinger @since 30-06-2009 @param [Object] object An object for which to generate the URI.

    # File lib/ramaze/app.rb, line 180
    def to(object)
      return unless mapped = url_map.to(object)
      [location, mapped].join('/').squeeze('/')
    end

to_app() click to toggle source

Converts the application to a Rack compatible class.

@author Michael Fellinger @since 30-06-2009 @return [Rack::Cascade]

    # File lib/ramaze/app.rb, line 154
    def to_app
      files = Ramaze::Files.new(*public_roots)
      app = Current.new(Route.new(url_map), Rewrite.new(url_map))
      Rack::Cascade.new([files, app])
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.