Class: Consul::Guard

Inherits:
Object
  • Object
show all
Defined in:
lib/consul/guard.rb

Defined Under Namespace

Classes: ActionMap

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Guard

Returns a new instance of Guard.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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

Instance Method Details

#direct_access_methodObject



78
79
80
# File 'lib/consul/guard.rb', line 78

def direct_access_method
  @options[:as]
end

#ensure!(controller, action_name) ⇒ Object



70
71
72
# 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_optionsObject



74
75
76
# File 'lib/consul/guard.rb', line 74

def filter_options
  @options.slice(:except, :only)
end

#power_value(controller, action_name) ⇒ Object



66
67
68
# File 'lib/consul/guard.rb', line 66

def power_value(controller, action_name)
  repository(controller).send(*power_name_with_context(controller, action_name))
end