Class: Users::Privilege

Inherits:
Object show all
Defined in:
lib/users/privilege.rb

Overview

Access control mechanism entailing unique identifier describing the prvilege and optionally the id of the entity which it applies to.

Operations may require privileges to invoke and users may be assigned privileges.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Privilege

Privilege initializer

Options Hash (args):

  • :id,'id' (String)

    id to assign to the privilege

  • :entity_id,'entity_id' (String)

    entity_id to assign to the privilege


27
28
29
# File 'lib/users/privilege.rb', line 27

def initialize(args = {})
  attr_from_args args, :id => nil, :entity_id => nil
end

Instance Attribute Details

#entity_idObject

Identifier of entity which this privilege applies to


21
22
23
# File 'lib/users/privilege.rb', line 21

def entity_id
  @entity_id
end

#idObject

Identifier of privilege this represents


18
19
20
# File 'lib/users/privilege.rb', line 18

def id
  @id
end

Class Method Details

.json_create(o) ⇒ Object

Create new privilege from json representation


53
54
55
56
# File 'lib/users/privilege.rb', line 53

def self.json_create(o)
  privilege = new(o['data'])
  return privilege
end

Instance Method Details

#==(privilege) ⇒ true, false

Return boolean indicating if local attributes match those of specified privilege


39
40
41
42
# File 'lib/users/privilege.rb', line 39

def ==(privilege)
  privilege.is_a?(Privilege) &&
  @id == privilege.id && @entity_id == privilege.entity_id
end

#to_json(*a) ⇒ Object

Convert privilege to json representation and return it


45
46
47
48
49
50
# File 'lib/users/privilege.rb', line 45

def to_json(*a)
  {
    'json_class' => self.class.name,
    'data'       => {:id => id, :entity_id => entity_id}
  }.to_json(*a)
end

#to_sObject


31
32
33
# File 'lib/users/privilege.rb', line 31

def to_s
  "privilege-#{id}#{entity_id ? ('-' + entity_id) : nil}"
end