Class: CanTango::Rules::UserRelation

Inherits:
Object
  • Object
show all
Includes:
Adaptor, RuleClass
Defined in:
lib/cantango/rules/user_relation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RuleClass

#rule_class

Methods included from Adaptor

#adaptor_for, #get_adapter, #orm_map, #use_adaptor!

Constructor Details

#initialize(attribute, permit, scope, *models, &block) ⇒ UserRelation

Returns a new instance of UserRelation.



11
12
13
14
15
16
17
18
19
# File 'lib/cantango/rules/user_relation.rb', line 11

def initialize attribute, permit, scope, *models, &block
  @attribute = attribute
  @scope = scope
  @permit = permit
  @models = models

  check_models
  use_adaptor! self, user_scope
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



6
7
8
# File 'lib/cantango/rules/user_relation.rb', line 6

def attribute
  @attribute
end

#modelsObject (readonly)

Returns the value of attribute models.



6
7
8
# File 'lib/cantango/rules/user_relation.rb', line 6

def models
  @models
end

#permitObject (readonly)

Returns the value of attribute permit.



6
7
8
# File 'lib/cantango/rules/user_relation.rb', line 6

def permit
  @permit
end

#scopeObject (readonly)

Returns the value of attribute scope.



6
7
8
# File 'lib/cantango/rules/user_relation.rb', line 6

def scope
  @scope
end

Instance Method Details

#can(action) ⇒ Object



21
22
23
24
25
# File 'lib/cantango/rules/user_relation.rb', line 21

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

#cannot(action) ⇒ Object



27
28
29
30
31
# File 'lib/cantango/rules/user_relation.rb', line 27

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