class Mousevc::App
true
The top level class of Mousevc
. The container for all of the objects created within a Mousevc
application.
Attributes
@!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
@!attribute router
Returns the current router
@return [Mousevc::Router] the router
@!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
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
Returns true
if +@looping+ is set to true
# File lib/mousevc/app.rb, line 87 def looping? @looping end
Runs the application
# File lib/mousevc/app.rb, line 68 def run reset @looping ? listen : single Input.clear nil end
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
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
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
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
Runs the application without looping automatically
# File lib/mousevc/app.rb, line 111 def single clear_view @router.route end