Module: Rightable

Extended by:
ActiveSupport::Concern
Included in:
Role, User
Defined in:
app/models/concerns/rightable.rb

Instance Method Summary collapse

Instance Method Details

#each_rightObject

Browse all resource/action pair


31
32
33
34
35
36
37
38
# File 'app/models/concerns/rightable.rb', line 31

def each_right
  return unless rights
  rights.each do |resource, actions|
    actions.each do |action|
      yield resource, action
    end
  end
end

#resource_actionsObject

Returns rights as a list of “action-resource” strings


22
23
24
25
26
27
28
# File 'app/models/concerns/rightable.rb', line 22

def resource_actions
  array = []
  each_right do |resource, action|
    array << action + '-' + resource
  end
  array
end

#right_exist?(action, resource) ⇒ Boolean

Returns:

  • (Boolean)

40
41
42
43
# File 'app/models/concerns/rightable.rb', line 40

def right_exist?(action, resource)
  return false unless rights && rights[resource.to_s]
  rights[resource.to_s].include?(action.to_s)
end

#rights_arrayObject

Returns rights as a list of “resource-action” strings


13
14
15
16
17
18
19
# File 'app/models/concerns/rightable.rb', line 13

def rights_array
  array = []
  each_right do |resource, action|
    array << resource + '-' + action
  end
  array
end