Class: Ekylibre::Access::Right

Inherits:
Object
  • Object
show all
Defined in:
lib/ekylibre/access/right.rb

Overview

Right class permit to define which resource is concerned, which interaction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, interaction, options = {}) ⇒ Right

Returns a new instance of Right.


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ekylibre/access/right.rb', line 7

def initialize(resource, interaction, options = {})
  @resource     = resource.to_sym
  @interaction  = interaction.to_sym
  @actions      = []
  @dependencies = []
  @origin = options[:origin] || :unknown
  options[:dependencies].each do |dependency|
    add_dependency(dependency)
  end if options[:dependencies]
  options[:actions].each do |action|
    add_action(action)
  end if options[:actions]
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions


5
6
7
# File 'lib/ekylibre/access/right.rb', line 5

def actions
  @actions
end

#dependenciesObject (readonly)

Returns the value of attribute dependencies


5
6
7
# File 'lib/ekylibre/access/right.rb', line 5

def dependencies
  @dependencies
end

#interactionObject (readonly)

Returns the value of attribute interaction


5
6
7
# File 'lib/ekylibre/access/right.rb', line 5

def interaction
  @interaction
end

#resourceObject (readonly)

Returns the value of attribute resource


5
6
7
# File 'lib/ekylibre/access/right.rb', line 5

def resource
  @resource
end

Instance Method Details

#==(other) ⇒ Object

Equality is based on name


32
33
34
# File 'lib/ekylibre/access/right.rb', line 32

def ==(other)
  name == other.name
end

#add_action(action) ⇒ Object

Add an access right action


22
23
24
# File 'lib/ekylibre/access/right.rb', line 22

def add_action(action)
  @actions << action unless @actions.include? action
end

#add_dependency(right) ⇒ Object

Add an access right dependency


27
28
29
# File 'lib/ekylibre/access/right.rb', line 27

def add_dependency(right)
  @dependencies << right unless @dependencies.include?(right)
end

#human_interaction_nameObject


45
46
47
# File 'lib/ekylibre/access/right.rb', line 45

def human_interaction_name
  Ekylibre::Access.human_interaction_name(@interaction)
end

#human_resource_nameObject


41
42
43
# File 'lib/ekylibre/access/right.rb', line 41

def human_resource_name
  Ekylibre::Access.human_resource_name(@resource)
end

#nameObject

Unique name of the right


37
38
39
# File 'lib/ekylibre/access/right.rb', line 37

def name
  "#{@interaction}-#{@resource}"
end