class Epuber::Compiler::FileTypes::SourceFile

Attributes

abs_source_path[RW]

@return [String] absolute source path

file_request[RW]

@return [Epuber::Book::FileRequest]

source_path[R]

@return [String] relative source path

Public Class Methods

new(source_path) click to toggle source

@param [String] source_path relative path from project root to source file

# File lib/epuber/compiler/file_types/source_file.rb, line 25
def initialize(source_path)
  @source_path = source_path
end

Public Instance Methods

default_file_copy() click to toggle source
# File lib/epuber/compiler/file_types/source_file.rb, line 83
def default_file_copy
  if destination_file_up_to_date?
    UI.print_processing_debug_info("Destination path #{pkg_destination_path} is up-to-date")
  else
    UI.print_processing_debug_info("Copying to #{pkg_destination_path}")
    self.class.file_copy!(abs_source_path, final_destination_path)
  end

  update_metadata!
end
destination_file_exist?() click to toggle source

Final destination path exist

@return [Bool]

# File lib/epuber/compiler/file_types/source_file.rb, line 70
def destination_file_exist?
  File.exist?(final_destination_path)
end
destination_file_up_to_date?() click to toggle source

Source file does not change from last build of this target

@return [Bool]

# File lib/epuber/compiler/file_types/source_file.rb, line 55
def destination_file_up_to_date?
  return false unless compilation_context.incremental_build?

  source_db = compilation_context.source_file_database
  target_db = compilation_context.target_file_database

  destination_file_exist? && # destination file must exist
    target_db.up_to_date?(source_path) && # source file must be up-to-date from last build of this target
    source_db.file_stat_for(source_path) == target_db.file_stat_for(source_path)
end
find_dependencies() click to toggle source

return [Array<String>]

# File lib/epuber/compiler/file_types/source_file.rb, line 31
def find_dependencies
  []
end
process(_compilation_context) click to toggle source
# File lib/epuber/compiler/file_types/source_file.rb, line 35
def process(_compilation_context)
  # do nothing
end
source_file_up_to_date?() click to toggle source

Source file does not change from last build @warning Using only this method can cause not updating files that are different for targets

@return [Bool]

# File lib/epuber/compiler/file_types/source_file.rb, line 44
def source_file_up_to_date?
  return false unless compilation_context.incremental_build?

  source_db = compilation_context.source_file_database
  source_db.up_to_date?(source_path)
end
update_metadata!() click to toggle source

Updates information about source file in file databases

@return [nil]

# File lib/epuber/compiler/file_types/source_file.rb, line 78
def update_metadata!
  compilation_context.source_file_database.update_metadata(source_path)
  compilation_context.target_file_database.update_metadata(source_path)
end
write_compiled(content) click to toggle source
# File lib/epuber/compiler/file_types/source_file.rb, line 94
def write_compiled(content)
  if self.class.write_to_file?(content, final_destination_path)
    UI.print_processing_debug_info("Writing compiled version to #{pkg_destination_path}")
    self.class.write_to_file!(content, final_destination_path)
  else
    UI.print_processing_debug_info("Not writing to disk ... compiled version at #{pkg_destination_path} is same")
  end
end
write_processed(content) click to toggle source
# File lib/epuber/compiler/file_types/source_file.rb, line 103
def write_processed(content)
  if self.class.write_to_file?(content, final_destination_path)
    UI.print_processing_debug_info("Writing processed version to #{pkg_destination_path}")
    self.class.write_to_file!(content, final_destination_path)
  else
    UI.print_processing_debug_info("Not writing to disk ... processed version at #{pkg_destination_path} is same")
  end
end