From c8b685b8a39db20c5a0402d34b51d5cc2b3b1134 Mon Sep 17 00:00:00 2001 From: Thibault Jouan Date: Tue, 12 May 2015 15:02:44 +0000 Subject: [PATCH] Fix coding standards --- lib/producer/core/cli.rb | 5 +++-- lib/producer/core/env.rb | 3 ++- lib/producer/core/error_formatter.rb | 2 +- lib/producer/core/logger_formatter.rb | 2 +- lib/producer/core/recipe.rb | 2 +- lib/producer/core/remote.rb | 8 ++++---- lib/producer/core/remote/fs.rb | 4 ++-- lib/producer/core/task.rb | 9 ++++++++- 8 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/producer/core/cli.rb b/lib/producer/core/cli.rb index c170de0..e952eca 100644 --- a/lib/producer/core/cli.rb +++ b/lib/producer/core/cli.rb @@ -38,7 +38,8 @@ module Producer 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 @stdin = stdin @stdout = stdout @@ -82,7 +83,7 @@ module Producer def split_arguments_lists(arguments) arguments .chunk { |e| e == ARGUMENTS_SEPARATOR } - .reject { |b, a| b } + .reject { |a, _| a } .map &:last end diff --git a/lib/producer/core/env.rb b/lib/producer/core/env.rb index 998bc57..b3755dc 100644 --- a/lib/producer/core/env.rb +++ b/lib/producer/core/env.rb @@ -7,7 +7,8 @@ module Producer attr_reader :input, :output, :error_output, :registry, :logger 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 @input = input @output = output diff --git a/lib/producer/core/error_formatter.rb b/lib/producer/core/error_formatter.rb index ca40cf8..df891fa 100644 --- a/lib/producer/core/error_formatter.rb +++ b/lib/producer/core/error_formatter.rb @@ -56,7 +56,7 @@ module Producer end def indent_backtrace(backtrace) - backtrace.map { |e| ' %s' % e } + backtrace.map { |e| ' ' + e } end end end diff --git a/lib/producer/core/logger_formatter.rb b/lib/producer/core/logger_formatter.rb index 1bd78de..f50e4ce 100644 --- a/lib/producer/core/logger_formatter.rb +++ b/lib/producer/core/logger_formatter.rb @@ -1,7 +1,7 @@ module Producer module Core class LoggerFormatter < Logger::Formatter - def call(severity, datetime, progname, message) + def call(severity, _datetime, _progname, message) prefix(severity) + message + "\n" end diff --git a/lib/producer/core/recipe.rb b/lib/producer/core/recipe.rb index 194cf4f..d4be0a6 100644 --- a/lib/producer/core/recipe.rb +++ b/lib/producer/core/recipe.rb @@ -46,7 +46,7 @@ module Producer end def compose_macro(name, macro, *base_args) - self.class.class_eval { compose_macro name, macro, *base_args} + self.class.class_eval { compose_macro name, macro, *base_args } end def test_macro(name, &block) diff --git a/lib/producer/core/remote.rb b/lib/producer/core/remote.rb index 42a8f5b..4f49bd0 100644 --- a/lib/producer/core/remote.rb +++ b/lib/producer/core/remote.rb @@ -26,16 +26,16 @@ module Producer def execute(command, output = '', error_output = '') session.open_channel do |channel| - channel.exec command do |ch, success| - ch.on_data do |c, data| + channel.exec command do |ch, _success| + ch.on_data do |_c, data| output << data end - ch.on_extended_data do |c, type, data| + ch.on_extended_data do |_c, _type, data| error_output << data end - ch.on_request 'exit-status' do |c, data| + ch.on_request 'exit-status' do |_c, data| exit_status = data.read_long fail RemoteCommandExecutionError, command if exit_status != 0 end diff --git a/lib/producer/core/remote/fs.rb b/lib/producer/core/remote/fs.rb index 5f6b286..3713980 100644 --- a/lib/producer/core/remote/fs.rb +++ b/lib/producer/core/remote/fs.rb @@ -29,11 +29,11 @@ module Producer end def mkdir(path, attributes = {}) - ret = sftp.mkdir! path, attributes + sftp.mkdir! path, attributes end def file_read(path) - sftp.file.open(path) { |f| content = f.read } + sftp.file.open(path) { |f| f.read } rescue Net::SFTP::StatusException nil end diff --git a/lib/producer/core/task.rb b/lib/producer/core/task.rb index 1b75683..9736525 100644 --- a/lib/producer/core/task.rb +++ b/lib/producer/core/task.rb @@ -52,13 +52,20 @@ module Producer @actions << self.class.evaluate(@env, name, *args, &block) end - def ask(question, choices, prompter: Prompter.new(@env.input, @env.output)) + def ask(question, choices, prompter: build_prompter) prompter.prompt(question, choices) end def template(path, variables = {}) Template.new(path).render variables end + + + private + + def build_prompter + Prompter.new(@env.input, @env.output) + end end end end