class Tennpipes::Application

Subclasses of this become independent Tennpipes applications (stemming from Sinatra::Application). These subclassed applications can be easily mounted into other Tennpipes applications as well.

Public Class Methods

default(option, *args, &block) click to toggle source
# File lib/tennpipes-base/application.rb, line 161
def default(option, *args, &block)
  set(option, *args, &block) unless respond_to?(option)
end
dependencies() click to toggle source

Returns default list of path globs to load as dependencies. Appends custom dependency patterns to the be loaded for your Application.

@return [Array]

list of path globs to load as dependencies

@example

MyApp.dependencies << "#{Tennpipes.root}/uploaders/**/*.rb"
MyApp.dependencies << Tennpipes.root('other_app', 'controllers.rb')
# File lib/tennpipes-base/application.rb, line 129
def dependencies
  [
    'urls.rb',
    'config/urls.rb',
    'mailers/*.rb',
    'mailers.rb',
    'controllers/**/*.rb',
    'controllers.rb',
    'helpers/**/*.rb',
    'helpers.rb',
  ].flat_map{ |file| Dir.glob(File.join(settings.root, file)) }
end
inherited(base) click to toggle source
Calls superclass method
# File lib/tennpipes-base/application.rb, line 30
def inherited(base)
  begun_at = Time.now
  CALLERS_TO_IGNORE.concat(TENNPIPES_IGNORE_CALLERS)
  super(base)
  base.prerequisites.replace(self.prerequisites.dup)
  base.default_configuration!
  logger.devel :setup, begun_at, base
end
layout_path(layout) click to toggle source

Returns an absolute path of application layout.

@example

Admin.layout_path :application #=> "/home/user/test/admin/views/layouts/application"
# File lib/tennpipes-base/application.rb, line 102
def layout_path(layout)
  view_path("layouts/#{layout}")
end
prerequisites() click to toggle source

An array of file to load before your app.rb, basically are files which our app depends on.

By default we look for files:

# List of default files that we are looking for:
yourapp/models.rb
yourapp/models/**/*.rb
yourapp/lib.rb
yourapp/lib/**/*.rb

@example Adding a custom prerequisite

MyApp.prerequisites << Tennpipes.root('my_app', 'custom_model.rb')
# File lib/tennpipes-base/application.rb, line 157
def prerequisites
  @_prerequisites ||= []
end
reload!() click to toggle source

Reloads the application files from all defined load paths.

This method is used from our Tennpipes Reloader during development mode in order to reload the source files.

@return [TrueClass]

@example

MyApp.reload!
# File lib/tennpipes-base/application.rb, line 50
def reload!
  logger.devel "Reloading application #{settings}"
  reset!
  reset_router!
  Tennpipes.require_dependencies(settings.app_file, :force => true)
  require_dependencies
  default_routes
  default_errors
  I18n.reload! if defined?(I18n)
  true
end
reset_routes!() click to toggle source

Resets application routes to only routes not defined by the user.

@return [TrueClass]

@example

MyApp.reset_routes!
# File lib/tennpipes-base/application.rb, line 70
def reset_routes!
  reset_router!
  default_routes
  true
end
routes() click to toggle source

Returns the routes of our app.

@example

MyApp.routes
# File lib/tennpipes-base/application.rb, line 82
def routes
  router.routes
end
run!(options={}) click to toggle source

Run the Tennpipes app as a self-hosted server using Thin, Mongrel or WEBrick (in that order).

@see Tennpipes::Server#start

# File lib/tennpipes-base/application.rb, line 112
def run!(options={})
  return unless Tennpipes.load!
  Tennpipes.mount(settings.to_s).to('/')
  Tennpipes.run!(options)
end
view_path(view) click to toggle source

Returns an absolute path of view in application views folder.

@example

Admin.view_path 'users/index' #=> "/home/user/test/admin/views/users/index"
# File lib/tennpipes-base/application.rb, line 92
def view_path(view)
  File.expand_path(view, views)
end

Protected Class Methods

require_dependencies() click to toggle source

Requires all files within the application load paths.

# File lib/tennpipes-base/application.rb, line 170
def require_dependencies
  Tennpipes.require_dependencies(dependencies, :force => true)
end

Public Instance Methods

logger() click to toggle source

Returns the logger for this application.

@return [Tennpipes::Logger] Logger associated with this app.

# File lib/tennpipes-base/application.rb, line 25
def logger
  Tennpipes.logger
end