20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/protector/cancan/ability.rb', line 20
def self.included(mod)
mod.class_eval do
def can_with_protector?(action, entity_set, *)
if entity_set.is_a? Hash
entity = entity_set.values.first
else
entity = entity_set
end
if entity.respond_to?(:restrict!) && @protector_subject_defined
@protector_models ||= Set.new
model = entity
model = model.class unless model.is_a?(Class)
unless @protector_models.include?(model)
meta = entity.is_a?(Class) ? entity.protector_meta.evaluate(@protector_subject)
: entity.protector_meta(@protector_subject)
meta.access.each do |action, fields|
action = :read if action == :view can action, model unless fields.empty?
end
can :destroy, model if meta.destroyable?
@protector_models << model
end
end
can_without_protector? action, entity_set, *
end
alias_method_chain :can?, :protector
end
end
|