Class: SynchronizeUsers::TargetGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/synchronize-users/target_group.rb

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(connection, name) ⇒ TargetGroup

Returns a new instance of TargetGroup.



22
23
24
25
26
27
# File 'lib/synchronize-users/target_group.rb', line 22

def initialize(connection, name)
  @connection = connection
  @name = name

  initialize_group!
end

Instance Method Details

#create_user(user) ⇒ Object



41
42
43
# File 'lib/synchronize-users/target_group.rb', line 41

def create_user(user)
  @connection.endpoint.users.import(user)
end

#has_user?(user) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/synchronize-users/target_group.rb', line 33

def has_user?(user)
  !!members.find { |m| m.username == user.username}
end

#import_user(source, role) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/synchronize-users/target_group.rb', line 45

def import_user(source, role)
  to_user = @connection.endpoint.users.find(source)

  if !to_user
    to_user = yield Result.new_user(source)
  end

  @group.add_member(to_user, role)
rescue => e
  yield Result.error(e)
end

#initialize_group!Object



29
30
31
# File 'lib/synchronize-users/target_group.rb', line 29

def initialize_group!
  @group = @connection.find(name: @name) || @connection.create(@name, @name)
end

#membersObject



37
38
39
# File 'lib/synchronize-users/target_group.rb', line 37

def members
  @members ||= @group.members
end