Module: InlineFormsInstaller::CreateLog
- Defined in:
- lib/inline_forms_installer/create_log.rb
Class Method Summary collapse
- .append_section(path, title, body) ⇒ Object
- .basename_for(started_at = Time.now) ⇒ Object
- .final_path(app_name, started_at = Time.now) ⇒ Object
- .tee_rails_new(app_name, shell_command, started_at: Time.now) ⇒ Object
Class Method Details
.append_section(path, title, body) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/inline_forms_installer/create_log.rb', line 39 def append_section(path, title, body) return if path.to_s.strip.empty? FileUtils.mkdir_p(File.dirname(path)) File.open(path, "a") { |f| f.puts "\n=== #{title} ===\n#{body}" } end |
.basename_for(started_at = Time.now) ⇒ Object
9 10 11 |
# File 'lib/inline_forms_installer/create_log.rb', line 9 def basename_for(started_at = Time.now) "inline_forms_create-#{started_at.strftime('%Y%m%d-%H%M%S')}.log" end |
.final_path(app_name, started_at = Time.now) ⇒ Object
13 14 15 |
# File 'lib/inline_forms_installer/create_log.rb', line 13 def final_path(app_name, started_at = Time.now) File.(File.join(app_name, "log", basename_for(started_at))) end |
.tee_rails_new(app_name, shell_command, started_at: Time.now) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/inline_forms_installer/create_log.rb', line 17 def tee_rails_new(app_name, shell_command, started_at: Time.now) final = final_path(app_name, started_at) tmp = File.(basename_for(started_at)) ENV["INLINE_FORMS_INSTALLER_LOG"] = final ENV["INLINE_FORMS_CREATE_STARTED_AT"] = started_at.iso8601 ok = system( "bash", "-c", "#{shell_command} 2>&1 | tee #{Shellwords.escape(tmp)}; exit ${PIPESTATUS[0]}" ) if ok && File.directory?(app_name) FileUtils.mkdir_p(File.join(app_name, "log")) FileUtils.mv(tmp, final) if File.exist?(tmp) elsif File.exist?(tmp) FileUtils.mkdir_p(File.dirname(final)) FileUtils.mv(tmp, final) end [ok, final] end |