lib/hanami.rb in hanami-1.1.1 vs lib/hanami.rb in hanami-1.2.0.beta1
- old
+ new
@@ -19,10 +19,11 @@
DEFAULT_PUBLIC_DIRECTORY = 'public'.freeze
# @api private
# @since 0.9.0
@_mutex = Mutex.new
+ @_plugins = Concurrent::Array.new
# Configure Hanami project
#
# Please note that the code for this method is generated by `hanami new`.
#
@@ -73,9 +74,42 @@
def self.configuration
@_mutex.synchronize do
raise "Hanami not configured" unless defined?(@_configuration)
@_configuration
end
+ end
+
+ # Configure a plugin
+ #
+ # @see Hanami.configure
+ #
+ # @since x.x.x
+ def self.plugin(&blk)
+ @_plugins << blk
+ end
+
+ # Plugins registry
+ #
+ # NOTE: We can't use `Components` registry.
+ #
+ # Plugins are loaded when Bundler requires `Gemfile` gems.
+ # During this phase the `Components` that we can resolve are erased by the
+ # first incoming request in development.
+ # They are erased by a workaround that we had to put in place in `Hanami.boot`.
+ # This workaround is `Components.release` and it was introduced because
+ # `shotgun` failed to reload components, so we have to release for each
+ # incoming request.
+ # After the `Components` registry is cleared up, Hanami is able to resolve all
+ # the components from scratch.
+ #
+ # When we'll switch to `hanami-reloader` for development, we can remove
+ # `Components.release` and we'll be able to store plugins in `Components` and
+ # remove `Hanami.plugins` as well.
+ #
+ # @since x.x.x
+ # @api private
+ def self.plugins
+ @_plugins
end
# Boot your Hanami project
#
# NOTE: In case this is invoked many times, it guarantees that the boot