Class: Lotus::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/application.rb

Overview

A full stack Lotus application

Examples:

require 'lotus'

module Bookshelf
  class Application < Lotus::Application
  end
end

Since:

  • 0.1.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLotus::Application

Initialize and load a new instance of the application

Since:

  • 0.1.0



108
109
110
# File 'lib/lotus/application.rb', line 108

def initialize
  self.class.load!(self)
end

Instance Attribute Details

#rendererObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Rendering policy

 @param [Lotus::RenderingPolicy]

Since:

  • 0.2.0



101
102
103
# File 'lib/lotus/application.rb', line 101

def renderer
  @renderer
end

#routesLotus::Router

Return the routes for this application

Returns:

  • (Lotus::Router)

    a route set

See Also:

Since:

  • 0.1.0



85
86
87
# File 'lib/lotus/application.rb', line 85

def routes
  @routes
end

Class Method Details

.applicationsSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Registry of Lotus applications in the current Ruby process

Returns:

  • (Set)

    a set of all the registered applications

Since:

  • 0.2.0



48
49
50
51
52
# File 'lib/lotus/application.rb', line 48

def self.applications
  synchronize do
    @@applications ||= Set.new
  end
end

.configure(environment = nil, &blk) ⇒ Object

Configure the application. It yields the given block in the context of the configuration

Examples:

require 'lotus'

module Bookshelf
  Application < Lotus::Application
    configure do
      # ...
    end
  end
end

Parameters:

  • environment (Symbol, nil) (defaults to: nil)

    the configuration environment name

  • blk (Proc)

    the configuration block

See Also:

Since:

  • 0.1.0



74
75
76
# File 'lib/lotus/application.rb', line 74

def self.configure(environment = nil, &blk)
  configuration.configure(environment, &blk)
end

.inherited(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Override Ruby’s Class#inherited



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lotus/application.rb', line 27

def self.inherited(base)
  super

  base.class_eval do
    include Lotus::Utils::ClassAttribute

    class_attribute :configuration
    self.configuration = Configuration.new
  end

  synchronize do
    applications.add(base)
  end
end

.load!(application = self) ⇒ Object

Eager load the application configuration, by activating the framework duplication mechanisms.

Examples:

require 'lotus'

module OneFile
  class Application < Lotus::Application
    configure do
      routes do
        get '/', to: 'dashboard#index'
      end
    end

    load!
  end

  module Controllers::Dashboard
    include OneFile::Controller

    action 'Index' do
      def call(params)
        self.body = 'Hello!'
      end
    end
  end
end

Parameters:

Returns:

  • void

Since:

  • 0.1.1



144
145
146
# File 'lib/lotus/application.rb', line 144

def self.load!(application = self)
  Lotus::Loader.new(application).load!
end

.preload!Object

Preload all the registered applications, by yielding their configurations and preparing the frameworks.

This is useful for testing suites, where we want to make Lotus frameworks ready, but not preload applications code.

This allows to test components such as views or actions in isolation and to have faster boot times.

 @return [void]

Since:

  • 0.2.0



160
161
162
163
164
165
166
# File 'lib/lotus/application.rb', line 160

def self.preload!
  synchronize do
    applications.each(&:load!)
  end

  nil
end

.preload_applications!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Full preload for all the registered applications.

This is useful in console where we want all the application code available.

 @return [void]

Since:

  • 0.2.1



176
177
178
179
180
181
182
# File 'lib/lotus/application.rb', line 176

def self.preload_applications!
  synchronize do
    applications.each { |app| app.new }
  end

  nil
end

Instance Method Details

#call(env) ⇒ Array

Process a request. This method makes Lotus applications compatible with the Rack protocol.

Parameters:

  • env (Hash)

    a Rack env

Returns:

  • (Array)

    a serialized Rack response

See Also:

Since:

  • 0.1.0



213
214
215
216
# File 'lib/lotus/application.rb', line 213

def call(env)
  renderer.render(env,
                  middleware.call(env))
end

#configurationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the configuration for this application

See Also:

  • configuration

Since:

  • 0.1.0



190
191
192
# File 'lib/lotus/application.rb', line 190

def configuration
  self.class.configuration
end

#middlewareLotus::Middleware

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Rack middleware stack

Returns:

See Also:

Since:

  • 0.1.0



226
227
228
# File 'lib/lotus/application.rb', line 226

def middleware
  @middleware ||= configuration.middleware
end

#nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return the application name

Since:

  • 0.2.0



198
199
200
# File 'lib/lotus/application.rb', line 198

def name
  self.class.name
end