Class: Transform
- Inherits:
-
Object
- Object
- Transform
- Defined in:
- lib/transform.rb
Constant Summary collapse
- NO_VALUE =
'no'
- ROWKEY =
'RowKey'
- SETTING =
'setting'
- VALUE =
'value'
- APPCLIENTID =
'AppClientId'
- APPIDURI =
'AppIdUri'
- NEWRELIC_APPNAME =
'NewRelic.AppName'
- SERVICENAME =
'ServiceName'
- OLDAPPID =
'AppId'
- EMPTY_STR =
''
- STORAGEACCOUNT =
'StorageAccount'
- STORAGEACCOUNTKEY =
"#{STORAGEACCOUNT}Key"
- CONNECTIONSTRING =
'connectionString'
Instance Attribute Summary collapse
-
#config_files ⇒ Object
Returns the value of attribute config_files.
-
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
-
#env ⇒ Object
Returns the value of attribute env.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#svc ⇒ Object
Returns the value of attribute svc.
-
#table ⇒ Object
Returns the value of attribute table.
Instance Method Summary collapse
- #get(key) ⇒ Object
- #get_all ⇒ Object
- #get_value(key) ⇒ Object
- #remove_paths_from_list(paths_to_exclude, source_list) ⇒ Object
-
#transform(paths_to_exclude = []) ⇒ Object
paths_to_exclude is array of partial or full paths of projects where transform needs skipped.
- #transform_appdynamics(doc) ⇒ Object
- #transform_appdynamics_config ⇒ Object
- #transform_appdynamics_node(doc, xml_node) ⇒ Object
- #transform_appinsights(paths_to_exclude) ⇒ Object
- #transform_appsettings(key = EMPTY_STR, value = EMPTY_STR) ⇒ Object
- #transform_cacheclient ⇒ Object
- #transform_cscfg ⇒ Object
- #transform_csdef(custom_xml_process = nil) ⇒ Object
- #transform_diagnosticscfg ⇒ Object
-
#transform_log4net ⇒ Object
log level and azure table appender parameters are transformed.
- #transform_newrelic(doc) ⇒ Object
- #transform_newrelic_node(doc, xml_node) ⇒ Object
- #transform_riverbed(doc) ⇒ Object
- #transform_riverbed_node(doc, xml_node) ⇒ Object
- #transform_servicemodelconfig ⇒ Object
- #transform_systemwebcompilationattribs ⇒ Object
- #transform_xmlsettings(files, settings, update_setting, key = EMPTY_STR, value = EMPTY_STR) ⇒ Object
- #update_appdynamics_application(k, v, doc, file) ⇒ Object
- #update_appsetting(k, v, doc, file) ⇒ Object
- #update_xmlsetting(k, v, doc, file, xpath, value_key = VALUE) ⇒ Object
Instance Attribute Details
#config_files ⇒ Object
Returns the value of attribute config_files.
7 8 9 |
# File 'lib/transform.rb', line 7 def config_files @config_files end |
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
8 9 10 |
# File 'lib/transform.rb', line 8 def debug_mode @debug_mode end |
#env ⇒ Object
Returns the value of attribute env.
3 4 5 |
# File 'lib/transform.rb', line 3 def env @env end |
#settings ⇒ Object
Returns the value of attribute settings.
6 7 8 |
# File 'lib/transform.rb', line 6 def settings @settings end |
#svc ⇒ Object
Returns the value of attribute svc.
4 5 6 |
# File 'lib/transform.rb', line 4 def svc @svc end |
#table ⇒ Object
Returns the value of attribute table.
5 6 7 |
# File 'lib/transform.rb', line 5 def table @table end |
Instance Method Details
#get(key) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/transform.rb', line 24 def get key begin result = @svc.get_entity @table, @env, key rescue puts $! puts "Error retrieving key: #{@key}" puts end result end |
#get_all ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/transform.rb', line 36 def get_all begin query = { :filter => "PartitionKey eq '#{@env}'" } result = @svc.query_entities @table, query rescue puts $! puts "Error retrieving table entities for Env : #{@env}" puts end result end |
#get_value(key) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/transform.rb', line 49 def get_value key if @settings.nil? return end value = EMPTY_STR @settings.each { |i| if i.properties[ROWKEY] == key value = i.properties[SETTING] break end } value end |
#remove_paths_from_list(paths_to_exclude, source_list) ⇒ Object
433 434 435 436 437 438 439 |
# File 'lib/transform.rb', line 433 def remove_paths_from_list paths_to_exclude, source_list paths_to_exclude.each { |path| source_list.delete_if { |file| file.include? path } } end |
#transform(paths_to_exclude = []) ⇒ Object
paths_to_exclude is array of partial or full paths of projects where transform needs skipped
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/transform.rb', line 442 def transform paths_to_exclude = [] @debug_mode = ENV['transform_debug_mode'] # --- Get environment invoked @env = ENV['env'] || NO_VALUE if @env == NO_VALUE puts 'Environment name required to transform. No configuration changes will be done...' return false else puts "Transforming config for environment: #{@env} ..." end # --- Get Settings Account Name, Key and Table from Environment variables settings_account_name = ENV['SettingsAccount'] || ENV[STORAGEACCOUNT] || NO_VALUE if settings_account_name == NO_VALUE puts "No settings storage account name found" return false end settings_access_key = ENV['SettingsAccountKey'] || ENV[STORAGEACCOUNTKEY] || NO_VALUE if settings_access_key == NO_VALUE puts "No settings storage account key found" return false end config_table = ENV['ConfigSettingsTable'] || NO_VALUE if config_table == NO_VALUE puts "No configuration table found" end # --- Collect config files to transform # find all App.config and web.config files @config_files = Dir.glob '**/app.config' @config_files.concat(Dir.glob '**/appSettings.config') @config_files.concat(Dir.glob '**/web.config') @config_files.concat(Dir.glob '**/RuntimeWeb/*Web.dll.config') @config_files.concat(Dir.glob '**/RuntimeService/*.exe.config') # remove projects which need not be transformed remove_paths_from_list paths_to_exclude, @config_files # --- Load Settings from storage # azure table storage account where settings reside Azure.config.storage_account_name = settings_account_name Azure.config.storage_access_key = settings_access_key @table = config_table # table service @svc = Azure::TableService.new # get all settings for environment @settings = get_all # --- Start Transformations --- puts "updating settings #{CONNECTIONSTRING}..." settings_connstr = "DefaultEndpointsProtocol=https;AccountName=#{settings_account_name};AccountKey=#{settings_access_key}" should_update_settings_connstr = ENV['should_update_settings_connstr'] || NO_VALUE if should_update_settings_connstr == NO_VALUE puts "Flag for Setttings #{CONNECTIONSTRING} Update not set." else transform_appsettings CONNECTIONSTRING, settings_connstr end puts "updating unit test #{CONNECTIONSTRING}..." unitest_connstr = ENV["unitest#{CONNECTIONSTRING}"] || NO_VALUE if unitest_connstr == NO_VALUE puts "No unit test #{CONNECTIONSTRING} found." else transform_appsettings "unitest#{CONNECTIONSTRING}", unitest_connstr end puts "updating #{APPCLIENTID}..." appClientId = ENV[APPCLIENTID] || NO_VALUE if appClientId == NO_VALUE puts "No #{APPCLIENTID} found." # old version notify check oldAppId = ENV[OLDAPPID] if oldAppId != NO_VALUE puts "You appear to be using the old AppId environment variable, AppClientId is expected. Proceeding with old AppId update." transform_appsettings OLDAPPID, oldAppId end else transform_appsettings APPCLIENTID, appClientId end puts "updating #{APPIDURI}..." appIdUri = ENV[APPIDURI] || NO_VALUE if appIdUri == NO_VALUE puts "No #{APPIDURI} found." else transform_appsettings APPIDURI, appIdUri end @service_name = ENV[SERVICENAME] is_service = @service_name || NO_VALUE if is_service != NO_VALUE puts "Transforming config for service: #{@service_name}" puts 'Obtaining cloud configuration templates...' csdefTemplate = get_value 'ServiceDefinitionTemplate' File.write 'ServiceDefinition.csdef', csdefTemplate cscfgTemplate = get_value 'ServiceConfigurationTemplate' File.write 'ServiceConfiguration.cscfg', cscfgTemplate puts 'Transforming csdef...' xml_node_processing = nil use_riverbed = ENV['UseRiverbed'] || NO_VALUE use_riverbed = use_riverbed.downcase if use_riverbed == "true" puts 'Using riverbed...' xml_node_processing = method(:transform_riverbed) end use_newrelic = ENV['UseNewrelic'] || NO_VALUE use_newrelic = use_newrelic.downcase if use_newrelic == "true" puts 'Using new relic...' transform_appsettings NEWRELIC_APPNAME, @service_name xml_node_processing = method(:transform_newrelic) end use_appdynamics = ENV['UseAppdynamics'] || NO_VALUE use_appdynamics = use_appdynamics.downcase if use_appdynamics == "true" puts 'Using app dynamics...' xml_node_processing = method(:transform_appdynamics) transform_appdynamics_config end if !((use_riverbed == "true" and use_newrelic != "true" and use_appdynamics != "true") or (use_riverbed != "true" and use_newrelic == "true" and use_appdynamics != "true") or (use_riverbed != "true" and use_newrelic != "true" and use_appdynamics == "true") or (use_riverbed != "true" and use_newrelic != "true" and use_appdynamics != "true")) puts 'Only one APM tool can be used at one time, aborting.' return false end transform_csdef xml_node_processing puts 'Transforming cscfg...' transform_cscfg puts 'Transforming diagnostics cfg...' transform_diagnosticscfg puts 'Replacing service model settings...' transform_servicemodelconfig else puts 'Target to transform is not a service...' end puts 'Replacing app settings...' transform_appsettings puts 'Removing debug compilation attributes...' transform_systemwebcompilationattribs puts 'Transforming cache client...' transform_cacheclient puts 'Transforming Application Insights...' transform_appinsights paths_to_exclude puts 'Transforming log4net config...' transform_log4net return true end |
#transform_appdynamics(doc) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/transform.rb', line 289 def transform_appdynamics doc is_service = @service_name || NO_VALUE if is_service != NO_VALUE node = doc.at_css 'WebRole' transform_appdynamics_node(doc, node) if !node.nil? node = doc.at_css 'WorkerRole' transform_appdynamics_node(doc, node) if !node.nil? else puts 'Not a service, avoiding transforming the csdef.' end end |
#transform_appdynamics_config ⇒ Object
70 71 72 73 74 75 |
# File 'lib/transform.rb', line 70 def transform_appdynamics_config # update application name in the config.xml puts 'Transforming appdynamics config.' files = Dir.glob '**/RuntimeService/AppDynamics/config.xml' transform_xmlsettings(files, nil, method(:update_appdynamics_application), 'name', @service_name) end |
#transform_appdynamics_node(doc, xml_node) ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/transform.rb', line 301 def transform_appdynamics_node doc, xml_node task_node = Nokogiri::XML::Node.new 'Task', doc task_node['commandLine'] = "AppDynamics\\startup_env.cmd" task_node['executionContext'] = 'elevated' task_node['taskType'] = 'simple' env_node = Nokogiri::XML::Node.new 'Environment', doc var_node = Nokogiri::XML::Node.new 'Variable', doc var_node['name'] = 'EMULATED' val_node = Nokogiri::XML::Node.new 'RoleInstanceValue', doc val_node['xpath'] = '/RoleEnvironment/Deployment/@emulated' var_node.add_child(val_node) env_node.add_child(var_node) task_node.add_child(env_node) existing_start_up_node = xml_node.at_css('Startup') if existing_start_up_node.nil? start_up_node = Nokogiri::XML::Node.new 'Startup', doc xml_node.add_child(start_up_node) start_up_node.add_child(task_node) else existing_start_up_node.add_child(task_node) end end |
#transform_appinsights(paths_to_exclude) ⇒ Object
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/transform.rb', line 352 def transform_appinsights paths_to_exclude aiconfig = Dir.glob '**/ApplicationInsights.config' remove_paths_from_list paths_to_exclude, aiconfig aiconfig.each{ |file| doc = Nokogiri::XML(File.read file) node = doc.at_css 'InstrumentationKey' if !node.nil? val_from_settings = get_value 'AI_InstrumentationKey' if val_from_settings.to_s == EMPTY_STR aikey = ENV['AI_InstrumentationKey'] || NO_VALUE else aikey = val_from_settings end if aikey != NO_VALUE node.content = aikey end end File.write file, doc.to_xml } end |
#transform_appsettings(key = EMPTY_STR, value = EMPTY_STR) ⇒ Object
64 65 66 67 68 |
# File 'lib/transform.rb', line 64 def transform_appsettings key = EMPTY_STR, value = EMPTY_STR # go to each file and replace value of matching appSettings key puts 'Transforming app settings.' transform_xmlsettings(@config_files, @settings, method(:update_appsetting), key, value) end |
#transform_cacheclient ⇒ Object
392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/transform.rb', line 392 def transform_cacheclient cacheclient_id = get_value 'CacheClient_Identifier' @config_files.each{ |file| doc = Nokogiri::XML(File.read file) node = doc.at_css 'dataCacheClients/dataCacheClient/autoDiscover' if !node.nil? node['identifier'] = cacheclient_id end File.write file, doc.to_xml } end |
#transform_cscfg ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/transform.rb', line 328 def transform_cscfg csdef = Dir.glob '**/*.cscfg' csdef.each{ |file| doc = Nokogiri::XML(File.read file) node = doc.at_css 'ServiceConfiguration' node['serviceName'] = @service_name if !node.nil? node = doc.at_css 'Role' node['name'] = @service_name if !node.nil? node = doc.at_css 'Certificates' node.replace(get_value 'Certificates_cscfg') if !node.nil? node = doc.at_css 'ConfigurationSettings' node.replace(get_value 'ConfigurationSettings_cscfg') if !node.nil? File.write file, doc.to_xml } end |
#transform_csdef(custom_xml_process = nil) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/transform.rb', line 169 def transform_csdef custom_xml_process=nil csdef = Dir.glob '**/*.csdef' csdef.each{ |file| doc = Nokogiri::XML(File.read file) node = doc.at_css 'ServiceDefinition' node['name'] = @service_name if !node.nil? node = doc.at_css 'WebRole' node['name'] = @service_name if !node.nil? node = doc.at_css 'WorkerRole' node['name'] = @service_name if !node.nil? node = doc.at_css 'Certificates' node.replace(get_value 'Certificates_csdef') if !node.nil? node = doc.at_css 'Endpoints' node.replace(get_value 'Endpoints') if !node.nil? node = doc.at_css 'Bindings' node.replace(get_value 'Bindings') if !node.nil? node = doc.at_css 'Sites' node.replace(get_value 'Sites') if !node.nil? node = doc.at_css 'Imports' node.replace(get_value 'Imports') if !node.nil? node = doc.at_css 'LocalResources' node.replace(get_value 'LocalResources') if !node.nil? custom_xml_process.call(doc) if !custom_xml_process.nil? and !doc.nil? File.write file, doc.to_xml } end |
#transform_diagnosticscfg ⇒ Object
377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/transform.rb', line 377 def transform_diagnosticscfg csdef = Dir.glob '**/*.wadcfgx' csdef.each{ |file| doc = Nokogiri::XML(File.read file) node = doc.at_css "PrivateConfig/#{STORAGEACCOUNT}" node['name'] = get_value STORAGEACCOUNT node['key'] = get_value STORAGEACCOUNTKEY node = doc.at_css STORAGEACCOUNT node.content = get_value STORAGEACCOUNT File.write file, doc.to_xml } end |
#transform_log4net ⇒ Object
log level and azure table appender parameters are transformed
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
# File 'lib/transform.rb', line 407 def transform_log4net config_files = Dir.glob '**/log4net.config' config_files.each{ |file| doc = Nokogiri::XML(File.read file) # azure table name is service name node = doc.at_css 'log4net/appender[@name=AzureTableAppender]/param[@name=TableName]' node['value'] = @service_name if !node.nil? node = doc.at_css 'log4net/appender[@name=AzureTableAppender]/param[@name=ConnectionString]' log_connstr = ENV["log#{CONNECTIONSTRING}"] || NO_VALUE if log_connstr == NO_VALUE puts "No logging #{CONNECTIONSTRING} found." else node['value'] = log_connstr if !node.nil? end # log level node = doc.at_css 'log4net/root/level' loglevel = ENV['loglevel'] || NO_VALUE node['value'] = ENV['loglevel'] if (!node.nil? && loglevel != NO_VALUE) File.write file, doc.to_xml } end |
#transform_newrelic(doc) ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/transform.rb', line 250 def transform_newrelic doc is_service = @service_name || NO_VALUE if is_service != NO_VALUE node = doc.at_css 'WebRole' transform_newrelic_node(doc, node) if !node.nil? node = doc.at_css 'WorkerRole' transform_newrelic_node(doc, node) if !node.nil? else puts 'Not a service, avoiding transforming the csdef.' end end |
#transform_newrelic_node(doc, xml_node) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/transform.rb', line 262 def transform_newrelic_node doc, xml_node task_node = Nokogiri::XML::Node.new 'Task', doc task_node['commandLine'] = 'newrelic_env.cmd' task_node['executionContext'] = 'elevated' task_node['taskType'] = 'simple' env_node = Nokogiri::XML::Node.new 'Environment', doc var_node = Nokogiri::XML::Node.new 'Variable', doc var_node['name'] = 'EMULATED' val_node = Nokogiri::XML::Node.new 'RoleInstanceValue', doc val_node['xpath'] = '/RoleEnvironment/Deployment/@emulated' var_node.add_child(val_node) env_node.add_child(var_node) task_node.add_child(env_node) existing_start_up_node = xml_node.at_css('Startup') if existing_start_up_node.nil? start_up_node = Nokogiri::XML::Node.new 'Startup', doc xml_node.add_child(start_up_node) start_up_node.add_child(task_node) else existing_start_up_node.add_child(task_node) end end |
#transform_riverbed(doc) ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/transform.rb', line 209 def transform_riverbed doc is_service = @service_name || NO_VALUE if is_service != NO_VALUE node = doc.at_css 'WebRole' transform_riverbed_node(doc, node) if !node.nil? node = doc.at_css 'WorkerRole' transform_riverbed_node(doc, node) if !node.nil? else puts 'Not a service, avoiding transforming the csdef.' end end |
#transform_riverbed_node(doc, xml_node) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/transform.rb', line 221 def transform_riverbed_node doc, xml_node task_node = Nokogiri::XML::Node.new 'Task', doc task_node['commandLine'] = 'AppInternals\startup.cmd' task_node['executionContext'] = 'elevated' task_node['taskType'] = 'foreground' env_node = Nokogiri::XML::Node.new 'Environment', doc var_node = Nokogiri::XML::Node.new 'Variable', doc var_node['name'] = 'AnalysisServerIP' var_node['value'] = get_value 'AnalysisServerIP' var_node2 = Nokogiri::XML::Node.new 'Variable', doc var_node2['name'] = 'AgentInstaller' var_node2['value'] = get_value 'AgentInstaller' env_node.add_child(var_node) env_node.add_child(var_node2) task_node.add_child(env_node) existing_start_up_node = xml_node.at_css('Startup') if existing_start_up_node.nil? start_up_node = Nokogiri::XML::Node.new 'Startup', doc xml_node.add_child(start_up_node) start_up_node.add_child(task_node) else existing_start_up_node.add_child(task_node) end end |
#transform_servicemodelconfig ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/transform.rb', line 137 def transform_servicemodelconfig @config_files.each{|file| doc = Nokogiri::XML(File.read file) doc.xpath('//system.serviceModel').each do |node| if !node.nil? if file.end_with?('app.config') || file.end_with?('App.config') val = get_value 'system.ServiceModel.Client' node.replace val if !val.nil? elsif file.end_with?('Web.config') val = get_value 'system.ServiceModel.Service' node.replace val if !val.nil? end File.write file, doc.to_xml end end } end |
#transform_systemwebcompilationattribs ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/transform.rb', line 155 def transform_systemwebcompilationattribs @config_files.each{|file| doc = Nokogiri::XML(File.read file) node = doc.at_css 'compilation' if !node.nil? #puts node node.xpath('//@debug').remove node.xpath('//@tempDirectory').remove #puts node File.write file, doc.to_xml end } end |
#transform_xmlsettings(files, settings, update_setting, key = EMPTY_STR, value = EMPTY_STR) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/transform.rb', line 77 def transform_xmlsettings files, settings, update_setting, key = EMPTY_STR, value = EMPTY_STR files.each{|file| doc = Nokogiri::XML(File.read file) puts "Processing file: #{file}" if (key.to_s != EMPTY_STR && value.to_s != EMPTY_STR) k = key v = value status = update_setting.call(k, v, doc, file) if status == :updated if @debug_mode puts "Updated key #{k} with #{v}" else puts "Updated key: #{k}" end end else if !settings.nil? settings.each { |i| k = i.properties[ROWKEY] || NO_VALUE v = i.properties[SETTING] || NO_VALUE status = update_setting.call(k, v, doc, file) if status == :updated if @debug_mode puts "Updated key #{k} with #{v}" else puts "Updated key: #{k}" end end } end end } end |
#update_appdynamics_application(k, v, doc, file) ⇒ Object
115 116 117 |
# File 'lib/transform.rb', line 115 def update_appdynamics_application k, v, doc, file update_xmlsetting(k, v, doc, file, "controller/application", k) end |
#update_appsetting(k, v, doc, file) ⇒ Object
111 112 113 |
# File 'lib/transform.rb', line 111 def update_appsetting k, v, doc, file update_xmlsetting(k, v, doc, file, "appSettings/add[@key='#{k}']") end |
#update_xmlsetting(k, v, doc, file, xpath, value_key = VALUE) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/transform.rb', line 119 def update_xmlsetting k, v, doc, file, xpath, value_key = VALUE status = :noargs if (k != NO_VALUE && v != NO_VALUE) node = doc.at_css xpath if !node.nil? puts "Old value: #{node[value_key]}" if @debug_mode node[value_key] = v puts "New value: #{v}" if @debug_mode File.write file, doc.to_xml status = :updated else status = :notfound end end status end |