Class: Flame::Application

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

Overview

Core class, like Framework::Application

Defined Under Namespace

Classes: Config

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = nil) ⇒ Application

Returns a new instance of Application.



27
28
29
30
31
32
33
34
# File 'lib/flame/application.rb', line 27

def initialize(app = nil)
	@app = app
	router.routes.map! do |route|
		route[:hooks] = router.find_hooks(route)
		route.freeze
	end
	router.freeze
end

Class Attribute Details

.configObject

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



42
43
44
45
# File 'lib/flame/application.rb', line 42

def self.call(env)
	@app ||= new
	@app.call env
end

.default_config_dirs(root_dir:) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/flame/application.rb', line 64

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

.helpers(*modules) ⇒ Object



51
52
53
# File 'lib/flame/application.rb', line 51

def self.helpers(*modules)
	modules.empty? ? (@helpers ||= []) : helpers.concat(modules).uniq!
end

.inherited(app) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/flame/application.rb', line 16

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, &block) ⇒ Object



47
48
49
# File 'lib/flame/application.rb', line 47

def self.mount(ctrl, path = nil, &block)
	router.add_controller(ctrl, path, block)
end

.routerObject

Router for routing



56
57
58
# File 'lib/flame/application.rb', line 56

def self.router
	@router ||= Flame::Router.new(self)
end

Instance Method Details

#call(env) ⇒ Object

Init function



37
38
39
40
# File 'lib/flame/application.rb', line 37

def call(env)
	@app.call(env) if @app.respond_to? :call
	Flame::Dispatcher.new(self, env).run!
end

#configObject

Framework configuration



12
13
14
# File 'lib/flame/application.rb', line 12

def config
	self.class.config
end

#routerObject



60
61
62
# File 'lib/flame/application.rb', line 60

def router
	self.class.router
end