lib/hanami/application.rb in hanami-0.7.0 vs lib/hanami/application.rb in hanami-0.7.1

- old
+ new

@@ -38,46 +38,10 @@ synchronize do applications.add(base) end end - # Registry of Hanami applications in the current Ruby process - # - # @return [Set] a set of all the registered applications - # - # @since 0.2.0 - # @api private - def self.applications - synchronize do - @@applications ||= Set.new - end - end - - # Configure the application. - # It yields the given block in the context of the configuration - # - # @param environment [Symbol,nil] the configuration environment name - # @param blk [Proc] the configuration block - # - # @since 0.1.0 - # - # @see Hanami::Configuration - # - # @example - # require 'hanami' - # - # module Bookshelf - # Application < Hanami::Application - # configure do - # # ... - # end - # end - # end - def self.configure(environment = nil, &blk) - configuration.configure(environment, &blk) - end - # Return the routes for this application # # @return [Hanami::Router] a route set # # @since 0.1.0 @@ -109,82 +73,10 @@ def initialize(options = {}) self.class.configuration.path_prefix options[:path_prefix] self.class.load!(self) end - # Eager load the application configuration, by activating the framework - # duplication mechanisms. - # - # @param application [Hanami::Application, Class<Hanami::Application>] - # @return void - # - # @since 0.1.1 - # - # @example - # require 'hanami' - # - # module OneFile - # class Application < Hanami::Application - # configure do - # routes do - # get '/', to: 'dashboard#index' - # end - # end - # - # load! - # end - # - # module Controllers::Dashboard - # class Index - # include OneFile::Action - # - # def call(params) - # self.body = 'Hello!' - # end - # end - # end - # end - def self.load!(application = self) - Hanami::Loader.new(application).load! - end - - # Preload all the registered applications, by yielding their configurations - # and preparing the frameworks. - # - # This is useful for testing suites, where we want to make Hanami frameworks - # ready, but not preload applications code. - # - # This allows to test components such as views or actions in isolation and - # to have faster boot times. - # - # @return [void] - # - # @since 0.2.0 - def self.preload! - synchronize do - applications.each(&:load!) - end - - nil - end - - # Full preload for all the registered applications. - # - # This is useful in console where we want all the application code available. - # - # @return [void] - # - # @since 0.2.1 - # @api private - def self.preload_applications! - synchronize do - applications.each { |app| app.new } - end - - nil - end - # Return the configuration for this application # # @since 0.1.0 # @api private # @@ -227,18 +119,129 @@ # @see Hanami::Middleware def middleware @middleware ||= configuration.middleware end - private + class << self - # Yields the given block in a critical section - # - # @since 0.2.0 - # @api private - def self.synchronize - Mutex.new.synchronize do - yield + # Registry of Hanami applications in the current Ruby process + # + # @return [Set] a set of all the registered applications + # + # @since 0.2.0 + # @api private + def applications + synchronize do + @@applications ||= Set.new + end + end + + # Configure the application. + # It yields the given block in the context of the configuration + # + # @param environment [Symbol,nil] the configuration environment name + # @param blk [Proc] the configuration block + # + # @since 0.1.0 + # + # @see Hanami::Configuration + # + # @example + # require 'hanami' + # + # module Bookshelf + # Application < Hanami::Application + # configure do + # # ... + # end + # end + # end + def configure(environment = nil, &blk) + configuration.configure(environment, &blk) + end + + # Eager load the application configuration, by activating the framework + # duplication mechanisms. + # + # @param application [Hanami::Application, Class<Hanami::Application>] + # @return void + # + # @since 0.1.1 + # + # @example + # require 'hanami' + # + # module OneFile + # class Application < Hanami::Application + # configure do + # routes do + # get '/', to: 'dashboard#index' + # end + # end + # + # load! + # end + # + # module Controllers::Dashboard + # class Index + # include OneFile::Action + # + # def call(params) + # self.body = 'Hello!' + # end + # end + # end + # end + def load!(application = self) + Hanami::Loader.new(application).load! + end + + # Preload all the registered applications, by yielding their configurations + # and preparing the frameworks. + # + # This is useful for testing suites, where we want to make Hanami frameworks + # ready, but not preload applications code. + # + # This allows to test components such as views or actions in isolation and + # to have faster boot times. + # + # @return [void] + # + # @since 0.2.0 + def preload! + synchronize do + applications.each(&:load!) + end + + nil + end + + # Full preload for all the registered applications. + # + # This is useful in console where we want all the application code available. + # + # @return [void] + # + # @since 0.2.1 + # @api private + def preload_applications! + synchronize do + applications.each { |app| app.new } + end + + nil + end + + private + + # Yields the given block in a critical section + # + # @since 0.2.0 + # @api private + def synchronize + Mutex.new.synchronize do + yield + end end end end end