Class: CanTango::Api::Ability::Relation

Inherits:
Object
  • Object
show all
Includes:
CanTango::Adaptor, CanCan::RuleClass
Defined in:
lib/cantango/api/ability/relation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, ability, scope, *models, &block) ⇒ Relation

Returns a new instance of Relation.



12
13
14
15
16
17
18
19
20
# File 'lib/cantango/api/ability/relation.rb', line 12

def initialize attribute, ability, scope, *models, &block
  @attribute = attribute
  @abil = ability
  @scope = scope
  @models = models

  check_models
  use_adaptor! self, user_scope
end

Instance Attribute Details

#abilObject (readonly)

Returns the value of attribute abil.



7
8
9
# File 'lib/cantango/api/ability/relation.rb', line 7

def abil
  @abil
end

#attributeObject (readonly)

Returns the value of attribute attribute.



7
8
9
# File 'lib/cantango/api/ability/relation.rb', line 7

def attribute
  @attribute
end

#modelsObject (readonly)

Returns the value of attribute models.



7
8
9
# File 'lib/cantango/api/ability/relation.rb', line 7

def models
  @models
end

#scopeObject (readonly)

Returns the value of attribute scope.



7
8
9
# File 'lib/cantango/api/ability/relation.rb', line 7

def scope
  @scope
end

Instance Method Details

#can(action) ⇒ Object



24
25
26
27
28
29
# File 'lib/cantango/api/ability/relation.rb', line 24

def can(action)
  models.each do |model|
    rules << rule_class.new(true, action, model, nil, condition_block(model))
  end
  self
end

#cannot(action) ⇒ Object



31
32
33
34
35
36
# File 'lib/cantango/api/ability/relation.rb', line 31

def cannot(action)
  models.each do |model|
    rules << rule_class.new(false, action, model, nil, condition_block(model))
  end
  self
end