lib/consul/controller.rb in consul-0.3.0 vs lib/consul/controller.rb in consul-0.4.0
- old
+ new
@@ -67,30 +67,37 @@
# Store arguments for testing
@consul_power_args = args
before_filter :check_power, filter_options
- private
-
- define_method :check_power do
- send(power_method).include!(power_method_for_action)
- end
-
- define_method direct_access_method do
- send(power_method).send(power_method_for_action)
- end if direct_access_method
-
- define_method :power_method_for_action do
+ singleton_class.send(:define_method, :power_name_for_action) do |action_name|
+ action_name = action_name.to_s
key = actions_map.keys.detect do |actions|
Array(actions).collect(&:to_s).include?(action_name)
end
if key
actions_map[key]
elsif default_power
default_power
else
raise Consul::UnmappedAction, "Could not map the action ##{action_name} to a power"
end
+ end
+
+ private
+
+ define_method :check_power do
+ send(power_method).include!(power_name_for_current_action)
+ end
+
+ if direct_access_method
+ define_method direct_access_method do
+ send(power_method).send(power_name_for_current_action)
+ end
+ end
+
+ define_method :power_name_for_current_action do
+ self.class.power_name_for_action(action_name)
end
end
end