Class: Jun::Application

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inherited(subclass) ⇒ Object



5
6
7
8
# File 'lib/jun/application.rb', line 5

def self.inherited(subclass)
  super
  Jun.app_class = subclass
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
# File 'lib/jun/application.rb', line 10

def call(env)
  routes.call(env)
end

#initialize!Boolean

Initializes the Jun application.

Returns:

  • (Boolean)

    true if successful, false if already initialized.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jun/application.rb', line 20

def initialize!
  return false if initialized? || Jun.application.nil?

  # Add app/* directories to autoload paths.
  Jun::ActiveSupport::Dependencies.autoload_paths += Jun.root.join("app").children

  # Set up routes and make its helpers available to controllers & views.
  require Jun.root.join("config/routes.rb")
  url_helpers = Jun.application.routes.url_helpers
  Jun::ActionController::Base.include(url_helpers)
  Jun::ActionView::Base.include(url_helpers)

  # Include all helpers in app/helpers directory.
  Dir.glob(Jun.root.join("app/helpers/**/*.rb")).each do |filepath|
    helper_class_name = File.basename(filepath, ".rb").camelize
    helper_class = Object.const_get(helper_class_name)

    Jun::ActionView::Base.include(helper_class)
  end

  @initialized = true
end

#initialized?Boolean

Checks whether the Jun application has been initialized.

Returns:

  • (Boolean)

    true if initialized, false if not initialized.



45
46
47
# File 'lib/jun/application.rb', line 45

def initialized?
  !!@initialized
end

#routesObject



14
15
16
# File 'lib/jun/application.rb', line 14

def routes
  @routes ||= Jun::ActionDispatch::Routing::RouteSet.new
end