Class: Wright::Resource::Group

Inherits:
Wright::Resource show all
Defined in:
lib/wright/resource/group.rb

Overview

TODO:

Use GnuPasswd provider on all GNU-flavoured systems

Group resource, represents a group.

Examples:

admins = Wright::Resource::Group.new('admins', members: ['root'])
admins.create

Instance Attribute Summary collapse

Attributes inherited from Wright::Resource

#action, #ignore_failure, #name, #resource_name

Instance Method Summary collapse

Methods inherited from Wright::Resource

#run_action

Constructor Details

#initialize(name, args = {}) ⇒ Group

Initializes a Group.

Parameters:

  • name (String)

    the group’s name

  • args (Hash) (defaults to: {})

    the arguments

Options Hash (args):

  • :action (Symbol) — default: :create

    the action

  • :members (Array<String>)

    the group’s members

  • :gid (Integer)

    the group’s gid

  • :system (Bool) — default: false

    denotes whether the group should be a system group or not



32
33
34
35
36
37
38
# File 'lib/wright/resource/group.rb', line 32

def initialize(name, args = {})
  super
  @action  = args.fetch(:action, :create)
  @members = args.fetch(:members, nil)
  @gid     = args.fetch(:gid, nil)
  @system  = args.fetch(:system, false)
end

Instance Attribute Details

#gidInteger

Returns the group’s intended group id.

Returns:

  • (Integer)

    the group’s intended group id



17
18
19
# File 'lib/wright/resource/group.rb', line 17

def gid
  @gid
end

#membersArray<String>

Returns the group’s intended members.

Returns:

  • (Array<String>)

    the group’s intended members



14
15
16
# File 'lib/wright/resource/group.rb', line 14

def members
  @members
end

#systemBool

Returns true if the group should be a system group. Ignored if #gid is set.

Returns:

  • (Bool)

    true if the group should be a system group. Ignored if #gid is set.



21
22
23
# File 'lib/wright/resource/group.rb', line 21

def system
  @system
end

Instance Method Details

#createBool

Creates or updates the group.

Returns:

  • (Bool)

    true if the group was updated and false otherwise



44
45
46
47
48
# File 'lib/wright/resource/group.rb', line 44

def create
  might_update_resource do
    provider.create
  end
end

#removeBool

Removes the group.

Returns:

  • (Bool)

    true if the group was updated and false otherwise



54
55
56
57
58
# File 'lib/wright/resource/group.rb', line 54

def remove
  might_update_resource do
    provider.remove
  end
end