Module: MarbleGate::BaseMethods

Defined in:
lib/marble_gate/base_methods.rb

Instance Method Summary collapse

Instance Method Details

#authorize!(model = nil, *args) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/marble_gate/base_methods.rb', line 9

def authorize!(model = nil, *args)
  unless model
    raise MarbleGate::MissingModel unless respond_to?(:controller_name)
    model = controller_name.classify.constantize
  end
  raise MarbleGate::AccessDenied unless can?(params[:action], model, *args)
end

#can?(action, model, *args) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/marble_gate/base_methods.rb', line 17

def can?(action, model, *args)
  # p "#{model.class.to_s}Authorizer".constantize
  MarbleGate.access(self, action, *args).for_model?(model)
end

#cannot?(action, model, *args) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/marble_gate/base_methods.rb', line 22

def cannot?(action, model, *args)
  !can?(action, model, *args)
end