class Dopi::Command::Ssh::FileReplace
Public Instance Methods
file()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 40 def file @file ||= file_valid? ? hash[:file] : nil end
global()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 35 def global @global ||= global_valid? ? hash[:global] : true end
pattern()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 44 def pattern @pattern ||= pattern_valid? ? hash[:pattern] : nil end
replacement()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 30 def replacement @replacement ||= replacement_valid? ? hash[:replacement] : nil end
run()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 21 def run cmd_stdout, cmd_stderr, cmd_exit_code = ssh_command({}, command_string) check_exit_code(cmd_exit_code) end
run_noop()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 26 def run_noop log(:info, "(NOOP) Executing '#{command_string}' for command #{name}") end
validate()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 14 def validate validate_ssh validate_exit_code log_validation_method(:replacement_valid?, CommandParsingError) log_validation_method(:global_valid?, CommandParsingError) end
Private Instance Methods
command_string()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 51 def command_string "sed -i \"s/#{pattern}/#{replacement}/#{global_string}\" #{file}" end
file_valid?()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 72 def file_valid? hash[:file] or raise CommandParsingError, "Plugin #{name}: The key 'file' needs to be specified" begin Pathname.new(hash[:file]).absolute? or raise CommandParsingError, "Plugin #{name}: The path for 'file' has to be absolute" rescue ArgumentError => e raise CommandParsingError, "Plugin #{name}: The value in 'file' is not a valid file path: #{e.message}" end end
global_string()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 55 def global_string global ? 'g' : '' end
global_valid?()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 66 def global_valid? return false if hash[:global].nil? # is optional hash[:global].kind_of?(TrueClass) or hash[:global].kind_of?(FalseClass) or raise CommandParsingError, "Plugin #{name}: The value for 'global' must be boolean" end
pattern_valid?()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 83 def pattern_valid? hash[:pattern] or raise CommandParsingError, "Plugin #{name}: The key 'pattern' needs to be specified" begin Regexp.new(hash[:pattern]) rescue raise CommandParsingError, "Plugin #{name}: The value in 'pattern' is not a valid regexp: #{e.message}" end end
replacement_valid?()
click to toggle source
# File lib/dopi/command/ssh/file_replace.rb, line 59 def replacement_valid? hash[:replacement] or raise CommandParsingError, "Plugin #{name}: The key 'replacement' needs to be specified" hash[:replacement].kind_of?(String) or raise CommandParsingError, "Plugin #{name}: The value in 'replacement' has to be a String" end