Class: Epuber::Compiler::FileTypes::SourceFile
- Inherits:
-
AbstractFile
- Object
- AbstractFile
- Epuber::Compiler::FileTypes::SourceFile
- Defined in:
- lib/epuber/compiler/file_types/source_file.rb
Direct Known Subclasses
CoffeeScriptFile, ImageFile, StaticFile, StylusFile, XHTMLFile, Plugin::PluginFile
Instance Attribute Summary collapse
-
#abs_source_path ⇒ String
Absolute source path.
- #file_request ⇒ Epuber::Book::FileRequest
-
#source_path ⇒ String
readonly
Relative source path.
Attributes inherited from AbstractFile
#compilation_context, #destination_path, #final_destination_path, #group, #path_type, #pkg_destination_path, #properties
Instance Method Summary collapse
- #default_file_copy ⇒ Object
-
#destination_file_exist? ⇒ Bool
Final destination path exist.
-
#destination_file_up_to_date? ⇒ Bool
Source file does not change from last build of this target.
-
#find_dependencies ⇒ Object
return [Array<String>].
-
#initialize(source_path) ⇒ SourceFile
constructor
A new instance of SourceFile.
- #process(_compilation_context) ⇒ Object
-
#source_file_up_to_date? ⇒ Bool
Source file does not change from last build.
-
#update_metadata! ⇒ nil
Updates information about source file in file databases.
- #write_compiled(content) ⇒ Object
- #write_processed(content) ⇒ Object
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.
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_path ⇒ String
Returns 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_request ⇒ Epuber::Book::FileRequest
21 22 23 |
# File 'lib/epuber/compiler/file_types/source_file.rb', line 21 def file_request @file_request end |
#source_path ⇒ String (readonly)
Returns 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_copy ⇒ Object
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 end |
#destination_file_exist? ⇒ Bool
Final destination path exist
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
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_dependencies ⇒ Object
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
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
78 79 80 81 |
# File 'lib/epuber/compiler/file_types/source_file.rb', line 78 def 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 |