@@ -15,11 +15,10 @@ def cur_example
1515 def get_working_node
1616 example = cur_example
1717 if example and example . metadata [ :node ]
18- node = example . metadata [ :node ]
18+ example . metadata [ :node ]
1919 else
20- node = default_node
20+ default_node
2121 end
22- node
2322 end
2423
2524 # The cygwin backend
@@ -40,20 +39,20 @@ def exec_backend
4039module Specinfra
4140 module Configuration
4241 class << self
43- VALID_OPTIONS_KEYS = [
44- : backend,
45- : env,
46- : path,
47- : pre_command,
48- : sudo_path,
49- : disable_sudo,
50- : sudo_options,
51- : docker_image,
52- : docker_url,
53- : lxc,
54- : request_pty,
55- : ssh_options,
56- : dockerfile_finalizer,
42+ VALID_OPTIONS_KEYS = %i [
43+ backend
44+ env
45+ path
46+ pre_command
47+ sudo_path
48+ disable_sudo
49+ sudo_options
50+ docker_image
51+ docker_url
52+ lxc
53+ request_pty
54+ ssh_options
55+ dockerfile_finalizer
5756 ] . freeze
5857 end
5958
@@ -66,9 +65,7 @@ module Specinfra::Helper::Os
6665
6766 def os
6867 working_node_name = get_working_node . to_s
69- if !@@known_nodes [ working_node_name ] # haven't seen this yet, better detect the os
70- @@known_nodes [ working_node_name ] = property [ :os ] = detect_os
71- end
68+ @@known_nodes [ working_node_name ] = property [ :os ] = detect_os unless @@known_nodes [ working_node_name ] # haven't seen this yet, better detect the os
7269 @@known_nodes [ working_node_name ]
7370 end
7471
@@ -80,9 +77,7 @@ def detect_os
8077 return Specinfra . configuration . os if Specinfra . configuration . os
8178 backend = Specinfra . backend
8279 node = get_working_node
83- if node [ 'platform' ] . include? ( 'windows' )
84- return { :family => 'windows' }
85- end
80+ return { family : 'windows' } if node [ 'platform' ] . include? ( 'windows' )
8681 Specinfra ::Helper ::DetectOs . subclasses . each do |c |
8782 res = c . detect
8883 if res
@@ -109,11 +104,8 @@ def get_windows_cmd(meth, *args)
109104 command_class = version_class . const_get ( resource_type . to_camel_case )
110105
111106 command_class = command_class . create
112- if command_class . respond_to? ( method )
113- command_class . send ( method , *args )
114- else
115- raise NotImplementedError . new ( "#{ method } is not implemented in #{ command_class } " )
116- end
107+ raise NotImplementedError , "#{ method } is not implemented in #{ command_class } " unless command_class . respond_to? ( method )
108+ command_class . send ( method , *args )
117109 end
118110
119111 end
@@ -135,12 +127,10 @@ def self.method_missing(meth, *args)
135127 else
136128 run ( meth , *args )
137129 end
130+ elsif backend . respond_to? ( meth )
131+ backend . send ( meth , *args )
138132 else
139- if backend . respond_to? ( meth )
140- backend . send ( meth , *args )
141- else
142- run ( meth , *args )
143- end
133+ run ( meth , *args )
144134 end
145135 end
146136
@@ -167,7 +157,7 @@ def convert_regexp(target)
167157 when Regexp
168158 target . source
169159 else
170- Regexp . escape ( target . to_s . gsub '/' , '\/' ) . gsub ( '\n' , '(\r\n|\n)' )
160+ Regexp . escape ( target . to_s . gsub ( '/' , '\/' ) ) . gsub ( '\n' , '(\r\n|\n)' )
171161 end
172162 end
173163 end
@@ -176,19 +166,17 @@ def convert_regexp(target)
176166module Specinfra ::Backend
177167 class BeakerBase < Specinfra ::Backend ::Base
178168 # Example accessor
179- def example
180- @example
181- end
169+ attr_reader :example
182170
183171 # Execute the provided ssh command
184172 # @param [String] command The command to be executed
185173 # @return [Hash] Returns a hash containing :exit_status, :stdout and :stderr
186174 def ssh_exec! ( node , command )
187- r = on node , command , { : acceptable_exit_codes => ( 0 ..127 ) }
175+ r = on node , command , { acceptable_exit_codes : ( 0 ..127 ) }
188176 {
189- : exit_status => r . exit_code ,
190- : stdout => r . stdout ,
191- : stderr => r . stderr ,
177+ exit_status : r . exit_code ,
178+ stdout : r . stdout ,
179+ stderr : r . stderr ,
192180 }
193181 end
194182
@@ -237,11 +225,11 @@ def run_command(cmd, _opt = {})
237225 #when node is not cygwin rm -rf will fail so lets use native del instead
238226 #There should be a better way to do this, but for now , this works
239227 if node . is_cygwin?
240- delete_command = " rm -rf"
241- redirection = " < /dev/null"
228+ delete_command = ' rm -rf'
229+ redirection = ' < /dev/null'
242230 else
243- delete_command = " del"
244- redirection = " < NUL"
231+ delete_command = ' del'
232+ redirection = ' < NUL'
245233 end
246234 on node , "#{ delete_command } script.ps1"
247235 create_remote_file ( node , 'script.ps1' , script )
@@ -288,9 +276,7 @@ def build_command(cmd)
288276 cmd = "#{ String ( useshell ) . shellescape } -c #{ String ( cmd ) . shellescape } "
289277
290278 path = Specinfra . configuration . path
291- if path
292- cmd = %Q{env PATH="#{ path } " #{ cmd } }
293- end
279+ cmd = %(env PATH="#{ path } " #{ cmd } ) if path
294280
295281 cmd
296282 end
0 commit comments