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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/resources/group.rb', line 19 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
38 39 40 41 |
# File 'lib/resources/group.rb', line 38 def exists? # ensure that we found one group !group_info.nil? && group_info.size > 0 end |
#gid ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/resources/group.rb', line 43 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
56 57 58 |
# File 'lib/resources/group.rb', line 56 def has_gid?(compare_gid) gid == compare_gid end |
#local ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/resources/group.rb', line 60 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
72 73 74 |
# File 'lib/resources/group.rb', line 72 def to_s "Group #{@group}" end |