Class: YesApp
- Inherits:
-
Object
- Object
- YesApp
- Defined in:
- lib/yes_app.rb
Class Attribute Summary collapse
-
.assets ⇒ Object
Returns the value of attribute assets.
-
.middleware ⇒ Object
Returns the value of attribute middleware.
-
.route_class ⇒ Object
Returns the value of attribute route_class.
- .routes(class_name = :Routes) ⇒ Object
Class Method Summary collapse
- .app ⇒ Object
- .build_rack_app ⇒ Object
- .bundle_static_files ⇒ Object
- .call(env) ⇒ Object
- .css(arr) ⇒ Object
- .default_session_cookie ⇒ Object
- .development? ⇒ Boolean
- .freeze ⇒ Object
- .js(arr) ⇒ Object
- .logger(logger_class, params: true, database: true) ⇒ Object
- .migrate ⇒ Object
- .migrations(dir) ⇒ Object
- .path(class_name, method_name, params = {}) ⇒ Object
- .paths ⇒ Object
- .production? ⇒ Boolean
- .rollback(step) ⇒ Object
- .test? ⇒ Boolean
- .use(middleware, *args) ⇒ Object
Class Attribute Details
.assets ⇒ Object
Returns the value of attribute assets.
5 6 7 |
# File 'lib/yes_app.rb', line 5 def assets @assets end |
.middleware ⇒ Object
Returns the value of attribute middleware.
5 6 7 |
# File 'lib/yes_app.rb', line 5 def middleware @middleware end |
.route_class ⇒ Object
Returns the value of attribute route_class.
5 6 7 |
# File 'lib/yes_app.rb', line 5 def route_class @route_class end |
.routes(class_name = :Routes) ⇒ Object
104 105 106 107 |
# File 'lib/yes_app.rb', line 104 def routes(class_name = :Routes) @route_class = Object.const_get(class_name) @routes ||= @route_class.routes end |
Class Method Details
.app ⇒ Object
13 14 15 |
# File 'lib/yes_app.rb', line 13 def app @app || build_rack_app end |
.build_rack_app ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/yes_app.rb', line 17 def build_rack_app builder = Rack::Builder.new middleware&.each do |m, args| m.logger = @logger if m.respond_to?(:logger=) builder.use(m, *args) end builder.use Yescode::RequestCache::Middleware Yescode::Router.assets = @assets builder.run Yescode::Router.new(@routes) @app = builder.to_app end |
.bundle_static_files ⇒ Object
62 63 64 65 |
# File 'lib/yes_app.rb', line 62 def bundle_static_files @assets ||= Yescode::Assets.new @assets.compile_assets end |
.call(env) ⇒ Object
42 43 44 |
# File 'lib/yes_app.rb', line 42 def call(env) app.call(env) end |
.css(arr) ⇒ Object
52 53 54 55 |
# File 'lib/yes_app.rb', line 52 def css(arr) @assets ||= Yescode::Assets.new @assets.css(arr) end |
.default_session_cookie ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/yes_app.rb', line 93 def { path: "/", expire_after: 2_592_000, secret: ENV["SECRET"], http_only: true, same_site: :strict, secure: production? } end |
.development? ⇒ Boolean
81 82 83 |
# File 'lib/yes_app.rb', line 81 def development? Yescode::Env.development? end |
.freeze ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/yes_app.rb', line 33 def freeze build_rack_app @app.freeze @middleware.freeze @assets.freeze super end |
.js(arr) ⇒ Object
57 58 59 60 |
# File 'lib/yes_app.rb', line 57 def js(arr) @assets ||= Yescode::Assets.new @assets.js(arr) end |
.logger(logger_class, params: true, database: true) ⇒ Object
46 47 48 49 50 |
# File 'lib/yes_app.rb', line 46 def logger(logger_class, params: true, database: true) @logger = logger_class Yescode::Database.logger = logger_class if database Yescode::Router.logger = logger_class if params end |
.migrate ⇒ Object
71 72 73 74 |
# File 'lib/yes_app.rb', line 71 def migrate Yescode::Database.logger = YesLogger.new($stdout) Yescode::Database.migrate(@migrations || Dir["./db/migrations/*.sql"]) end |
.migrations(dir) ⇒ Object
67 68 69 |
# File 'lib/yes_app.rb', line 67 def migrations(dir) @migrations ||= Dir[dir] end |
.path(class_name, method_name, params = {}) ⇒ Object
113 114 115 |
# File 'lib/yes_app.rb', line 113 def path(class_name, method_name, params = {}) @route_class.path(class_name, method_name, params) end |
.paths ⇒ Object
109 110 111 |
# File 'lib/yes_app.rb', line 109 def paths @paths ||= @route_class.paths end |
.production? ⇒ Boolean
89 90 91 |
# File 'lib/yes_app.rb', line 89 def production? Yescode::Env.production? end |
.rollback(step) ⇒ Object
76 77 78 79 |
# File 'lib/yes_app.rb', line 76 def rollback(step) Yescode::Database.logger = YesLogger.new($stdout) Yescode::Database.rollback_schema(@migrations || Dir["./db/migrations/*.sql"], step:) end |
.use(middleware, *args) ⇒ Object
8 9 10 11 |
# File 'lib/yes_app.rb', line 8 def use(middleware, *args) @middleware ||= [] @middleware << [middleware, args] end |