-
Notifications
You must be signed in to change notification settings - Fork 9
/
group.rb
39 lines (32 loc) · 867 Bytes
/
group.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require "serverkit/resources/base"
module Serverkit
module Resources
class Group < Base
attribute :gid, type: Integer
attribute :name, required: true, type: String
# @note Override
def apply
if has_correct_group?
run_command_from_identifier(:update_group_gid, name, gid)
else
run_command_from_identifier(:add_group, name, gid: gid)
end
end
# @note Override
def check
has_correct_group? && has_correct_gid?
end
private
def has_correct_gid?
gid.nil? || gid == remote_gid
end
def has_correct_group?
check_command_from_identifier(:check_group_exists, name)
end
# @return [Integer]
def remote_gid
run_command_from_identifier(:get_group_gid, name).stdout.strip.to_i
end
end
end
end