Skip to content

Commit

Permalink
register instances instead of crawling ObjectSpace for them
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Bullock committed Feb 22, 2012
1 parent bc1c30a commit 414c8d8
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/stasis.rb
Expand Up @@ -84,6 +84,7 @@ def initialize(root, *args)
# Create plugin instances.
@plugins = Plugin.plugins.collect { |klass| klass.new(self) }

self.class.register_instance(self)
load_controllers
end

Expand Down Expand Up @@ -270,13 +271,22 @@ def render(*only)
collect if render_options[:collect]
end

def self.register_instance(inst)
@instances ||= []
@instances << inst
end

def add_plugin(plugin)
plugin = plugin.new(self)
plugins << plugin
controller._bind_plugin(plugin, :controller_method)
end

# Add a plugin to all existing controller instances. This method should be called by
# all external plugins.
def self.register(plugin)
ObjectSpace.each_object(::Stasis) do |stasis|
plugin = plugin.new(stasis)
stasis.plugins << plugin
stasis.controller._bind_plugin(plugin, :controller_method)
@instances.each do |stasis|
stasis.add_plugin(plugin)
end
end

Expand Down

0 comments on commit 414c8d8

Please sign in to comment.