@@ -35,7 +35,7 @@ def criticality
3535 end
3636
3737 def installed?
38- return false
38+ false
3939 end
4040
4141 def to_s
@@ -55,28 +55,29 @@ def initialize
5555
5656 # returns all available updates
5757 def all
58- updates = fetchUpdates
58+ updates = fetch_updates
5959 updates . map { |update | WindowsUpdate . new ( update ) }
6060 end
6161
6262 # returns all important updates
6363 def important
64- updates = fetchUpdates
64+ updates = fetch_updates
6565 updates
6666 . select { |update |
67- @update_mgmt . isImportant ( update )
67+ @update_mgmt . important? ( update )
68+ } . map { |update | # rubocop:disable Style/MultilineBlockChain
69+ WindowsUpdate . new ( update )
6870 }
69- . map { |update | WindowsUpdate . new ( update ) }
7071 end
7172
7273 # returns all optional updates
7374 def optional
74- updates = fetchUpdates
75- updates
76- . select { | update |
77- @update_mgmt . isOptional ( update )
78- }
79- . map { | update | WindowsUpdate . new ( update ) }
75+ updates = fetch_updates
76+ updates . select { | update |
77+ @update_mgmt . optional? ( update )
78+ } . map { | update | # rubocop:disable Style/MultilineBlockChain
79+ WindowsUpdate . new ( update )
80+ }
8081 end
8182
8283 def reboot_required?
@@ -85,29 +86,31 @@ def reboot_required?
8586 end
8687
8788 def to_s
88- " Windows Update Services"
89+ ' Windows Update Services'
8990 end
9091
9192 # private
9293
9394 # detection for nano server
9495 # @see https://msdn.microsoft.com/en-us/library/hh846315(v=vs.85).aspx
95- def detect_nano
96+ def windows_nano?
9697 return false unless inspec . os [ :release ] . to_i >= 10
9798 '1' == inspec . powershell ( 'Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Server\ServerLevels" | Select -ExpandProperty "NanoServer" ' ) . stdout . chomp
9899 end
99100
101+ private
102+
100103 def select_update_mgmt
101- if detect_nano
104+ if windows_nano?
102105 WindowsNanoUpdateFetcher . new ( inspec )
103106 else
104107 Windows2012UpdateFetcher . new ( inspec )
105108 end
106109 end
107110
108- def fetchUpdates
111+ def fetch_updates
109112 return [ ] if @update_mgmt . nil?
110- @update_mgmt . fetchUpdates
113+ @update_mgmt . fetch_updates
111114 end
112115
113116 def hotfixes
@@ -125,7 +128,7 @@ def hotfixes
125128 [ ]
126129 end
127130
128- def fetchUpdates
131+ def fetch_updates
129132 [ ]
130133 end
131134end
@@ -134,7 +137,7 @@ class Windows2012UpdateFetcher < UpdateFetcher
134137 def hotfixes
135138 return @cache_hotfix_installed if defined? ( @cache_hotfix_installed )
136139
137- hotfix_cmd = " Get-HotFix | Select-Object -Property Status, Description, HotFixId, Caption, InstallDate, InstalledBy | ConvertTo-Json"
140+ hotfix_cmd = ' Get-HotFix | Select-Object -Property Status, Description, HotFixId, Caption, InstallDate, InstalledBy | ConvertTo-Json'
138141 cmd = @inspec . command ( hotfix_cmd )
139142 begin
140143 @cache_hotfix_installed = JSON . parse ( cmd . stdout )
@@ -143,7 +146,7 @@ def hotfixes
143146 end
144147 end
145148
146- def fetchUpdates
149+ def fetch_updates
147150 return @cache_available if defined? ( @cache_available )
148151 script = <<-EOH
149152$updateSession = new-object -com "Microsoft.Update.Session"
@@ -175,29 +178,29 @@ def fetchUpdates
175178 end
176179 end
177180
178- def isImportant ( update )
179- isSecurityCategory ( update [ 'CategoryIDs' ] )
181+ def important? ( update )
182+ security_category? ( update [ 'CategoryIDs' ] )
180183 end
181184
182- def isOptional ( update )
183- !isImportant ( update )
185+ def optional? ( update )
186+ !important? ( update )
184187 end
185188
186189 # @see: https://msdn.microsoft.com/en-us/library/ff357803(v=vs.85).aspx
187190 # e6cf1350-c01b-414d-a61f-263d14d133b4 -> Critical Updates
188191 # 0fa1201d-4330-4fa8-8ae9-b877473b6441 -> Security Updates
189192 # 28bc880e-0592-4cbf-8f95-c79b17911d5f -> Update Rollups
190193 # does not include recommended updates yet
191- def isSecurityCategory ( uuids )
194+ def security_category? ( uuids )
192195 return if uuids . nil?
193196 uuids . include? ( '0fa1201d-4330-4fa8-8ae9-b877473b6441' ) ||
194- uuids . include? ( '28bc880e-0592-4cbf-8f95-c79b17911d5f' ) ||
195- uuids . include? ( 'e6cf1350-c01b-414d-a61f-263d14d133b4' )
197+ uuids . include? ( '28bc880e-0592-4cbf-8f95-c79b17911d5f' ) ||
198+ uuids . include? ( 'e6cf1350-c01b-414d-a61f-263d14d133b4' )
196199 end
197200end
198201
199202class WindowsNanoUpdateFetcher < UpdateFetcher
200- def fetchUpdates
203+ def fetch_updates
201204 return @cache_available if defined? ( @cache_available )
202205 script = <<-EOH
203206$sess = New-CimInstance -Namespace root/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession
@@ -224,11 +227,11 @@ def fetchUpdates
224227 end
225228 end
226229
227- def isImportant ( update )
230+ def important? ( update )
228231 %w{ Important Critical } . include? update [ 'MsrcSeverity' ]
229232 end
230233
231- def isOptional ( update )
232- !isImportant ( update )
234+ def optional? ( update )
235+ !important? ( update )
233236 end
234237end
0 commit comments