Class CKApplication
In: lib/cgikit.rb
Parent: Object

This class is one of the most important classes in CGIKit. CKApplication has two major roles.

One role is that CKAplication provides parameters which effect the whole behavior of CGIKit application. The other role is that CKApplication communicates with CKAdapter, an interface between a web server and CGIKit.

When CGIKit receives a request from a client, CKApplication arranges its parameters and creates a CKAdapter object. Next, CKApplication gets a request object from the CKAdapter object. In reponse to the request object, CKApplication creates a response object and sends it to the CKAdapter object.

Application Process

1. Ready a request and response object

First, CKApplication creates a CKAdapter object and gets a request ( CKRequest ) object from it. Then, CKApplication creates a response ( CKResponse ) object.

2. Event loop

Next, CKApplication goes into event loop. In this loop, CKApplication creates components depending on the request and invokes the specified method of the components until it returns an object whose class is not CKComponent.

3. Return the response object to the CKAdapter object

Finally, CKApplication converts the components created in event loop to HTML and adds the HTML to the CKResponse object created in 1. CKApplication sends the response object to the CKAdapter object. Then, the CKAdapter object displays the response object to a client.

CKApplication Attributes

Controlling application

target:Component to be displayed.
action:Invoked method name of the target component.
main:Main component. If target isn't specified, this component is shown. The default value is 'MainPage'.
path:Path of an application.
component_path:Path for components. Components are searched under this path.
document_root:Document root directory.
locale:Locale of an application in a transaction. If the locale is specified, CGIKit change a template for a component. The name of the template includes the component name and the locale name. Also, the template name is seprated by underscore("_"). For example, if the locale is "ja" and the component name is "MainPage", the template name is "MainPage_ja.html".
master_locale:Main locale of an application in a transaction. If the master_locale is equal to the specified locale, the components use templates whose name doesn't include the locale name. For instance, if the master_locale is "ja", the locale is "ja" and the component name is "MainPage", the template name is "MainPage.html".
resource:Resource directory. If "file" attribute of CKImage is set, the CKImage object searches an image file from resource directory. ( classes which manages other resources will be developed. )
interface:Interface of adapter. The default value is an interface for CGI.

Debugging

debug:Shows the backtrace in an error page when true is set.
attributes_check:Checks required attributes of elements if true is set. If undefined attributes are used or required attributes don't exist, an error page is displayed when the value is true.
Methods
create_adapter    handle_error    master_locale?    name    new    page    run    version   
Attributes
:action  [RW] 
:adapter  [RW] 
:attributes_check  [RW] 
:baseurl  [RW] 
:component_path  [RW] 
:debug  [RW] 
:document_root  [RW] 
:interface  [RW] 
:locale  [RW] 
:main  [RW] 
:master_locale  [RW] 
:path  [RW] 
:request  [RW] 
:resource  [RW] 
:response  [RW] 
:target  [RW] 
Public Class methods
version()

Returns version of CGIKit.

new()
Public Instance methods
name()

Returns the name of the application without file extension.

master_locale?()
run()

This method runs the CGIKit application.

 require 'cgikit'

 app = CKApplication.new
 app.run
create_adapter()
handle_error( error )
page( name )