Class: Flame::Application
- Inherits:
-
Object
- Object
- Flame::Application
- Defined in:
- lib/flame/application.rb
Overview
Core class, like Framework::Application
Defined Under Namespace
Classes: Config
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
-
.call(env) ⇒ Object
Make available ‘run Application` without `.new` for `rackup`.
-
.default_config_dirs(root_dir:) ⇒ Object
Initialize default for config directories.
-
.inherited(app) ⇒ Object
Generating application config when inherited.
-
.mount(ctrl, path = nil) { ... } ⇒ Object
Mount controller in application class.
-
.router ⇒ Object
Router for routing.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Request recieving method.
-
#config ⇒ Object
Framework configuration.
-
#initialize(app = nil) ⇒ Application
constructor
A new instance of Application.
- #router ⇒ Object
Constructor Details
#initialize(app = nil) ⇒ Application
Returns a new instance of Application.
28 29 30 |
# File 'lib/flame/application.rb', line 28 def initialize(app = nil) @app = app end |
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
8 9 10 |
# File 'lib/flame/application.rb', line 8 def config @config end |
Class Method Details
.call(env) ⇒ Object
Make available ‘run Application` without `.new` for `rackup`
39 40 41 42 |
# File 'lib/flame/application.rb', line 39 def self.call(env) @app ||= new @app.call env end |
.default_config_dirs(root_dir:) ⇒ Object
Initialize default for config directories
72 73 74 75 76 77 78 79 |
# File 'lib/flame/application.rb', line 72 def self.default_config_dirs(root_dir:) { root_dir: File.realpath(root_dir), public_dir: proc { File.join(config[:root_dir], 'public') }, views_dir: proc { File.join(config[:root_dir], 'views') }, config_dir: proc { File.join(config[:root_dir], 'config') } } end |
.inherited(app) ⇒ Object
Generating application config when inherited
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/flame/application.rb', line 17 def self.inherited(app) app.config = Config.new( app, default_config_dirs( root_dir: File.dirname(caller[0].split(':')[0]) ).merge( environment: ENV['RACK_ENV'] || 'development' ) ) end |
.mount(ctrl, path = nil) { ... } ⇒ Object
Mount controller in application class
58 59 60 |
# File 'lib/flame/application.rb', line 58 def self.mount(ctrl, path = nil, &block) router.add_controller(ctrl, path, block) end |
Instance Method Details
#call(env) ⇒ Object
Request recieving method
33 34 35 36 |
# File 'lib/flame/application.rb', line 33 def call(env) @app.call(env) if @app.respond_to? :call Flame::Dispatcher.new(self, env).run! end |
#config ⇒ Object
Framework configuration
12 13 14 |
# File 'lib/flame/application.rb', line 12 def config self.class.config end |
#router ⇒ Object
67 68 69 |
# File 'lib/flame/application.rb', line 67 def router self.class.router end |