Module: DebtCeiling

Extended by:
DebtCeiling, Forwardable
Includes:
Configurations
Included in:
DebtCeiling
Defined in:
lib/debt_ceiling.rb,
lib/debt_ceiling/debt.rb,
lib/debt_ceiling/version.rb,
lib/debt_ceiling/accounting.rb

Defined Under Namespace

Classes: Accounting, Debt

Constant Summary collapse

VERSION =
'0.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#debtObject (readonly)

Returns the value of attribute debt.



11
12
13
# File 'lib/debt_ceiling.rb', line 11

def debt
  @debt
end

Instance Method Details

#blacklist_matching(matchers) ⇒ Object



51
52
53
# File 'lib/debt_ceiling.rb', line 51

def blacklist_matching(matchers)
  @blacklist = matchers.map { |matcher| Regexp.new(matcher) }
end

#calculate(dir = '.', opts = {preconfigured: false}) ⇒ Object



45
46
47
48
49
# File 'lib/debt_ceiling.rb', line 45

def calculate(dir = '.', opts={preconfigured: false})
  load_configuration unless @loaded || opts[:preconfigured]
  @debt = DebtCeiling::Accounting.calculate(dir)
  evaluate
end

#debt_per_reference_to(string, value) ⇒ Object



60
61
62
# File 'lib/debt_ceiling.rb', line 60

def debt_per_reference_to(string, value)
  deprecated_reference_pairs[string] = value
end

#evaluateObject



65
66
67
68
69
70
71
72
73
# File 'lib/debt_ceiling.rb', line 65

def evaluate
  if debt_ceiling && debt_ceiling <= debt
    fail_test
  elsif reduction_target && reduction_target <= debt &&
        Time.now > reduction_date
    fail_test
  end
  debt
end

#fail_testObject



75
76
77
# File 'lib/debt_ceiling.rb', line 75

def fail_test
  Kernel.exit 1
end

#load_configurationObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/debt_ceiling.rb', line 32

def load_configuration
  if File.exist?(Dir.pwd + '/.debt_ceiling.rb')
    load(Dir.pwd + '/.debt_ceiling.rb')
  elsif File.exist?(Dir.home + '/.debt_ceiling.rb')
    load(Dir.home + '/.debt_ceiling.rb')
  else
    puts "No .debt_ceiling.rb configuration file detected in #{Dir.pwd} or ~/, using defaults"
  end

  load extension_path if extension_path && File.exist?(extension_path)
  @loaded = true
end

#whitelist_matching(matchers) ⇒ Object



55
56
57
# File 'lib/debt_ceiling.rb', line 55

def whitelist_matching(matchers)
  @whitelist =  matchers.map { |matcher| Regexp.new(matcher) }
end