Module: AutoC::Module::SmartRenderer

Included in:
Header, Source
Defined in:
lib/autoc/module.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#digestObject (readonly)

def render_contents(stream)



180
181
182
# File 'lib/autoc/module.rb', line 180

def digest
  @digest
end

Instance Method Details

#renderObject



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/autoc/module.rb', line 182

def render
  io = stream
  _file_name = io.path # Memorize temporary file name
  begin
    begin
      render_contents(io)
      @digest = io.digest
    ensure
      io.close
    end
  rescue
    File.unlink(_file_name) # Remove improperly rendered temporary file
    raise
  else
    if !File.exist?(file_name) || self.module.digests[file_name] != digest
      File.rename(_file_name, file_name) # Rendered temporary has different digest - replace original permanent file with it
    else
      File.unlink(_file_name) # New temporary has the same digest as permanent - no need to replace the latter, delete the temporary instead
    end
  end
end