Module: Josef::Remote

Includes:
GoogleWorkspace::Client, GoogleWorkspace::Group
Included in:
Cli, Diff
Defined in:
lib/josef/remote.rb

Instance Method Summary collapse

Methods included from GoogleWorkspace::Group

#create_group, #delete_group, #groups, #groups!

Methods included from GoogleWorkspace::Members

#add_member, #del_member, #member_mail_addreses, #members_by

Methods included from GoogleWorkspace::Config

#actor, #actor!, #credential_path, #domains, #token_path

Methods included from GoogleWorkspace::Client

#authorize!, #client, #client!

Instance Method Details

#remoteObject



9
10
11
# File 'lib/josef/remote.rb', line 9

def remote
  @_remote ||= remote!
end

#remote!Object



13
14
15
16
17
# File 'lib/josef/remote.rb', line 13

def remote!
  groups.map do | group |
    { group_mail_address: group.email, members: member_mail_addreses(group) }
  end
end

#remote_apply(local) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/josef/remote.rb', line 23

def remote_apply(local)
  remote_diff(remote, local)
  local.each do | local_group |
    next unless should_be_tareget?(local_group)

    if be_create?(local_group)
      create_group(local_group[:group_mail_address])

      local_group[:members].each do | member |
        add_member(local_group[:group_mail_address], member)
      end
    elsif changed?(local_group)
      remote_members = remote.find{|g| g[:group_mail_address] == local_group[:group_mail_address]}[:members]

      add = local_group[:members] - remote_members
      del = remote_members - local_group[:members]

      add.each do | add_member_mail_address |
        add_member(local_group[:group_mail_address], add_member_mail_address)
      end

      del.each do | del_member_mail_address |
        del_member(local_group[:group_mail_address], del_member_mail_address)
      end
    end
  end

  remote.each do | remote_group |
    next unless should_be_tareget?(remote_group)

    if be_delete?(remote_group)
      delete_group(remote_group[:group_mail_address])
    end
  end
end

#remote_dumpObject



19
20
21
# File 'lib/josef/remote.rb', line 19

def remote_dump
  YAML.dump(remote.map{|h| h.deep_stringify_keys}, File.open('dump.yml', 'w'))
end