Class: Flame::Application
- Inherits:
-
Object
- Object
- Flame::Application
- Extended by:
- Memery
- Defined in:
- lib/flame/application.rb
Overview
Core class, like Framework::Application
Class Method Summary collapse
-
.call(env) ⇒ Object
Make available ‘run Application` without
.newforrackup. -
.inherited(app) ⇒ Object
Remember root directory when inherited.
-
.path_to(ctrl, action = :index, args = {}) ⇒ String
Build a path to the given controller and action.
-
.require_dirs(dirs, ignore: []) ⇒ Object
Require project directories, exclude executable files ).
-
.router ⇒ Object
Router for routing.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Request receiving method.
-
#initialize(app = nil) ⇒ Application
constructor
A new instance of Application.
Constructor Details
#initialize(app = nil) ⇒ Application
Returns a new instance of Application.
132 133 134 |
# File 'lib/flame/application.rb', line 132 def initialize(app = nil) @app = app end |
Class Method Details
.call(env) ⇒ Object
Make available ‘run Application` without .new for rackup
46 47 48 49 |
# File 'lib/flame/application.rb', line 46 def call(env) @app ||= new @app.call env end |
.inherited(app) ⇒ Object
Remember root directory when inherited
15 16 17 18 |
# File 'lib/flame/application.rb', line 15 def inherited(app) super app.root_dir = File.dirname caller(2..2).first.split(':')[0] end |
.path_to(ctrl, action = :index, args = {}) ⇒ String
Build a path to the given controller and action
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/flame/application.rb', line 64 def path_to(ctrl, action = :index, args = {}) path = router.path_of(ctrl, action) raise Errors::RouteNotFoundError.new(ctrl, action) unless path args = args.deep_dup path = path.assign_arguments(args) path = '/' if path.empty? query = Rack::Utils.build_nested_query args unless args.empty? Addressable::URI.new(path: path, query: query).to_s end |
.require_dirs(dirs, ignore: []) ⇒ Object
Require project directories, exclude executable files
)
39 40 41 42 43 |
# File 'lib/flame/application.rb', line 39 def require_dirs(dirs, ignore: []) dirs.each do |dir| require_dir File.join(root_dir, dir), ignore: ignore end end |
.router ⇒ Object
Router for routing
25 26 27 |
# File 'lib/flame/application.rb', line 25 memoize def router Flame::Router.new(self) end |
Instance Method Details
#call(env) ⇒ Object
Request receiving method
137 138 139 140 |
# File 'lib/flame/application.rb', line 137 def call(env) @app.call(env) if @app.respond_to? :call Flame::Dispatcher.new(self.class, env).run! end |