Class: Sitespec::Writer
- Inherits:
-
Object
- Object
- Sitespec::Writer
- Defined in:
- lib/sitespec/writer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #color(text) ⇒ Object
- #create ⇒ Object
- #create_with_output ⇒ Object
- #create_with_output_and_build_count ⇒ Object
-
#initialize(request, response) ⇒ Writer
constructor
A new instance of Writer.
- #mkpath ⇒ Object
- #path ⇒ Object
- #puts(text) ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(request, response) ⇒ Writer
Returns a new instance of Writer.
8 9 10 11 |
# File 'lib/sitespec/writer.rb', line 8 def initialize(request, response) @request = request @response = response end |
Class Method Details
.write(*args) ⇒ Object
4 5 6 |
# File 'lib/sitespec/writer.rb', line 4 def self.write(*args) new(*args).write end |
Instance Method Details
#color(text) ⇒ Object
38 39 40 |
# File 'lib/sitespec/writer.rb', line 38 def color(text) RSpec.configuration.color_enabled? ? "\e[32m#{text}\e[0m" : text end |
#create ⇒ Object
26 27 28 |
# File 'lib/sitespec/writer.rb', line 26 def create path.open("w") {|file| file << @response.body } end |
#create_with_output ⇒ Object
30 31 32 |
# File 'lib/sitespec/writer.rb', line 30 def create_with_output create.tap { puts "#{color(?✔)} #{path}" } end |
#create_with_output_and_build_count ⇒ Object
34 35 36 |
# File 'lib/sitespec/writer.rb', line 34 def create_with_output_and_build_count create_with_output.tap { Sitespec.build_count += 1 } end |
#mkpath ⇒ Object
22 23 24 |
# File 'lib/sitespec/writer.rb', line 22 def mkpath path.parent.mkpath end |
#path ⇒ Object
18 19 20 |
# File 'lib/sitespec/writer.rb', line 18 def path @path ||= Pathname.new("#{Sitespec.configuration.build_path}#{@request.uri.path}") end |
#puts(text) ⇒ Object
42 43 44 |
# File 'lib/sitespec/writer.rb', line 42 def puts(text) RSpec.configuration.formatters[0].output.puts text end |
#write ⇒ Object
13 14 15 16 |
# File 'lib/sitespec/writer.rb', line 13 def write mkpath create_with_output_and_build_count end |