Module: RakeDocker::Output
- Defined in:
- lib/rake_docker/output.rb
Class Method Summary collapse
- .line_includes_aux?(json) ⇒ Boolean
- .line_includes_error?(json) ⇒ Boolean
- .line_includes_id?(json) ⇒ Boolean
- .line_includes_progress?(json) ⇒ Boolean
- .line_includes_status?(json) ⇒ Boolean
- .line_includes_status_and_id?(json) ⇒ Boolean
- .line_includes_stream?(json) ⇒ Boolean
- .line_skippable?(json) ⇒ Boolean
- .parse(chunk) ⇒ Object
- .parse_line(line) ⇒ Object
- .print(chunk) ⇒ Object
- .to_error(json) ⇒ Object
- .to_fallthrough(line) ⇒ Object
- .to_skipped(_) ⇒ Object
- .to_status(json) ⇒ Object
- .to_status_with_id(json) ⇒ Object
- .to_stream(json) ⇒ Object
- .to_unparseable(line) ⇒ Object
- .try_parse_json(line) ⇒ Object
Class Method Details
.line_includes_aux?(json) ⇒ Boolean
55 56 57 |
# File 'lib/rake_docker/output.rb', line 55 def self.line_includes_aux?(json) json['aux'] end |
.line_includes_error?(json) ⇒ Boolean
59 60 61 |
# File 'lib/rake_docker/output.rb', line 59 def self.line_includes_error?(json) json['error'] end |
.line_includes_id?(json) ⇒ Boolean
43 44 45 |
# File 'lib/rake_docker/output.rb', line 43 def self.line_includes_id?(json) json['id'] end |
.line_includes_progress?(json) ⇒ Boolean
51 52 53 |
# File 'lib/rake_docker/output.rb', line 51 def self.line_includes_progress?(json) json['progress'] end |
.line_includes_status?(json) ⇒ Boolean
47 48 49 |
# File 'lib/rake_docker/output.rb', line 47 def self.line_includes_status?(json) json['status'] end |
.line_includes_status_and_id?(json) ⇒ Boolean
67 68 69 70 |
# File 'lib/rake_docker/output.rb', line 67 def self.line_includes_status_and_id?(json) line_includes_status?(json) && line_includes_id?(json) end |
.line_includes_stream?(json) ⇒ Boolean
63 64 65 |
# File 'lib/rake_docker/output.rb', line 63 def self.line_includes_stream?(json) json['stream'] end |
.line_skippable?(json) ⇒ Boolean
72 73 74 75 76 |
# File 'lib/rake_docker/output.rb', line 72 def self.line_skippable?(json) (line_includes_status?(json) && line_includes_progress?(json)) || line_includes_aux?(json) end |
.parse(chunk) ⇒ Object
8 9 10 11 12 |
# File 'lib/rake_docker/output.rb', line 8 def self.parse(chunk) chunk.each_line do |line| yield parse_line(line) end end |
.parse_line(line) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rake_docker/output.rb', line 14 def self.parse_line(line) json, error = try_parse_json(line) return to_unparseable(line) if error return to_skipped(json) if line_skippable?(json) return to_error(json) if line_includes_error?(json) return to_stream(json) if line_includes_stream?(json) return to_status_with_id(json) if line_includes_status_and_id?(json) return to_status(json) if line_includes_status?(json) to_fallthrough(line) end |
.print(chunk) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/rake_docker/output.rb', line 33 def self.print(chunk) parse(chunk) do |text, error| if error $stdout.print "#{text.red}\n" raise text end $stdout.print text unless text.empty? end end |
.to_error(json) ⇒ Object
98 99 100 |
# File 'lib/rake_docker/output.rb', line 98 def self.to_error(json) [json['error'], true] end |
.to_fallthrough(line) ⇒ Object
102 103 104 |
# File 'lib/rake_docker/output.rb', line 102 def self.to_fallthrough(line) [line, false] end |
.to_skipped(_) ⇒ Object
82 83 84 |
# File 'lib/rake_docker/output.rb', line 82 def self.to_skipped(_) ['', false] end |
.to_status(json) ⇒ Object
90 91 92 |
# File 'lib/rake_docker/output.rb', line 90 def self.to_status(json) ["#{json['status']}\n", false] end |
.to_status_with_id(json) ⇒ Object
86 87 88 |
# File 'lib/rake_docker/output.rb', line 86 def self.to_status_with_id(json) ["#{json['id']}: #{json['status']}\n", false] end |
.to_stream(json) ⇒ Object
94 95 96 |
# File 'lib/rake_docker/output.rb', line 94 def self.to_stream(json) [json['stream'], false] end |
.to_unparseable(line) ⇒ Object
78 79 80 |
# File 'lib/rake_docker/output.rb', line 78 def self.to_unparseable(line) [line, false] end |
.try_parse_json(line) ⇒ Object
27 28 29 30 31 |
# File 'lib/rake_docker/output.rb', line 27 def self.try_parse_json(line) [JSON.parse(line.strip), false] rescue JSON::ParserError [nil, true] end |