Fix coding standards

This commit is contained in:
Thibault Jouan 2015-05-12 15:02:44 +00:00
parent 658e333420
commit c8b685b8a3
8 changed files with 22 additions and 13 deletions

View File

@ -38,7 +38,8 @@ module Producer
attr_reader :arguments, :stdin, :stdout, :stderr, :env attr_reader :arguments, :stdin, :stdout, :stderr, :env
def initialize(args, environment, stdin: $stdin, stdout: $stdout, stderr: $stderr) def initialize(args, environment, stdin: $stdin, stdout: $stdout,
stderr: $stderr)
@arguments = args @arguments = args
@stdin = stdin @stdin = stdin
@stdout = stdout @stdout = stdout
@ -82,7 +83,7 @@ module Producer
def split_arguments_lists(arguments) def split_arguments_lists(arguments)
arguments arguments
.chunk { |e| e == ARGUMENTS_SEPARATOR } .chunk { |e| e == ARGUMENTS_SEPARATOR }
.reject { |b, a| b } .reject { |a, _| a }
.map &:last .map &:last
end end

View File

@ -7,7 +7,8 @@ module Producer
attr_reader :input, :output, :error_output, :registry, :logger attr_reader :input, :output, :error_output, :registry, :logger
attr_accessor :target, :verbose, :debug, :dry_run, :recipe_argv attr_accessor :target, :verbose, :debug, :dry_run, :recipe_argv
def initialize(input: $stdin, output: $stdout, error_output: $stderr, remote: nil, registry: {}) def initialize(input: $stdin, output: $stdout, error_output: $stderr,
remote: nil, registry: {})
@verbose = @debug = @dry_run = false @verbose = @debug = @dry_run = false
@input = input @input = input
@output = output @output = output

View File

@ -56,7 +56,7 @@ module Producer
end end
def indent_backtrace(backtrace) def indent_backtrace(backtrace)
backtrace.map { |e| ' %s' % e } backtrace.map { |e| ' ' + e }
end end
end end
end end

View File

@ -1,7 +1,7 @@
module Producer module Producer
module Core module Core
class LoggerFormatter < Logger::Formatter class LoggerFormatter < Logger::Formatter
def call(severity, datetime, progname, message) def call(severity, _datetime, _progname, message)
prefix(severity) + message + "\n" prefix(severity) + message + "\n"
end end

View File

@ -26,16 +26,16 @@ module Producer
def execute(command, output = '', error_output = '') def execute(command, output = '', error_output = '')
session.open_channel do |channel| session.open_channel do |channel|
channel.exec command do |ch, success| channel.exec command do |ch, _success|
ch.on_data do |c, data| ch.on_data do |_c, data|
output << data output << data
end end
ch.on_extended_data do |c, type, data| ch.on_extended_data do |_c, _type, data|
error_output << data error_output << data
end end
ch.on_request 'exit-status' do |c, data| ch.on_request 'exit-status' do |_c, data|
exit_status = data.read_long exit_status = data.read_long
fail RemoteCommandExecutionError, command if exit_status != 0 fail RemoteCommandExecutionError, command if exit_status != 0
end end

View File

@ -29,11 +29,11 @@ module Producer
end end
def mkdir(path, attributes = {}) def mkdir(path, attributes = {})
ret = sftp.mkdir! path, attributes sftp.mkdir! path, attributes
end end
def file_read(path) def file_read(path)
sftp.file.open(path) { |f| content = f.read } sftp.file.open(path) { |f| f.read }
rescue Net::SFTP::StatusException rescue Net::SFTP::StatusException
nil nil
end end

View File

@ -52,13 +52,20 @@ module Producer
@actions << self.class.evaluate(@env, name, *args, &block) @actions << self.class.evaluate(@env, name, *args, &block)
end end
def ask(question, choices, prompter: Prompter.new(@env.input, @env.output)) def ask(question, choices, prompter: build_prompter)
prompter.prompt(question, choices) prompter.prompt(question, choices)
end end
def template(path, variables = {}) def template(path, variables = {})
Template.new(path).render variables Template.new(path).render variables
end end
private
def build_prompter
Prompter.new(@env.input, @env.output)
end
end end
end end
end end