Class: Goz::User
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Goz::User
- Defined in:
- lib/goz/user.rb,
lib/goz/user/base.rb,
lib/goz/user/ldap.rb,
lib/goz/user/test_case.rb,
lib/goz/user/etc_passwd.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Base, EtcPasswd, LDAP, TestCase
Constant Summary collapse
- ATTRIBUTES =
[ :email, :identifier, :klass, :login, :name ]
- TAG =
self.name
- @@api =
XXX
Goz::User
Class Method Summary collapse
-
.api(klass = nil, configuration = {}) ⇒ Object
TODO.
-
.find_by_identifier(identifier) ⇒ Object
Find Goz::User by identifier or return
nil
. -
.find_by_login(login) ⇒ Object
Find Goz::User by login or return
nil
.
Instance Method Summary collapse
-
#initialize(*params) {|_self| ... } ⇒ User
constructor
Initialize new (non-persistent) Goz::User object.
-
#sync(force = false) ⇒ Object
Synchronize user with external data sources (if relevant).
- #to_hash ⇒ Object
-
#validate ⇒ Object
Perform model valiations.
Constructor Details
#initialize(*params) {|_self| ... } ⇒ User
Initialize new (non-persistent) Goz::User object
69 70 71 72 73 |
# File 'lib/goz/user.rb', line 69 def initialize( *params ) super yield self if block_given? self end |
Class Method Details
.api(klass = nil, configuration = {}) ⇒ Object
TODO
78 79 80 81 82 83 84 85 86 |
# File 'lib/goz/user.rb', line 78 def self.api( klass = nil, configuration = {} ) return @@api if klass.nil? Goz::Logger.info TAG, "changing api from #{@@api} to #{klass}" klass_name = klass.kind_of?(String) ? klass : klass.name require klass_name.underscore klass = klass.constantize if klass.kind_of?(String) klass.configuration configuration @@api = klass end |
.find_by_identifier(identifier) ⇒ Object
Find Goz::User by identifier or return nil
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/goz/user.rb', line 91 def self.find_by_identifier(identifier) Goz::Logger.debug TAG, "find_by_identifier( identifier=#{identifier} )" u = self.find :identifier => identifier return u unless u.nil? return nil if Goz::User == self.api u = self.api.find_by_identifier identifier return nil if u.nil? begin return self.find_or_create u.to_hash rescue => e Goz::Logger.error TAG, "find_by_identifier( identifier=#{identifier} ) => #{ e.to_s }" end return nil end |
.find_by_login(login) ⇒ Object
Find Goz::User by login or return nil
109 110 111 112 113 114 115 116 117 |
# File 'lib/goz/user.rb', line 109 def self.find_by_login(login) Goz::Logger.debug TAG, "find_by_login( login=#{login} )" u = self.find :login => login return u unless u.nil? return nil if Goz::User == self.api u = self.api.find_by_login login return nil if u.nil? return self.find_or_create u.to_hash end |
Instance Method Details
#sync(force = false) ⇒ Object
Synchronize user with external data sources (if relevant).
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/goz/user.rb', line 122 def sync(force = false) Goz::Logger.debug TAG, "#{self.login} - #sync( force=#{force} )" if sync_user && sync_groups && sync_memberships self.synchronized_at = Time.now self.save Goz::Event.user_sync(self) return true end false end |
#to_hash ⇒ Object
133 134 135 |
# File 'lib/goz/user.rb', line 133 def to_hash Hash[ ATTRIBUTES.map { |k| [ k, self[k] ] } ] end |
#validate ⇒ Object
Perform model valiations.
140 141 142 143 144 145 |
# File 'lib/goz/user.rb', line 140 def validate super validates_presence [ :email, :identifier, :klass, :login, :name ] validates_type Time, [ :created_at, :modified_at, :synchronized_at ] validates_unique [ :email, :identifier, :login ] end |