Class: Ritsu::SrcFiles::TemplatedSrcFile

Inherits:
Ritsu::SrcFile show all
Defined in:
lib/ritsu/src_files/templated_src_file.rb

Instance Attribute Summary collapse

Attributes inherited from Ritsu::SrcFile

#owner, #src_path

Instance Method Summary collapse

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

platform

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, options={})
  super(src_path, owner)
  
  options = {
    :block_start_prefix => "//<<", 
    :block_end_prefix => "//>>"
  }.merge(options)
  @block_start_prefix = options[:block_start_prefix]
  @block_end_prefix = options[:block_end_prefix]
end

Instance Attribute Details

#block_end_prefixObject

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_prefixObject

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

#templateObject

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

#createObject



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_contentObject



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