77
88class Hash
99 def recursive_merge! ( other )
10- self . merge! ( other ) do |_ , old_value , new_value |
11- if old_value . class == Hash && new_value . class == Hash
10+ merge! ( other ) do |_ , old_value , new_value |
11+ if old_value . class == Hash && new_value . class == Hash # rubocop:disable Style/ClassEqualityComparison
1212 old_value . recursive_merge! ( new_value )
1313 else
1414 new_value
@@ -27,14 +27,14 @@ def initialize(spec)
2727 @name = spec [ "job" ] [ "name" ] if spec [ "job" ] . is_a? ( Hash )
2828 @index = spec [ "index" ]
2929
30- if !spec [ ' job_properties' ] . nil?
31- properties1 = spec [ ' job_properties' ]
30+ properties1 = if !spec [ " job_properties" ] . nil?
31+ spec [ " job_properties" ]
3232 else
33- properties1 = spec [ ' global_properties' ] . recursive_merge! ( spec [ ' cluster_properties' ] )
33+ spec [ " global_properties" ] . recursive_merge! ( spec [ " cluster_properties" ] )
3434 end
3535
3636 properties = { }
37- spec [ ' default_properties' ] . each do |name , value |
37+ spec [ " default_properties" ] . each do |name , value |
3838 copy_property ( properties , properties1 , name , value )
3939 end
4040
@@ -66,7 +66,7 @@ def if_p(*names)
6666 value
6767 end
6868
69- yield *values
69+ yield ( *values )
7070 InactiveElseBlock . new
7171 end
7272
@@ -97,13 +97,15 @@ def copy_property(dst, src, name, default = nil)
9797
9898 def openstruct ( object )
9999 case object
100- when Hash
101- mapped = object . inject ( { } ) { |h , ( k , v ) | h [ k ] = openstruct ( v ) ; h }
102- OpenStruct . new ( mapped )
103- when Array
104- object . map { |item | openstruct ( item ) }
105- else
106- object
100+ when Hash
101+ mapped = object . each_with_object ( { } ) { |( k , v ) , h |
102+ h [ k ] = openstruct ( v )
103+ }
104+ OpenStruct . new ( mapped )
105+ when Array
106+ object . map { |item | openstruct ( item ) }
107+ else
108+ object
107109 end
108110 end
109111
@@ -137,13 +139,14 @@ def else
137139 yield
138140 end
139141
140- def else_if_p ( *names , &block )
141- @context . if_p ( *names , &block )
142+ def else_if_p ( *names , &block ) # rubocop:disable Style/ArgumentsForwarding
143+ @context . if_p ( *names , &block ) # rubocop:disable Style/ArgumentsForwarding
142144 end
143145 end
144146
145147 class InactiveElseBlock
146- def else ; end
148+ def else
149+ end
147150
148151 def else_if_p ( *names )
149152 InactiveElseBlock . new
@@ -153,7 +156,7 @@ def else_if_p(*names)
153156
154157# todo do not use JSON in releases
155158class << JSON
156- alias dump_array_or_hash dump
159+ alias_method : dump_array_or_hash, : dump
157160
158161 def dump ( *args )
159162 arg = args [ 0 ]
@@ -174,18 +177,16 @@ def render(src_path, dst_path)
174177 erb = ERB . new ( File . read ( src_path ) , trim_mode : "-" )
175178 erb . filename = src_path
176179
177- context_hash = JSON . load ( File . read ( @json_context_path ) )
180+ # Note: JSON.load_file was added in v2.3.1: https://github.com/ruby/json/blob/v2.3.1/lib/json/common.rb#L286
181+ context_hash = JSON . parse ( File . read ( @json_context_path ) )
178182 template_evaluation_context = TemplateEvaluationContext . new ( context_hash )
179183
180- File . open ( dst_path , "w" ) do |f |
181- f . write ( erb . result ( template_evaluation_context . get_binding ) )
182- end
183-
184- rescue Exception => e
184+ File . write ( dst_path , erb . result ( template_evaluation_context . get_binding ) )
185+ rescue Exception => e # rubocop:disable Lint/RescueException
185186 name = "#{ template_evaluation_context &.name } /#{ template_evaluation_context &.index } "
186187
187- line_i = e . backtrace . index { |l | l . include? ( " #{ erb &.filename } " ) }
188- line_num = line_i ? e . backtrace [ line_i ] . split ( ':' ) [ 1 ] : "unknown"
188+ line_i = e . backtrace . index { |l | l . include? ( erb &.filename . to_s ) }
189+ line_num = line_i ? e . backtrace [ line_i ] . split ( ":" ) [ 1 ] : "unknown"
189190 location = "(line #{ line_num } : #{ e . inspect } )"
190191
191192 raise ( "Error filling in template '#{ src_path } ' for #{ name } #{ location } " )
0 commit comments