Class: Ritsu::SrcFiles::TemplatedSrcFile
- Inherits:
-
Ritsu::SrcFile
- Object
- Ritsu::SrcFile
- Ritsu::SrcFiles::TemplatedSrcFile
- Defined in:
- lib/ritsu/src_files/templated_src_file.rb
Direct Known Subclasses
ProjectCmakeLists, ProjectConfigHeaderTemplateFile, TargetCmakeLists
Instance Attribute Summary collapse
-
#block_end_prefix ⇒ Object
Returns the value of attribute block_end_prefix.
-
#block_start_prefix ⇒ Object
Returns the value of attribute block_start_prefix.
-
#template ⇒ Object
Returns the value of attribute template.
Attributes inherited from Ritsu::SrcFile
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(src_path, owner, options = {}) ⇒ TemplatedSrcFile
constructor
A new instance of TemplatedSrcFile.
- #update_content ⇒ Object
Methods inherited from Ritsu::SrcFile
#abs_path, #base_name, find_by_src_path, #include_in_source_files?, is_valid_src_path?, #project, #remove, #update, validate_instance
Methods included from Utility
Methods included from Utility::InstanceSet
included, #initialize_instance
Constructor Details
#initialize(src_path, owner, options = {}) ⇒ TemplatedSrcFile
Returns a new instance of TemplatedSrcFile.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ritsu/src_files/templated_src_file.rb', line 12 def initialize(src_path, owner, ={}) super(src_path, owner) = { :block_start_prefix => "//<<", :block_end_prefix => "//>>" }.merge() @block_start_prefix = [:block_start_prefix] @block_end_prefix = [:block_end_prefix] end |
Instance Attribute Details
#block_end_prefix ⇒ Object
Returns the value of attribute block_end_prefix.
10 11 12 |
# File 'lib/ritsu/src_files/templated_src_file.rb', line 10 def block_end_prefix @block_end_prefix end |
#block_start_prefix ⇒ Object
Returns the value of attribute block_start_prefix.
9 10 11 |
# File 'lib/ritsu/src_files/templated_src_file.rb', line 9 def block_start_prefix @block_start_prefix end |
#template ⇒ Object
Returns the value of attribute template.
8 9 10 |
# File 'lib/ritsu/src_files/templated_src_file.rb', line 8 def template @template end |
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/ritsu/src_files/templated_src_file.rb', line 23 def create block = template.create_block( :block_start_prefix => block_start_prefix, :block_end_prefix => block_end_prefix) template.update_block(block, :block_start_prefix => block_start_prefix, :block_end_prefix => block_end_prefix) Ritsu::Utility::FileRobot.create_file(abs_path, block.to_s(:no_delimiter=>true) + "\n") end |
#update_content ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ritsu/src_files/templated_src_file.rb', line 33 def update_content file_content = Ritsu::Utility::Files.read(abs_path) block = Ritsu::Block.parse(file_content, :block_start_prefix => block_start_prefix, :block_end_prefix => block_end_prefix) template.update_block(block, :block_start_prefix => block_start_prefix, :block_end_prefix => block_end_prefix) new_content = block.to_s(:no_delimiter=>true) + "\n" if new_content != file_content Ritsu::Utility::FileRobot.create_file(abs_path, new_content) end end |