Class: Mkduino::GeneratedFile
- Inherits:
-
Object
- Object
- Mkduino::GeneratedFile
- Defined in:
- lib/file_generator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#backup_directory ⇒ Object
Returns the value of attribute backup_directory.
-
#output_directory ⇒ Object
Returns the value of attribute output_directory.
-
#output_filename ⇒ Object
Returns the value of attribute output_filename.
-
#user_updates_file ⇒ Object
Returns the value of attribute user_updates_file.
Instance Method Summary collapse
- #apply_user_updates ⇒ Object
-
#initialize(output_filename, options = {}) ⇒ GeneratedFile
constructor
A new instance of GeneratedFile.
- #save_file ⇒ Object
- #save_user_updates ⇒ Object
- #write_file ⇒ Object
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, = {} @output_filename = output_filename @output_directory = [:output_directory] || '.' + File::SEPARATOR @backup_directory = [:backup_directory] || 'generated' @user_updates_file = [: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_directory ⇒ Object
Returns the value of attribute backup_directory.
6 7 8 |
# File 'lib/file_generator.rb', line 6 def backup_directory @backup_directory end |
#output_directory ⇒ Object
Returns the value of attribute output_directory.
5 6 7 |
# File 'lib/file_generator.rb', line 5 def output_directory @output_directory end |
#output_filename ⇒ Object
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_file ⇒ Object
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_updates ⇒ Object
40 41 42 |
# File 'lib/file_generator.rb', line 40 def apply_user_updates `patch < #{user_updates_file}` end |
#save_file ⇒ Object
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_updates ⇒ Object
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_file ⇒ Object
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 |