Class: Zeno::Makefile

Inherits:
FileGenerator show all
Defined in:
lib/zeno/makefile.rb

Instance Attribute Summary

Attributes inherited from FileGenerator

#path, #vars

Instance Method Summary collapse

Methods inherited from FileGenerator

#add_var, #del_var

Constructor Details

#initialize(path) ⇒ Makefile

Returns a new instance of Makefile.



23
24
25
26
# File 'lib/zeno/makefile.rb', line 23

def initialize(path)
  super
  @targets = Hash.new
end

Instance Method Details

#add_target(target, rules) ⇒ Object



28
29
30
# File 'lib/zeno/makefile.rb', line 28

def add_target(target, rules)
  @targets[target] = rules
end

#generateObject



32
33
34
35
36
37
38
# File 'lib/zeno/makefile.rb', line 32

def generate
  File.open(@path, 'w') do |makefile|
    makefile.puts self.to_s
  end

  nil
end

#to_sObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/zeno/makefile.rb', line 40

def to_s
  output = super

  output += "\n"
  @targets.each do |key, value|
    output += "#{key}:\n"
    if value.is_a? Array
      value.each do |e|
        output += "\t#{e}\n"
      end
    else
      output += "\t#{value}\n"
    end

    output += "\n"
  end

  output
end