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.



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

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.



32
33
34
35
# File 'lib/ehsso/person.rb', line 32

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.



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

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



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

def first_name
  @first_name
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/ehsso/person.rb', line 3

def id
  @id
end

#last_error_messageObject

Returns the value of attribute last_error_message.



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

def last_error_message
  @last_error_message
end

#last_nameObject

Returns the value of attribute last_name.



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

def last_name
  @last_name
end

#module_keyObject

Returns the value of attribute module_key.



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

def module_key
  @module_key
end

#module_nameObject

Returns the value of attribute module_name.



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

def module_name
  @module_name
end

#referenceObject

Returns the value of attribute reference.



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

def reference
  @reference
end

#rolesObject

Returns the value of attribute roles.



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

def roles
  @roles
end

Class Method Details

.parse_from_request_header(header = {}) ⇒ Object



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

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

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

Instance Method Details

#fetchObject



71
72
73
# File 'lib/ehsso/person.rb', line 71

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

#fetch_or_createObject



75
76
77
# File 'lib/ehsso/person.rb', line 75

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

#full_nameObject



41
42
43
44
# File 'lib/ehsso/person.rb', line 41

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

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/ehsso/person.rb', line 37

def respond_to_missing?(method)
  true if method[-1] == "?"
end

#valid?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ehsso/person.rb', line 27

def valid?
  @last_error_message.nil?
end