Class: Goz::Group
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Goz::Group
- Defined in:
- lib/goz/group.rb,
lib/goz/group/base.rb,
lib/goz/group/grouper.rb,
lib/goz/group/etc_group.rb,
lib/goz/group/test_case.rb,
lib/goz/group/grouper/stemmed_groups.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Base, EtcGroup, Grouper, TestCase
Constant Summary collapse
- ATTRIBUTES =
[ :display_name, :identifier, :klass, :name ]
- TAG =
self.name
- @@api =
Goz::Group
Class Method Summary collapse
-
.admin(user) ⇒ Object
Return groups where user is an admin.
-
.after_add_service(g, s) ⇒ Object
TODO DRY w/ “Service”.
-
.after_remove_service(g, s) ⇒ Object
TODO DRY w/ “Service”.
-
.api(klass = nil, configuration = {}) ⇒ Object
TODO.
-
.find_by_name(name) ⇒ Object
Find Goz::Group by name or return
nil
. -
.member(user) ⇒ Object
Return groups where user is a member.
Instance Method Summary collapse
-
#sync(force = false) ⇒ Object
Synchronize group with external data sources (if relevant).
-
#sync_service(service, force = false) ⇒ Object
Synchronize group service with external data soruces (if relevant).
- #to_hash ⇒ Object
-
#validate ⇒ Object
Perform model valiations.
Class Method Details
.admin(user) ⇒ Object
Return groups where user is an admin.
75 76 77 78 79 80 81 |
# File 'lib/goz/group.rb', line 75 def self.admin(user) Goz::Logger.debug TAG, "admin( user=#{user.login} )" return user.groups if Goz::Group.name == @@api.name groups = self.api.groups(user).collect { |g| self.find_or_create g.to_hash } groups.each { |g| yield g } if block_given? groups end |
.after_add_service(g, s) ⇒ Object
TODO DRY w/ “Service”
84 85 86 |
# File 'lib/goz/group.rb', line 84 def self.after_add_service(g, s) s.create(g) && Goz::Event.group_service_add(g, s) end |
.after_remove_service(g, s) ⇒ Object
TODO DRY w/ “Service”
89 90 91 |
# File 'lib/goz/group.rb', line 89 def self.after_remove_service(g, s) s.destroy(g) && Goz::Event.group_service_remove(g, s) end |
.api(klass = nil, configuration = {}) ⇒ Object
TODO
96 97 98 99 100 101 102 103 104 |
# File 'lib/goz/group.rb', line 96 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_name(name) ⇒ Object
Find Goz::Group by name or return nil
109 110 111 112 113 114 115 116 117 |
# File 'lib/goz/group.rb', line 109 def self.find_by_name(name) Goz::Logger.debug TAG, "find_by_name( name=#{name} )" g = self.find :name => name return g unless g.nil? return nil if Goz::Group == self.api g = self.api.find_by_name name return nil if g.nil? return self.find_or_create g.to_hash end |
.member(user) ⇒ Object
Return groups where user is a member.
122 123 124 125 126 127 128 |
# File 'lib/goz/group.rb', line 122 def self.member(user) Goz::Logger.debug TAG, "member( user=#{user.login} )" return user.memberships if Goz::Group.name == @@api.name groups = self.api.memberships(user).collect { |g| self.find_or_create g.to_hash } groups.each { |g| yield g } if block_given? groups end |
Instance Method Details
#sync(force = false) ⇒ Object
Synchronize group with external data sources (if relevant).
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/goz/group.rb', line 133 def sync(force = false) Goz::Logger.debug TAG, "#{self.name} - #sync( force=#{force} )" if sync_group && sync_admins && sync_members self.services.each { |s| self.sync_service(s, force) } # TODO self.synchronized_at = Time.now self.save Goz::Event.group_sync(self) return true end false end |
#sync_service(service, force = false) ⇒ Object
Synchronize group service with external data soruces (if relevant).
148 149 150 151 |
# File 'lib/goz/group.rb', line 148 def sync_service(service, force = false ) Goz::Logger.debug TAG, "#{self.name} - #sync_service( service.name=#{service.name}, force=#{force} )" service.sync_group(self) # XXX end |
#to_hash ⇒ Object
153 154 155 |
# File 'lib/goz/group.rb', line 153 def to_hash Hash[ ATTRIBUTES.map { |k| [ k, self[k] ] } ] end |
#validate ⇒ Object
Perform model valiations.
160 161 162 163 164 165 |
# File 'lib/goz/group.rb', line 160 def validate super validates_presence [ :display_name, :identifier, :klass, :name ] validates_type Time, [ :created_at, :modified_at, :synchronized_at ] validates_unique [ :display_name, :identifier, :name ] end |