class Wright::Resource::User

User resource, represents a user.

@example

johndoe = Wright::Resource::User.new('johndoe', home: '/home/johndoe')
johndoe.create

Attributes

full_name[RW]

@return [String] the user's intended full name

groups[RW]

@return [Array<String>] the user's intended groups

home[RW]

@return [String] the user's intended home directory path

homedir[RW]

@return [String] the user's intended home directory path

login_group[RW]

@return [String, Integer] the user's intended primary group

primary_group[RW]

@return [String, Integer] the user's intended primary group

shell[RW]

@return [String] the user's intended shell

system[RW]

@return [Bool] true if the user should be a system

user. Ignored if {#uid} is set.
uid[RW]

@return [Integer] the user's intended user id

Public Class Methods

new(name, args = {}) click to toggle source

Initializes a user.

@param name [String] the user's name @param args [Hash] the arguments @option args [Symbol] :action (:create) the action @option args [Integer] :uid the user's uid @option args [String] :full_name the user's full name @option args [Array<String>] :groups the user's groups @option args [String] :shell the user's shell @option args [String] :home the user's home directory @option args [String] :primary_group the user's primary group @option args [Bool] :system (false) denotes whether the user

should be a system user or not
Calls superclass method Wright::Resource::new
# File lib/wright/resource/user.rb, line 49
def initialize(name, args = {})
  super
  @action        = args.fetch(:action, :create)
  @uid           = args.fetch(:uid, nil)
  @full_name     = args.fetch(:full_name, nil)
  @groups        = args.fetch(:groups, nil)
  @shell         = args.fetch(:shell, nil)
  @home          = fetch_last(args, [:home, :homedir], nil)
  @primary_group = fetch_last(args, [:primary_group, :login_group], nil)
  @system        = args.fetch(:system, false)
end

Public Instance Methods

create() click to toggle source

Creates or updates the user.

@return [Bool] true if the user was updated and false

otherwise
# File lib/wright/resource/user.rb, line 65
def create
  might_update_resource do
    provider.create
  end
end
remove() click to toggle source

Removes the user.

@return [Bool] true if the user was updated and false

otherwise
# File lib/wright/resource/user.rb, line 75
def remove
  might_update_resource do
    provider.remove
  end
end

Private Instance Methods

fetch_last(hash, candidate_keys, default = nil) click to toggle source
# File lib/wright/resource/user.rb, line 83
def fetch_last(hash, candidate_keys, default = nil)
  Wright::Util.fetch_last(hash, candidate_keys, default)
end