Class: IAmICan::ThatAllow

Inherits:
Object
  • Object
show all
Defined in:
lib/i_am_i_can/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records, subject) ⇒ ThatAllow

Returns a new instance of ThatAllow.



17
18
19
20
# File 'lib/i_am_i_can/resource.rb', line 17

def initialize(records, subject)
  self.records = records
  self.subject = subject
end

Instance Attribute Details

#recordsObject

Returns the value of attribute records.



15
16
17
# File 'lib/i_am_i_can/resource.rb', line 15

def records
  @records
end

#subjectObject

Returns the value of attribute subject.



15
16
17
# File 'lib/i_am_i_can/resource.rb', line 15

def subject
  @subject
end

Instance Method Details

#to(pred) ⇒ Object



22
23
24
25
26
27
# File 'lib/i_am_i_can/resource.rb', line 22

def to(pred)
  roles = Configs.take.subject_model._roles
  permissions = Configs.take.role_model._permissions
  allowed_ids = subject.send(roles).send(permissions).where(pred: pred, obj_type: records.name).pluck(:obj_id)
  records.where(id: allowed_ids)
end