Class: Ehsso::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/ehsso/person.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Person

Returns a new instance of Person.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ehsso/person.rb', line 16

def initialize(args={})
  @id               = args[:id]
  @reference        = args[:reference]
  @first_name       = args[:first_name]
  @last_name        = args[:last_name]
  @email            = args[:email]

  # for this purpose we deal with only one module
  @module_key       = args[:module_key]
  @module_name      = args[:module_name]
  @roles            = args[:roles].is_a?(Array) ? args[:roles] : []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object

you can use methods like guest?, user?, operator?, administrator? etc.



34
35
36
37
# File 'lib/ehsso/person.rb', line 34

def method_missing(method)
  raise "Method [#{method}] not defined or allowed" unless method[-1] == '?'
  @roles.include?(method[0..-2].upcase)
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



9
10
11
# File 'lib/ehsso/person.rb', line 9

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



7
8
9
# File 'lib/ehsso/person.rb', line 7

def first_name
  @first_name
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/ehsso/person.rb', line 5

def id
  @id
end

#last_error_messageObject

Returns the value of attribute last_error_message.



14
15
16
# File 'lib/ehsso/person.rb', line 14

def last_error_message
  @last_error_message
end

#last_nameObject

Returns the value of attribute last_name.



8
9
10
# File 'lib/ehsso/person.rb', line 8

def last_name
  @last_name
end

#module_keyObject

Returns the value of attribute module_key.



10
11
12
# File 'lib/ehsso/person.rb', line 10

def module_key
  @module_key
end

#module_nameObject

Returns the value of attribute module_name.



11
12
13
# File 'lib/ehsso/person.rb', line 11

def module_name
  @module_name
end

#referenceObject

Returns the value of attribute reference.



6
7
8
# File 'lib/ehsso/person.rb', line 6

def reference
  @reference
end

#rolesObject

Returns the value of attribute roles.



12
13
14
# File 'lib/ehsso/person.rb', line 12

def roles
  @roles
end

Class Method Details

.parse_from_request_header(header = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ehsso/person.rb', line 44

def self.parse_from_request_header(header={})
  person = Ehsso::Person.new()

  # reference (mandatory)
  if header['HTTP_NIBR521'].nil? || header['HTTP_NIBR521'].size == 0
    person.last_error_message = "Unable to extract HTTP_NIBR* porperties from request header"
    return person
  end

  person.reference = header['HTTP_NIBR521'].downcase

  [
    [:first_name=, 'HTTP_NIBRFIRST'],
    [:last_name=, 'HTTP_NIBRLAST'],
    [:email=, 'HTTP_NIBREMAIL']
  ].each do |method, key|
    person.send(method, header[key]) if header[key] && header[key].strip.size > 0
  end

  return person
rescue => e
  person.last_error_message = e.to_s
  return person
end

Instance Method Details

#fetchObject



69
70
71
# File 'lib/ehsso/person.rb', line 69

def fetch
  handle_service_call(action: 'people.modules.roles')
end

#fetch_or_createObject



73
74
75
# File 'lib/ehsso/person.rb', line 73

def fetch_or_create
  handle_service_call(action: 'people_with_guest_registration_if_missing.modules.roles')
end

#full_nameObject



39
40
41
42
# File 'lib/ehsso/person.rb', line 39

def full_name
  return nil if self.last_name.nil? && self.first_name.nil?
  [self.last_name, self.first_name].compact.join(" ")
end

#valid?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ehsso/person.rb', line 29

def valid?
  @last_error_message.nil?
end