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
20
21
22
23
# 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
  if options[:dependencies]
    options[:dependencies].each do |dependency|
      add_dependency(dependency)
    end
  end
  if options[:actions]
    options[:actions].each do |action|
      add_action(action)
    end
  end
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


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

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

#add_action(action) ⇒ Object

Add an access right action


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

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

#add_dependency(right) ⇒ Object

Add an access right dependency


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

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

#human_interaction_nameObject


49
50
51
# File 'lib/ekylibre/access/right.rb', line 49

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

#human_resource_nameObject


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

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

#nameObject

Unique name of the right


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

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