class Bow::Inventory

Constants

DEFAULT_RAKEFILES
DEFAULT_TARGETFILES

Attributes

location[R]
rakefile[R]
targetfile[R]

Public Class Methods

new() click to toggle source
# File lib/bow/inventory.rb, line 22
def initialize
  @rakefiles = DEFAULT_RAKEFILES.dup
  @targetfiles = DEFAULT_TARGETFILES.dup
  @original_dir = Dir.pwd
end

Public Instance Methods

ensure!() click to toggle source
# File lib/bow/inventory.rb, line 41
def ensure!
  parse
  [
    ['Rakefile', @rakefile, @rakefiles],
    ['Target file', @targetfile, @targetfiles]
  ].each do |name, file, variants|
    unless file
      raise "No #{name} found (looking for: #{variants.join(', ')})"
    end
  end
  self
end
parse() click to toggle source
# File lib/bow/inventory.rb, line 28
def parse
  return if @inventory_loaded
  rakefile, targetfile, @location = inventory_location
  @rakefile = File.join(@location, rakefile) if rakefile
  @targetfile = File.join(@location, targetfile) if targetfile
  @inventory_loaded = true
end
valid?() click to toggle source
# File lib/bow/inventory.rb, line 36
def valid?
  parse
  !!(rakefile && targetfile && location)
end

Private Instance Methods

detect_files(variants) click to toggle source
# File lib/bow/inventory.rb, line 80
def detect_files(variants)
  variants.detect { |fn| File.exist?(fn) }
end
inspect_dir() click to toggle source
# File lib/bow/inventory.rb, line 74
def inspect_dir
  rakefile = detect_files(@rakefiles)
  targetfile = detect_files(@targetfiles)
  [rakefile, targetfile]
end
inventory_location() click to toggle source
# File lib/bow/inventory.rb, line 56
def inventory_location
  reset_path do
    here = @original_dir
    until (files = inspect_dir)
      break if here == '/'
      Dir.chdir('..')
      here = Dir.pwd
    end
    [files, here].flatten
  end
end
reset_path() { || ... } click to toggle source
# File lib/bow/inventory.rb, line 68
def reset_path
  yield
ensure
  Dir.chdir(@original_dir)
end