Class: Group
- Inherits:
-
Object
- Object
- Group
- Defined in:
- lib/resources/group.rb
Overview
Usage: describe group(‘root’) do
it { should exist }
its('gid') { should eq 0 }
end
deprecated has matcher describe group(‘root’) do
it { should have_gid 0 }
end
Instance Method Summary collapse
-
#exists? ⇒ Boolean
verifies if a group exists.
- #gid ⇒ Object
-
#has_gid?(compare_gid) ⇒ Boolean
implements rspec has matcher, to be compatible with serverspec.
-
#initialize(groupname, domain = nil) ⇒ Group
constructor
A new instance of Group.
- #local ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(groupname, domain = nil) ⇒ Group
Returns a new instance of Group.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/resources/group.rb', line 26 def initialize(groupname, domain = nil) @group = groupname.downcase @domain = domain @domain = @domain.downcase unless @domain.nil? @cache = nil # select group manager @group_provider = nil if inspec.os.unix? @group_provider = UnixGroup.new(inspec) elsif inspec.os.windows? @group_provider = WindowsGroup.new(inspec) else return skip_resource 'The `group` resource is not supported on your OS yet.' end end |
Instance Method Details
#exists? ⇒ Boolean
verifies if a group exists
45 46 47 48 |
# File 'lib/resources/group.rb', line 45 def exists? # ensure that we found one group !group_info.nil? && group_info.size > 0 end |
#gid ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/resources/group.rb', line 50 def gid if group_info.nil? || group_info.size == 0 return nil elsif group_info.size == 1 # the default case should be one group return group_info[0][:gid] else # return array if we got multiple gids return group_info.map { |grp| grp[:gid] } end end |
#has_gid?(compare_gid) ⇒ Boolean
implements rspec has matcher, to be compatible with serverspec
63 64 65 |
# File 'lib/resources/group.rb', line 63 def has_gid?(compare_gid) gid == compare_gid end |
#local ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/resources/group.rb', line 67 def local if group_info.nil? || group_info.size == 0 return nil elsif group_info.size == 1 # the default case should be one group return group_info[0][:local] else # return array if we got multiple gids return group_info.map { |grp| grp[:local] } end end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/resources/group.rb', line 79 def to_s "Group #{@group}" end |