Class: NestedFile::PutFile

Inherits:
Object
  • Object
show all
Includes:
FromHash
Defined in:
lib/nested_file/put_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#convert_pathObject

Returns the value of attribute convert_path.



4
5
6
# File 'lib/nested_file/put_file.rb', line 4

def convert_path
  @convert_path
end

#filenameObject

Returns the value of attribute filename.



4
5
6
# File 'lib/nested_file/put_file.rb', line 4

def filename
  @filename
end

#raw_bodyObject

Returns the value of attribute raw_body.



4
5
6
# File 'lib/nested_file/put_file.rb', line 4

def raw_body
  @raw_body
end

Instance Method Details

#write_all!(file = nil) ⇒ Object



38
39
40
41
# File 'lib/nested_file/put_file.rb', line 38

def write_all!(file=nil)
  write_subs!
  write_self!(file)
end

#write_self!(file = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/nested_file/put_file.rb', line 27

def write_self!(file=nil)
  res = raw_body.gsub(/<file (.+?)>(.*?)<\/file>/m) do
    "<file #{$1}>\n</file>"
  end
 
  if file
    file.write res
  else
    File.create filename, res
  end
end

#write_subs!Object



19
20
21
22
23
24
25
26
# File 'lib/nested_file/put_file.rb', line 19

def write_subs!
  raw_body.scan(/<file (.+?)>(.*?)<\/file>/m) do |m|
    sub_file, sub_body = *m
    #ff = File.expand_path(sub_file,File.dirname(filename))
    full = convert_path.mount_to_parent_if_relative(sub_file)
    FileSection::Write.new(parent_body: sub_body, full_file_to_insert: full).write!
  end
end