Class: GitTest::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/git_test/writer.rb

Overview

takes a path, a name (file name) and a report makes directory if not present writes the given report to the file name in that path

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, notify = Notify.new) ⇒ Writer

Returns a new instance of Writer.



11
12
13
14
15
16
# File 'lib/git_test/writer.rb', line 11

def initialize(options, notify = Notify.new)
  self.path   = options[:path]
  self.name   = options[:name]
  self.report = options[:report]
  self.notify = notify
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/git_test/writer.rb', line 9

def name
  @name
end

#notifyObject

Returns the value of attribute notify.



9
10
11
# File 'lib/git_test/writer.rb', line 9

def notify
  @notify
end

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/git_test/writer.rb', line 9

def path
  @path
end

#reportObject

Returns the value of attribute report.



9
10
11
# File 'lib/git_test/writer.rb', line 9

def report
  @report
end

Class Method Details

.save(*args) ⇒ Object



32
33
34
# File 'lib/git_test/writer.rb', line 32

def self.save(*args)
  self.new(*args).save
end

Instance Method Details

#full_pathObject



23
24
25
# File 'lib/git_test/writer.rb', line 23

def full_path
  File.join(path, name)
end

#mkdir!Object



19
20
21
# File 'lib/git_test/writer.rb', line 19

def mkdir!
  FileUtils.mkdir_p(path)
end

#saveObject Also known as: save!



36
37
38
39
# File 'lib/git_test/writer.rb', line 36

def save
  notify.start("Writing report to #{full_path}")
  write_report_to_disk!
end

#show_reportObject



42
43
44
# File 'lib/git_test/writer.rb', line 42

def show_report
  system "open #{}"
end

#write_report_to_disk!Object



27
28
29
30
# File 'lib/git_test/writer.rb', line 27

def write_report_to_disk!
  mkdir!
  File.open(full_path, 'w') {|f| f.write(report) }
end