Class: Tzispa::Application
- Inherits:
-
Object
- Object
- Tzispa::Application
- Extended by:
- Forwardable
- Defined in:
- lib/tzispa/app.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#map_path ⇒ Object
readonly
Returns the value of attribute map_path.
Class Method Summary collapse
- .[](name) ⇒ Object
- .__new__ ⇒ Object
- .add(app) ⇒ Object
-
.applications ⇒ Object
rubocop:disable Style/ClassVars.
- .new(*args, &block) ⇒ Object
- .synchronize ⇒ Object
Instance Method Summary collapse
- #[](domain) ⇒ Object
- #call(env) ⇒ Object
- #config ⇒ Object
- #default_layout?(layout) ⇒ Boolean
- #env ⇒ Object
-
#initialize(appid, on: nil, &block) ⇒ Application
constructor
A new instance of Application.
- #load! ⇒ Object
- #repository ⇒ Object
- #routes ⇒ Object
Constructor Details
#initialize(appid, on: nil, &block) ⇒ Application
Returns a new instance of Application.
52 53 54 55 56 |
# File 'lib/tzispa/app.rb', line 52 def initialize(appid, on: nil, &block) @domain = Domain.new(appid) @map_path = on instance_eval(&block) if block end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
17 18 19 |
# File 'lib/tzispa/app.rb', line 17 def domain @domain end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
17 18 19 |
# File 'lib/tzispa/app.rb', line 17 def logger @logger end |
#map_path ⇒ Object (readonly)
Returns the value of attribute map_path.
17 18 19 |
# File 'lib/tzispa/app.rb', line 17 def map_path @map_path end |
Class Method Details
.[](name) ⇒ Object
40 41 42 |
# File 'lib/tzispa/app.rb', line 40 def [](name) applications[name] end |
.__new__ ⇒ Object
23 |
# File 'lib/tzispa/app.rb', line 23 alias __new__ :new |
.add(app) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/tzispa/app.rb', line 44 def add(app) synchronize do raise DuplicateDomain.new(app.name) if applications.key?(app.name) applications[app.name] = app end end |
.applications ⇒ Object
rubocop:disable Style/ClassVars
30 31 32 33 34 |
# File 'lib/tzispa/app.rb', line 30 def applications synchronize do @@applications ||= Hash.new { |_, key| raise UnknownApplication(key.to_s) } end end |
.new(*args, &block) ⇒ Object
25 26 27 |
# File 'lib/tzispa/app.rb', line 25 def new(*args, &block) __new__(*args, &block).tap { |app| add app } end |
.synchronize ⇒ Object
36 37 38 |
# File 'lib/tzispa/app.rb', line 36 def synchronize Mutex.new.synchronize { yield } end |
Instance Method Details
#[](domain) ⇒ Object
74 75 76 |
# File 'lib/tzispa/app.rb', line 74 def [](domain) self.class[domain] end |
#call(env) ⇒ Object
58 59 60 |
# File 'lib/tzispa/app.rb', line 58 def call(env) routes.call env end |
#config ⇒ Object
90 91 92 |
# File 'lib/tzispa/app.rb', line 90 def config @config ||= Config::AppConfig.new(@domain).load! end |
#default_layout?(layout) ⇒ Boolean
78 79 80 |
# File 'lib/tzispa/app.rb', line 78 def default_layout?(layout) config.default_layout.to_sym == layout end |
#env ⇒ Object
82 83 84 |
# File 'lib/tzispa/app.rb', line 82 def env Tzispa::Environment.instance end |
#load! ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/tzispa/app.rb', line 62 def load! tap do |app| app.class.synchronize do logging load_locales domain.setup routes.setup repository&.load!(domain) end end end |
#repository ⇒ Object
94 95 96 97 98 99 |
# File 'lib/tzispa/app.rb', line 94 def repository @repository ||= begin dbcfg = Config::DbConfig.new(env.environment)&.to_h Data::Repository.new(dbcfg) if dbcfg&.count&.positive? end end |
#routes ⇒ Object
86 87 88 |
# File 'lib/tzispa/app.rb', line 86 def routes @routes ||= RouteSet.new(self, map_path) end |