class Mousevc::App

true

The top level class of Mousevc. The container for all of the objects created within a Mousevc application.

Attributes

looping[RW]

@!attribute looping

Set this to true if you want the application to loop, defaults to false

@return [Boolean] whether or not the application should loop

router[R]

@!attribute router

Returns the current router

@return [Mousevc::Router] the router

system_clear[RW]

@!attribute system_clear

Setting this to false will disable calls to +system('clear')+ at the start of each application loop.

@return [Boolean] whether or not to perform system clear

Public Class Methods

new(options={}) click to toggle source

Creates a new Mousevc::App instance

@note as of v0.0.6 Mousevc requires that the views path be absolute, e.g +“#{File.dirname(__FILE__)}/views”+

@param options [Hash] expects the following keys:

- :controller => [String] name of default controller class
- :model => [String] name of default model class
- :action => [Symbol] method to call on default controller
- :views => [String] the absolute path to your views directory
- :looping => [Boolean] +true+ if the application should loop, defaults to +false+
- :system_clear => [Boolean] +true+ if output should be cleared on update, defaults to +false+
# File lib/mousevc/app.rb, line 56
def initialize(options={})
        @controller = options[:controller]
        @model = options[:model]
        @action = options[:action]
        @views = options[:views]
        @looping = options[:looping].nil? ? false : options[:looping]
        @system_clear = options[:system_clear].nil? ? false : options[:system_clear]
end

Public Instance Methods

looping?() click to toggle source

Returns true if +@looping+ is set to true

# File lib/mousevc/app.rb, line 87
def looping?
        @looping
end
run() click to toggle source

Runs the application

# File lib/mousevc/app.rb, line 68
def run
        reset
        @looping ? listen : single
        Input.clear
        nil
end
system_clear?() click to toggle source

Returns true if +@system_clear+ is true

@return [Boolean] whether or not system clearing is enabled

# File lib/mousevc/app.rb, line 80
def system_clear?
        @system_clear
end

Private Instance Methods

clear_view() click to toggle source

Executes a system clear if system clearing is enabled

# File lib/mousevc/app.rb, line 135
def clear_view
        Kernel.system('clear') if system_clear?
end
listen() click to toggle source

Runs the application loop. Clears the system view each iteration. Calls route on the router instance.

If the user is trying to reset or quit the application responds accordingly. Clears Input class variables before exit.

# File lib/mousevc/app.rb, line 124
def listen
        begin
                clear_view
                @router.route unless Input.quit?
                reset if Input.reset?
        end until Input.quit?
end
reset() click to toggle source

Instantiates the router instance. @todo add callback where a block is called on reset, and event listener functionality

Passes the router instance the initialization options.

# File lib/mousevc/app.rb, line 99
def reset
        @router = Router.new(
                :controller => @controller,
                :action => @action,
                :model => @model,
                :views => @views
        )
end
single() click to toggle source

Runs the application without looping automatically

# File lib/mousevc/app.rb, line 111
def single
        clear_view
        @router.route
end