lib/roadie/errors.rb in roadie-4.0.0 vs lib/roadie/errors.rb in roadie-5.0.0

- old
+ new

@@ -16,14 +16,14 @@ # The original error, raised from +URI+. attr_reader :cause def initialize(given_path, cause = nil) @cause = cause - if cause - cause_message = " Caused by: #{cause}" + cause_message = if cause + " Caused by: #{cause}" else - cause_message = "" + "" end super "Cannot use path \"#{given_path}\" in URL generation.#{cause_message}" end end @@ -41,43 +41,47 @@ attr_reader :provider # Extra message attr_reader :extra_message - # TODO: Change signature in the next major version of Roadie. - def initialize(css_name, extra_message = nil, provider = nil) + def initialize(css_name:, message: nil, provider: nil) @css_name = css_name @provider = provider - @extra_message = extra_message - super build_message(extra_message) + @extra_message = message + super build_message end protected + def error_row - "#{provider || "Unknown provider"}: #{extra_message || message}" + "#{provider || "Unknown provider"}: #{extra_message}" end private - # Redundant method argument is to keep API compatability without major version bump. - # TODO: Remove argument on version 4.0. - def build_message(extra_message = @extra_message) + + def build_message message = +%(Could not find stylesheet "#{css_name}") message << ": #{extra_message}" if extra_message message << "\nUsed provider:\n#{provider}" if provider message end end class ProvidersFailed < CssNotFound attr_reader :errors - def initialize(css_name, provider_list, errors) + def initialize(css_name:, providers:, errors:) @errors = errors - super(css_name, "All providers failed", provider_list) + super( + css_name: css_name, + message: "All providers failed", + provider: providers + ) end private - def build_message(extra_message) + + def build_message message = +%(Could not find stylesheet "#{css_name}": #{extra_message}\nUsed providers:\n) each_error_row(errors) do |row| message << "\t" << row << "\n" end message