Class: Bow::Inventory

Inherits:
Object
  • Object
show all
Defined in:
lib/bow/inventory.rb

Constant Summary collapse

DEFAULT_RAKEFILES =
[
  'Rakefile',
  'rakefile',
  'Rakefile.rb',
  'rakefile.rb'
].freeze
DEFAULT_TARGETFILES =
[
  # 'bow.yaml',
  # 'bow.rb',
  'targets.json'
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInventory

Returns a new instance of Inventory.



22
23
24
25
26
# File 'lib/bow/inventory.rb', line 22

def initialize
  @rakefiles = DEFAULT_RAKEFILES.dup
  @targetfiles = DEFAULT_TARGETFILES.dup
  @original_dir = Dir.pwd
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



20
21
22
# File 'lib/bow/inventory.rb', line 20

def location
  @location
end

#rakefileObject (readonly)

Returns the value of attribute rakefile.



20
21
22
# File 'lib/bow/inventory.rb', line 20

def rakefile
  @rakefile
end

#targetfileObject (readonly)

Returns the value of attribute targetfile.



20
21
22
# File 'lib/bow/inventory.rb', line 20

def targetfile
  @targetfile
end

Instance Method Details

#ensure!Object



41
42
43
44
45
46
47
48
49
50
51
52
# 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

#parseObject



28
29
30
31
32
33
34
# 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?Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/bow/inventory.rb', line 36

def valid?
  parse
  !!(rakefile && targetfile && location)
end