lib/consul/controller.rb in consul-0.2.1 vs lib/consul/controller.rb in consul-0.2.2

- old
+ new

@@ -2,12 +2,21 @@ module Controller def self.included(base) base.send :include, InstanceMethods base.send :extend, ClassMethods + if ensure_power_initializer_present? + base.before_filter :ensure_power_initializer_present + end end + private + + def self.ensure_power_initializer_present? + ['development', 'test', 'cucumber', 'in_memory'].include?(Rails.env) + end + module ClassMethods def current_power_initializer @current_power_initializer || (superclass.respond_to?(:current_power_initializer) && superclass.current_power_initializer) end @@ -96,9 +105,15 @@ @current_power_class.current = power action.call ensure if @current_power_class @current_power_class.current = nil + end + end + + def ensure_power_initializer_present + unless self.class.current_power_initializer.present? + raise Consul::UnreachablePower, 'You included Consul::Controller but forgot to define a power using current_power do ... end' end end end