class Consul::Guard
Public Class Methods
new(*args)
click to toggle source
# File lib/consul/guard.rb, line 49 def initialize(*args) args_copy = args.dup @options = args_copy.extract_options! default_power = args_copy.shift # might be nil custom_action_mappings = @options[:map] if @options[:crud] @map = ActionMap.crud(@options[:crud], custom_action_mappings) else @map = ActionMap.new(default_power, custom_action_mappings) end end
Public Instance Methods
direct_access_method()
click to toggle source
# File lib/consul/guard.rb, line 78 def direct_access_method @options[:as] end
ensure!(controller, action_name)
click to toggle source
# File lib/consul/guard.rb, line 70 def ensure!(controller, action_name) repository(controller).include_power!(*power_name_with_context(controller, action_name)) end
filter_options()
click to toggle source
# File lib/consul/guard.rb, line 74 def filter_options @options.slice(:except, :only) end
power_value(controller, action_name)
click to toggle source
# File lib/consul/guard.rb, line 66 def power_value(controller, action_name) repository(controller).send(*power_name_with_context(controller, action_name)) end
Private Instance Methods
context(controller)
click to toggle source
# File lib/consul/guard.rb, line 100 def context(controller) context = [] Array.wrap(@options[:context]).each do |context_method| arg = controller.send(context_method) if arg.nil? raise Consul::MissingContext end context << arg end context end
power_name(action_name)
click to toggle source
# File lib/consul/guard.rb, line 84 def power_name(action_name) @map.power_name(action_name) end
power_name_with_context(controller, action_name)
click to toggle source
# File lib/consul/guard.rb, line 88 def power_name_with_context(controller, action_name) [power_name(action_name), *context(controller)] end
repository(controller)
click to toggle source
# File lib/consul/guard.rb, line 92 def repository(controller) controller.send(repository_method) end
repository_method()
click to toggle source
# File lib/consul/guard.rb, line 96 def repository_method @options[:power] || :current_power end