Class: Origen::Users::User
Instance Attribute Summary collapse
- #email ⇒ Object
- #name ⇒ Object
-
#role ⇒ Object
readonly
Returns the value of attribute role.
Class Method Summary collapse
Instance Method Summary collapse
- #==(user) ⇒ Object
-
#admin? ⇒ Boolean
Returns true if the user is an admin for the current application.
-
#current? ⇒ Boolean
Returns true if the user is the current user.
- #email_from_rc ⇒ Object
- #id ⇒ Object (also: #core_id)
-
#initialize(*args) ⇒ User
constructor
A new instance of User.
-
#initials ⇒ Object
Returns the user’s initials in lower case.
-
#lookup(default = 'Unknown') ⇒ Object
Fetch user data from the FSL application directory.
-
#method_missing(method, *args, &block) ⇒ Object
Provides methods to access attributes available from LDAP.
-
#name_and_email ⇒ Object
Returns a string like “Stephen McGinty <[email protected]>”.
- #name_from_rc ⇒ Object
-
#raw ⇒ Object
(also: #display)
Prints all raw data available on the given user from the FSL application directory.
- #respond_to?(method) ⇒ Boolean
-
#send(options) ⇒ Object
Send the user an email.
Constructor Details
#initialize(*args) ⇒ User
Returns a new instance of User.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/origen/users/user.rb', line 18 def initialize(*args) if args.last.is_a?(Symbol) @role = args.pop else @role = :user end if args.size == 2 @name = args.first end id = args.pop if id.to_s =~ /(.*)@/ @email = id @id = Regexp.last_match(1) else @id = id end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Provides methods to access attributes available from LDAP
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/origen/users/user.rb', line 129 def method_missing(method, *args, &block) l = Origen.ldap.lookup(self) if l if l.attribute_names.include?(method) l[method] else super end else super end end |
Instance Attribute Details
#email ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/origen/users/user.rb', line 76 def email @email ||= ENV['ORIGEN_EMAIL'] || email_from_rc || begin if Origen.site_config.email_domain "#{id}@#{Origen.site_config.email_domain}" end end end |
#name ⇒ Object
68 69 70 |
# File 'lib/origen/users/user.rb', line 68 def name @name ||= ENV['ORIGEN_NAME'] || name_from_rc || @id end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
7 8 9 |
# File 'lib/origen/users/user.rb', line 7 def role @role end |
Class Method Details
.current ⇒ Object
14 15 16 |
# File 'lib/origen/users/user.rb', line 14 def self.current Origen.current_user end |
.current_user_id ⇒ Object
10 11 12 |
# File 'lib/origen/users/user.rb', line 10 def self.current_user_id `whoami`.strip end |
Instance Method Details
#==(user) ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/origen/users/user.rb', line 118 def ==(user) if user.is_a?(Origen::Users::User) user.id == id elsif user.is_a?(String) user.downcase == id else super end end |
#admin? ⇒ Boolean
Returns true if the user is an admin for the current application
53 54 55 |
# File 'lib/origen/users/user.rb', line 53 def admin? role == :admin end |
#current? ⇒ Boolean
Returns true if the user is the current user
58 59 60 |
# File 'lib/origen/users/user.rb', line 58 def current? id.to_s.downcase == self.class.current_user_id end |
#email_from_rc ⇒ Object
84 85 86 |
# File 'lib/origen/users/user.rb', line 84 def email_from_rc RevisionControl::Git.user_email end |
#id ⇒ Object Also known as: core_id
47 48 49 |
# File 'lib/origen/users/user.rb', line 47 def id @id.to_s.downcase end |
#initials ⇒ Object
Returns the user’s initials in lower case
63 64 65 66 |
# File 'lib/origen/users/user.rb', line 63 def initials initials = name.split(/\s+/).map { |n| n[0].chr }.join('') initials.downcase end |
#lookup(default = 'Unknown') ⇒ Object
Fetch user data from the FSL application directory
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/origen/users/user.rb', line 93 def lookup(default = 'Unknown') data = Origen.ldap.lookup(self) if block_given? if data yield data else default end else data end end |
#name_and_email ⇒ Object
Returns a string like “Stephen McGinty <[email protected]>”
153 154 155 |
# File 'lib/origen/users/user.rb', line 153 def name_and_email "#{name} <#{email}>" end |
#name_from_rc ⇒ Object
72 73 74 |
# File 'lib/origen/users/user.rb', line 72 def name_from_rc RevisionControl::Git.user_name end |
#raw ⇒ Object Also known as: display
Prints all raw data available on the given user from the FSL application directory.
Most of the useful data is already exposed through the available user methods, but if you want to get any of these parameters they can be fetched via the lookup method.
112 113 114 115 |
# File 'lib/origen/users/user.rb', line 112 def raw Origen.ldap.display(self) nil end |