Class: Mkduino::GeneratedFile

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

Direct Known Subclasses

AutogenSh, ConfigureAc, MakefileAm

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_filename, options = {}) ⇒ GeneratedFile

Returns a new instance of GeneratedFile.



8
9
10
11
12
13
14
15
16
17
# File 'lib/file_generator.rb', line 8

def initialize output_filename, options = {}
  @output_filename = output_filename
  @output_directory = options[:output_directory] || '.' + File::SEPARATOR
  @backup_directory = options[:backup_directory] || 'generated'
  @user_updates_file = options[:user_updates_file] || @output_filename + ".patch"

  @output_directory = @output_directory + File::SEPARATOR unless @output_directory[-1] == File::SEPARATOR
  @backup_directory = @backup_directory + File::SEPARATOR unless @backup_directory[-1] == File::SEPARATOR
  puts "GeneratedFile.output_filename " + @output_filename
end

Instance Attribute Details

#backup_directoryObject

Returns the value of attribute backup_directory.



6
7
8
# File 'lib/file_generator.rb', line 6

def backup_directory
  @backup_directory
end

#output_directoryObject

Returns the value of attribute output_directory.



5
6
7
# File 'lib/file_generator.rb', line 5

def output_directory
  @output_directory
end

#output_filenameObject

Returns the value of attribute output_filename.



5
6
7
# File 'lib/file_generator.rb', line 5

def output_filename
  @output_filename
end

#user_updates_fileObject

Returns the value of attribute user_updates_file.



6
7
8
# File 'lib/file_generator.rb', line 6

def user_updates_file
  @user_updates_file
end

Instance Method Details

#apply_user_updatesObject



40
41
42
# File 'lib/file_generator.rb', line 40

def apply_user_updates
  `patch < #{user_updates_file}`
end

#save_fileObject



25
26
27
28
29
30
# File 'lib/file_generator.rb', line 25

def save_file
  unless Dir.exist?(@backup_directory)
    Dir.mkdir(@backup_directory)
  end
  File::cp("#{output_directory}#{@output_filename}",@backup_directory)
end

#save_user_updatesObject



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

def save_user_updates
  if(Pathname.new("#{output_directory}#{@output_file}").exist? &&
     Pathname.new("#{@backup_directory}#{@output_file}"))
    `diff -u #{@backup_directory}#{output_file} #{@output_directory}#{output_file} > #{user_updates_file}`
  end

end

#write_fileObject



19
20
21
22
23
# File 'lib/file_generator.rb', line 19

def write_file
  File.open("#{@output_directory}#{@output_filename}","w") do |f|
    yield f
  end
end