Class: ActionAuthorization::Resource

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, actor, *resources, **options) ⇒ Resource

Returns a new instance of Resource.



5
6
7
8
9
10
# File 'lib/authorizer/resource.rb', line 5

def initialize(action, actor, *resources, **options)
    @action = action
    @actor = actor
    @resources = resources
    @options = options
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



3
4
5
# File 'lib/authorizer/resource.rb', line 3

def action
  @action
end

#actorObject (readonly)

Returns the value of attribute actor.



3
4
5
# File 'lib/authorizer/resource.rb', line 3

def actor
  @actor
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/authorizer/resource.rb', line 3

def options
  @options
end

#resourcesObject (readonly)

Returns the value of attribute resources.



3
4
5
# File 'lib/authorizer/resource.rb', line 3

def resources
  @resources
end

Instance Method Details

#getObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/authorizer/resource.rb', line 12

def get
  return @resources if @resources.nil?
  return @resources if @resources.length == 0
  
  behavior = @options[:behavior]
  if !behavior
      behavior = :filter
  end
  
  case behavior
  when :allow_all
      collect_permitted(return_res: true) {|results| results.length > 0}
  when :deny_all
      collect_permitted {|results| results.length == @resources.length}
  when :filter
      collect_permitted {|results| results.length > 0}
  end
end