lib/omnibus/fetcher.rb in omnibus-1.3.0 vs lib/omnibus/fetcher.rb in omnibus-2.0.0.rc1
- old
+ new
@@ -1,7 +1,7 @@
#
-# Copyright:: Copyright (c) 2012 Opscode, Inc.
+# Copyright:: Copyright (c) 2012-2014 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@@ -16,20 +16,18 @@
#
require 'pp'
module Omnibus
-
# Base class for classes that fetch project sources from the internet.
#
# @abstract Subclass and override the {#clean}, {#description},
# {#fetch}, {#fetch_required?}, and {#version_guid} methods
#
# @todo Is this class supposed to be abstract or not? Pretty sure
# it's supposed to be abstract
class Fetcher
-
# Given an error and a fetcher that generated the error, print a
# formatted report of the error and stacktrace, along with fetcher
# details to stderr.
#
# @note Does not rethrow the error; that must currently be done manually.
@@ -41,11 +39,10 @@
# @todo Also, since we always 'raise' after calling {#explain}, we
# should just go ahead and exit from here. No need to raise,
# since we're already outputting the real error and stacktrace
# here.
class ErrorReporter
-
def initialize(error, fetcher)
@error, @fetcher = error, fetcher
end
# @todo Why not just make an attribute for error?
@@ -59,18 +56,18 @@
# @todo If {Omnibus::Fetcher#description} is meant to show
# parameters (presumably the kind of fetcher and the software it
# is fetching?),
def explain(why)
- $stderr.puts "* " * 40
+ $stderr.puts '* ' * 40
$stderr.puts why
- $stderr.puts "Fetcher params:"
+ $stderr.puts 'Fetcher params:'
$stderr.puts indent(@fetcher.description, 2)
- $stderr.puts "Exception:"
+ $stderr.puts 'Exception:'
$stderr.puts indent("#{e.class}: #{e.message.strip}", 2)
- Array(e.backtrace).each {|l| $stderr.puts indent(l, 4) }
- $stderr.puts "* " * 40
+ Array(e.backtrace).each { |l| $stderr.puts indent(l, 4) }
+ $stderr.puts '* ' * 40
end
private
# Indent each line of a string with `n` spaces.
@@ -80,13 +77,12 @@
#
# @param string [String] the string to indent
# @param n [Fixnum] the number of " " characters to indent each line.
# @return [String]
def indent(string, n)
- string.split("\n").map {|l| " ".rjust(n) << l }.join("\n")
+ string.split("\n").map { |l| ' '.rjust(n) << l }.join("\n")
end
-
end
class UnsupportedSourceLocation < ArgumentError
end
@@ -127,14 +123,14 @@
elsif software.source[:git]
GitFetcher.new(software)
elsif software.source[:path]
PathFetcher.new(software)
else
- raise UnsupportedSourceLocation, "Don't know how to fetch software project #{software}"
+ fail UnsupportedSourceLocation, "Don't know how to fetch software project #{software}"
end
end
- def self.name(name=NULL_ARG)
+ def self.name(name = NULL_ARG)
@name = name unless name.equal?(NULL_ARG)
@name
end
attr_reader :name