-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
132 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
require_relative '../lib/debt_ceiling' | ||
DebtCeiling.calculate(ARGV[0] ? ARGV[0] : '.') | ||
DebtCeiling.audit(ARGV[0] ? ARGV[0] : '.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module DebtCeiling | ||
class Audit | ||
extend Forwardable | ||
include CommonMethods | ||
undef :+ | ||
|
||
CONFIG_FILE_NAME = ".debt_ceiling.rb" | ||
CONFIG_LOCATIONS = ["#{Dir.pwd}/#{CONFIG_FILE_NAME}", "#{Dir.home}/#{CONFIG_FILE_NAME}"] | ||
NO_CONFIG_FOUND = "No #{CONFIG_FILE_NAME} configuration file detected in #{Dir.pwd} or ~/, using defaults" | ||
|
||
attr_reader :accounting, :dir, :loaded | ||
|
||
def_delegators :configuration, | ||
:extension_path, :debt_ceiling, :reduction_target, :reduction_date, :max_debt_per_module | ||
|
||
def_delegator :accounting, :total_debt | ||
|
||
def initialize(dir = '.', opts = {}) | ||
@loaded = opts[:preconfigured] | ||
@dir = dir | ||
@accounting = perform_accounting | ||
accounting.print_results unless opts[:skip_report] | ||
fail_test if failed_condition? | ||
end | ||
|
||
private | ||
|
||
def load_configuration | ||
config_file_location ? load(config_file_location) : puts(NO_CONFIG_FOUND) | ||
|
||
load extension_path if extension_path && File.exist?(extension_path) | ||
@loaded = true | ||
end | ||
|
||
def config_file_location | ||
CONFIG_LOCATIONS.find {|loc| File.exist?(loc) } | ||
end | ||
|
||
def perform_accounting | ||
load_configuration unless loaded | ||
Accounting.new(dir) | ||
end | ||
|
||
def blacklist_matching(matchers) | ||
@blacklist = matchers.map { |matcher| Regexp.new(matcher) } | ||
end | ||
|
||
def whitelist_matching(matchers) | ||
@whitelist = matchers.map { |matcher| Regexp.new(matcher) } | ||
end | ||
|
||
|
||
def debt_per_reference_to(string, value) | ||
deprecated_reference_pairs[string] = value | ||
end | ||
|
||
def failed_condition? | ||
exceeded_total_limit? || missed_target? || max_debt_per_module_exceeded? | ||
end | ||
|
||
def exceeded_total_limit? | ||
debt_ceiling && debt_ceiling <= total_debt | ||
end | ||
|
||
def missed_target? | ||
reduction_target && reduction_target <= total_debt && | ||
Time.now > Chronic.parse(reduction_date) | ||
end | ||
|
||
def max_debt_per_module_exceeded? | ||
max_debt_per_module && max_debt_per_module <= accounting.max_debt.to_i | ||
end | ||
|
||
def fail_test | ||
at_exit do | ||
Kernel.exit 1 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module DebtCeiling | ||
module CommonMethods | ||
|
||
def configuration | ||
DebtCeiling.configuration | ||
end | ||
|
||
def +(other) | ||
self.to_i + other.to_i | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.