Class: Epuber::Compiler::FileTypes::SourceFile

Inherits:
AbstractFile
  • Object
show all
Defined in:
lib/epuber/compiler/file_types/source_file.rb

Instance Attribute Summary collapse

Attributes inherited from AbstractFile

#compilation_context, #destination_path, #final_destination_path, #group, #path_type, #pkg_destination_path, #properties

Instance Method Summary collapse

Methods inherited from AbstractFile

#==, file_copy!, write_to_file, write_to_file!, write_to_file?

Constructor Details

#initialize(source_path) ⇒ SourceFile

Returns a new instance of SourceFile.

Parameters:

  • source_path (String)

    relative path from project root to source file



25
26
27
# File 'lib/epuber/compiler/file_types/source_file.rb', line 25

def initialize(source_path)
  @source_path = source_path
end

Instance Attribute Details

#abs_source_pathString

Returns absolute source path.

Returns:

  • (String)

    absolute source path



17
18
19
# File 'lib/epuber/compiler/file_types/source_file.rb', line 17

def abs_source_path
  @abs_source_path
end

#file_requestEpuber::Book::FileRequest



21
22
23
# File 'lib/epuber/compiler/file_types/source_file.rb', line 21

def file_request
  @file_request
end

#source_pathString (readonly)

Returns relative source path.

Returns:

  • (String)

    relative source path



13
14
15
# File 'lib/epuber/compiler/file_types/source_file.rb', line 13

def source_path
  @source_path
end

Instance Method Details

#default_file_copyObject



83
84
85
86
87
88
89
90
91
92
# 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?Bool

Final destination path exist

Returns:

  • (Bool)


70
71
72
# 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?Bool

Source file does not change from last build of this target

Returns:

  • (Bool)


55
56
57
58
59
60
61
62
63
64
# 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_dependenciesObject

return [Array<String>]



31
32
33
# File 'lib/epuber/compiler/file_types/source_file.rb', line 31

def find_dependencies
  []
end

#process(_compilation_context) ⇒ Object



35
36
37
# File 'lib/epuber/compiler/file_types/source_file.rb', line 35

def process(_compilation_context)
  # do nothing
end

#source_file_up_to_date?Bool

Source file does not change from last build

Returns:

  • (Bool)


44
45
46
47
48
49
# 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!nil

Updates information about source file in file databases

Returns:

  • (nil)


78
79
80
81
# File 'lib/epuber/compiler/file_types/source_file.rb', line 78

def update_metadata!
  compilation_context.source_file_database.(source_path)
  compilation_context.target_file_database.(source_path)
end

#write_compiled(content) ⇒ Object



94
95
96
97
98
99
100
101
# 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) ⇒ Object



103
104
105
106
107
108
109
110
# 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