Class: YesApp

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.assetsObject

Returns the value of attribute assets.



5
6
7
# File 'lib/yes_app.rb', line 5

def assets
  @assets
end

.middlewareObject

Returns the value of attribute middleware.



5
6
7
# File 'lib/yes_app.rb', line 5

def middleware
  @middleware
end

.route_classObject

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

.appObject



13
14
15
# File 'lib/yes_app.rb', line 13

def app
  @app || build_rack_app
end

.build_rack_appObject



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_filesObject



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


93
94
95
96
97
98
99
100
101
102
# File 'lib/yes_app.rb', line 93

def default_session_cookie
  {
    path: "/",
    expire_after: 2_592_000,
    secret: ENV["SECRET"],
    http_only: true,
    same_site: :strict,
    secure: production?
  }
end

.development?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/yes_app.rb', line 81

def development?
  Yescode::Env.development?
end

.freezeObject



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

.migrateObject



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

.pathsObject



109
110
111
# File 'lib/yes_app.rb', line 109

def paths
  @paths ||= @route_class.paths
end

.production?Boolean

Returns:

  • (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

.test?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/yes_app.rb', line 85

def test?
  Yescode::Env.test?
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