lib/hanami.rb in hanami-0.8.0 vs lib/hanami.rb in hanami-0.9.0
- old
+ new
@@ -1,19 +1,107 @@
-require 'hanami/version'
-require 'hanami/application'
-require 'hanami/container'
-require 'hanami/environment'
-require 'hanami/server'
+require 'thread'
# A complete web framework for Ruby
#
# @since 0.1.0
#
# @see http://hanamirb.org
module Hanami
+ require 'hanami/version'
+ require 'hanami/frameworks'
+ require 'hanami/environment'
+ require 'hanami/app'
+ require 'hanami/application'
+ require 'hanami/components'
+ require 'hanami/configuration'
+
+ # @api private
+ # @since 0.6.0
DEFAULT_PUBLIC_DIRECTORY = 'public'.freeze
+ # @api private
+ # @since 0.9.0
+ @_mutex = Mutex.new
+
+ # Configure Hanami project
+ #
+ # Please note that the code for this method is generated by `hanami new`.
+ #
+ # @param blk [Proc] the configuration block
+ #
+ # @since 0.9.0
+ #
+ # @example
+ # # config/environment.rb
+ #
+ # # ...
+ #
+ # Hanami.configure do
+ # mount Admin::Application, at: "/admin"
+ # mount Web::Application, at: "/"
+ #
+ # model do
+ # adapter :sql, ENV['DATABASE_URL']
+ #
+ # migrations "db/migrations"
+ # schema "db/schema.sql"
+ # end
+ #
+ # mailer do
+ # root "lib/bookshelf/mailers"
+ #
+ # delivery do
+ # development :test
+ # test :test
+ # # production :smtp, address: ENV['SMTP_HOST'], port: 1025
+ # end
+ # end
+ # end
+ def self.configure(&blk)
+ @_mutex.synchronize do
+ @_configuration = Hanami::Configuration.new(&blk)
+ end
+ end
+
+ # Hanami configuration
+ #
+ # @return [Hanami::Configuration] the configuration
+ #
+ # @see Hanami.configure
+ #
+ # @since 0.9.0
+ # @api private
+ def self.configuration
+ @_mutex.synchronize do
+ raise "Hanami not configured" unless defined?(@_configuration)
+ @_configuration
+ end
+ end
+
+ # Boot Hanami project
+ #
+ # @since 0.9.0
+ # @api private
+ def self.boot
+ Components.resolve('all')
+ end
+
+ # Main application that mounts many Rack and/or Hanami applications.
+ #
+ # This is used as integration point for:
+ #
+ # * `config.ru` (`run Hanami.app`)
+ # * Feature tests (`Capybara.app = Hanami.app`)
+ #
+ # @return [Hanami::App] the app
+ #
+ # @since 0.9.0
+ # @api private
+ def self.app
+ App.new(configuration, environment)
+ end
+
# Return root of the project (top level directory).
#
# @return [Pathname] root path
#
# @since 0.3.2
@@ -22,10 +110,19 @@
# Hanami.root # => #<Pathname:/Users/luca/Code/bookshelf>
def self.root
environment.root
end
+ # Project public directory
+ #
+ # @return [Pathname] public directory
+ #
+ # @since 0.6.0
+ # @api private
+ #
+ # @example
+ # Hanami.public_directory # => #<Pathname:/Users/luca/Code/bookshelf/public>
def self.public_directory
root.join(DEFAULT_PUBLIC_DIRECTORY)
end
# Return the current environment
@@ -68,15 +165,17 @@
# Hanami.env?(:production, :staging) # => false
def self.env?(*names)
environment.environment?(*names)
end
- # Return environment
+ # Current environment
#
# @return [Hanami::Environment] environment
#
# @api private
# @since 0.3.2
def self.environment
- Environment.new
+ Components.resolved('environment') do
+ Environment.new
+ end
end
end