Class: Tzispa::Application
- Inherits:
-
Object
- Object
- Tzispa::Application
- Extended by:
- Forwardable
- Includes:
- Helpers::ErrorView
- Defined in:
- lib/tzispa/app.rb
Class Attribute Summary collapse
-
.routes ⇒ Object
Returns the value of attribute routes.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#middleware ⇒ Object
readonly
Returns the value of attribute middleware.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Class Method Summary collapse
- .applications ⇒ Object
- .inherited(base) ⇒ Object
- .mount(mount_point, builder) ⇒ Object
- .router ⇒ Object
- .synchronize ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(domain_name) ⇒ Application
constructor
A new instance of Application.
- #load! ⇒ Object
Constructor Details
#initialize(domain_name) ⇒ Application
Returns a new instance of Application.
71 72 73 74 75 |
# File 'lib/tzispa/app.rb', line 71 def initialize(domain_name) @domain = Domain.new(domain_name) @middleware = Middleware.new self @config = Config::AppConfig.new(@domain).load! end |
Class Attribute Details
.routes ⇒ Object
Returns the value of attribute routes.
34 35 36 |
# File 'lib/tzispa/app.rb', line 34 def routes @routes end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
27 28 29 |
# File 'lib/tzispa/app.rb', line 27 def config @config end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
27 28 29 |
# File 'lib/tzispa/app.rb', line 27 def domain @domain end |
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
27 28 29 |
# File 'lib/tzispa/app.rb', line 27 def engine @engine end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
27 28 29 |
# File 'lib/tzispa/app.rb', line 27 def logger @logger end |
#middleware ⇒ Object (readonly)
Returns the value of attribute middleware.
27 28 29 |
# File 'lib/tzispa/app.rb', line 27 def middleware @middleware end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
27 28 29 |
# File 'lib/tzispa/app.rb', line 27 def repository @repository end |
Class Method Details
.applications ⇒ Object
45 46 47 48 49 |
# File 'lib/tzispa/app.rb', line 45 def applications synchronize do @@applications ||= Set.new end end |
.inherited(base) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/tzispa/app.rb', line 36 def inherited(base) super base.class_eval do synchronize do applications.add(base) end end end |
.mount(mount_point, builder) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/tzispa/app.rb', line 57 def mount(mount_point, builder) self.new.tap { |app| self.routes ||= Routes.new(mount_point) yield(routes) app.middleware.map mount_point, builder } end |
.router ⇒ Object
65 66 67 |
# File 'lib/tzispa/app.rb', line 65 def router self.routes&.router end |
.synchronize ⇒ Object
51 52 53 54 55 |
# File 'lib/tzispa/app.rb', line 51 def synchronize Mutex.new.synchronize { yield } end |
Instance Method Details
#call(env) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/tzispa/app.rb', line 77 def call(env) env[Tzispa::ENV_TZISPA_APP] = self context = Tzispa::Http::Context.new(env) env[Tzispa::ENV_TZISPA_CONTEXT] = context begin middleware.call(env) rescue StandardError, ScriptError => ex logger.error "#{ex.}\n#{ex.backtrace.map { |trace| "\t #{trace}" }.join('\n') if ex.respond_to?(:backtrace) && ex.backtrace}" if config.developing context.error_500 error_report(ex) else context.error_500 error_page(domain) end context.response.finish end end |
#load! ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/tzispa/app.rb', line 94 def load! unless @loaded Mutex.new.synchronize { load_locales @repository = Data::Repository.new(@config.repository.to_h).load! if @config.respond_to? :repository @engine = Rig::Engine.new(self, @config.template_cache.enabled, @config.template_cache.size) @logger = Logger.new("logs/#{@domain.name}.log", 'weekly') @logger.level = @config.respond_to?(:developing) && @config.developing ? Logger::DEBUG : Logger::INFO @domain.require_dir 'helpers' @domain.require_dir 'api' @domain.require_dir 'middleware' @middleware.load! @loaded = true } end self end |