Class: MarbleGate::Access

Inherits:
Object
  • Object
show all
Defined in:
lib/marble_gate/access.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, action, *args) ⇒ Access

Returns a new instance of Access.



13
14
15
16
# File 'lib/marble_gate/access.rb', line 13

def initialize(context, action, *args)
  @context, @action = context, action.to_sym
  @args = args
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



11
12
13
# File 'lib/marble_gate/access.rb', line 11

def context
  @context
end

Instance Method Details

#for_authorizer?(model_class) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/marble_gate/access.rb', line 25

def for_authorizer?(model_class)
  cls = auth_class(model_class)
  cls.send(choose_action(cls), *@args)
end

#for_model?(model) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/marble_gate/access.rb', line 18

def for_model?(model)
  return for_authorizer?(model) if model.is_a?(Class)

  obj = auth_class(model.class).new(model)
  obj.send(choose_action(obj), *@args)
end

#userObject



30
31
32
# File 'lib/marble_gate/access.rb', line 30

def user
  context.send(MarbleGate.current_user_method_name)
end