dotpretty 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f49efdc481cac0f784e3c65cb68cdf854376a0df3b6082baef9a893469a27a6b
4
+ data.tar.gz: 87d1b72bab6148ff502796e1c29d6bf786b08c3deeae45aa08f453dbaffaec63
5
+ SHA512:
6
+ metadata.gz: d262321031ccdc28a5e137697ecaed5bc168509de3e9ca4303ad672f072b35d8c857b3ddd1876fce04a51571e2568254e5928b300b1ec8a2524d5dc364b8f7d9
7
+ data.tar.gz: f13f21aacfd75aca9f9f4970958f63868d3a4b5b13ac56b4ea9f9dd84ca7c5364343dc50310bbd01c65206c75ea7b7314d0363a1c042225ff4f65344e075371c
data/bin/dotpretty ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "dotpretty/parser"
4
+
5
+ parser = Dotpretty::Parser.new({ output: STDOUT })
6
+
7
+ STDIN.each_line do |line|
8
+ parser.parse_line(line)
9
+ end
@@ -0,0 +1,69 @@
1
+ require "dotpretty/reporter"
2
+ require "dotpretty/state_machine_builder"
3
+
4
+ module Dotpretty
5
+ class Parser
6
+
7
+ def initialize(output:)
8
+ self.output = output
9
+ self.state_machine = Dotpretty::StateMachineBuilder.build(Dotpretty::Reporter.new(output: output)) do
10
+ state :waiting do
11
+ transition :build_started, :build_in_progress, :build_started
12
+ end
13
+ state :build_in_progress do
14
+ transition :build_completed, :ready_to_run_tests, :build_completed
15
+ end
16
+ state :ready_to_run_tests do
17
+ transition :starting_tests, :running_tests, :starting_tests
18
+ end
19
+ state :running_tests do
20
+ transition :test_failed, :reading_test_failure, :test_failed
21
+ transition :test_passed, :running_tests, :test_passed
22
+ transition :tests_completed, :done, :show_test_summary
23
+ end
24
+ state :reading_test_failure do
25
+ transition :test_passed, :running_tests, :test_passed
26
+ transition :received_failure_output, :reading_test_failure, :show_failure_details
27
+ transition :tests_completed, :done, :show_test_summary
28
+ end
29
+ end
30
+ end
31
+
32
+ def parse_line(input_line)
33
+ case state_machine.current_state_name
34
+ when :waiting
35
+ state_machine.trigger(:build_started)
36
+ when :build_in_progress
37
+ state_machine.trigger(:build_completed) if input_line.match(/^Build completed/)
38
+ when :ready_to_run_tests
39
+ if input_line.match(/^Starting test execution, please wait...$/)
40
+ state_machine.trigger(:starting_tests)
41
+ end
42
+ when :running_tests
43
+ if input_line.start_with?("Passed")
44
+ match = input_line.match(/^Passed\s+(.+)$/)
45
+ state_machine.trigger(:test_passed, match[1])
46
+ elsif input_line.start_with?("Failed")
47
+ match = input_line.match(/^Failed\s+(.+)$/)
48
+ state_machine.trigger(:test_failed, match[1])
49
+ elsif input_line.start_with?("Total tests")
50
+ state_machine.trigger(:tests_completed, input_line)
51
+ end
52
+ when :reading_test_failure
53
+ if input_line.start_with?("Passed")
54
+ match = input_line.match(/^Passed\s+(.+)$/)
55
+ state_machine.trigger(:test_passed, match[1])
56
+ elsif input_line.start_with?("Total tests")
57
+ state_machine.trigger(:tests_completed, input_line)
58
+ else
59
+ state_machine.trigger(:received_failure_output, input_line)
60
+ end
61
+ end
62
+ end
63
+
64
+ private
65
+
66
+ attr_accessor :output, :state_machine
67
+
68
+ end
69
+ end
@@ -0,0 +1,42 @@
1
+ module Dotpretty
2
+ class Reporter
3
+
4
+ def initialize(output:)
5
+ self.output = output
6
+ end
7
+
8
+ def build_completed
9
+ output.puts("Build completed")
10
+ output.puts("")
11
+ end
12
+
13
+ def build_started
14
+ output.puts("Build started")
15
+ end
16
+
17
+ def show_failure_details(details)
18
+ output.puts("#{details}")
19
+ end
20
+
21
+ def show_test_summary(summary)
22
+ output.puts("\n#{summary}")
23
+ end
24
+
25
+ def starting_tests
26
+ output.puts("Starting test execution...")
27
+ end
28
+
29
+ def test_failed(test_name)
30
+ output.puts("Failed #{test_name}")
31
+ end
32
+
33
+ def test_passed(test_name)
34
+ output.puts("Passed #{test_name}")
35
+ end
36
+
37
+ private
38
+
39
+ attr_accessor :output
40
+
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+ module Dotpretty
2
+ class StateDetails
3
+
4
+ def initialize(transitions:, exit_action:, entry_action:)
5
+ self.entry_action = entry_action
6
+ self.exit_action = exit_action
7
+ self.transitions = transitions
8
+ end
9
+
10
+ attr_reader :entry_action
11
+
12
+ def trigger(event, &block)
13
+ transition = transitions[event]
14
+ block.call(transition, exit_action) if transition
15
+ end
16
+
17
+ private
18
+
19
+ attr_accessor :exit_action, :transitions
20
+ attr_writer :entry_action
21
+
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ require "dotpretty/state_details"
2
+
3
+ module Dotpretty
4
+ class StateMachine
5
+
6
+ def initialize(initial_state:, observer:, states:)
7
+ self.current_state_name = initial_state
8
+ self.observer = observer
9
+ self.states = states
10
+ end
11
+
12
+ attr_reader :current_state_name
13
+
14
+ def trigger(event, *args)
15
+ current_state.trigger(event) do |transition, exit_action|
16
+ perform(exit_action, *args) if current_state_name != transition[:next_state_name]
17
+ perform(transition[:action], *args)
18
+ if current_state_name != transition[:next_state_name]
19
+ self.current_state_name = transition[:next_state_name]
20
+ perform(current_state.entry_action, *args)
21
+ end
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def perform(action, *args)
28
+ observer.send(action, *args) if action
29
+ end
30
+
31
+ def current_state
32
+ states[current_state_name] || StateDetails.new({
33
+ entry_action: nil,
34
+ exit_action: nil,
35
+ transitions: {}
36
+ })
37
+ end
38
+
39
+ attr_accessor :observer, :states
40
+ attr_writer :current_state_name
41
+
42
+ end
43
+ end
@@ -0,0 +1,79 @@
1
+ require "dotpretty/state_details"
2
+ require "dotpretty/state_machine"
3
+
4
+ module Dotpretty
5
+ class StateMachineBuilder
6
+
7
+ class StateDetailsBuilder
8
+
9
+ def self.build(name, &definition)
10
+ builder = StateDetailsBuilder.new(name)
11
+ builder.instance_eval(&definition)
12
+ return builder.build
13
+ end
14
+
15
+ def initialize(name)
16
+ self.name = name
17
+ self.transitions = {}
18
+ end
19
+
20
+ def build
21
+ StateDetails.new({
22
+ entry_action: entry_action,
23
+ exit_action: exit_action,
24
+ transitions: transitions
25
+ })
26
+ end
27
+
28
+ def transition(event, next_state_name, action = nil)
29
+ transitions[event] = {
30
+ action: action,
31
+ next_state_name: next_state_name
32
+ }
33
+ end
34
+
35
+ def on_entry(action)
36
+ self.entry_action = action
37
+ end
38
+
39
+ def on_exit(action)
40
+ self.exit_action = action
41
+ end
42
+
43
+ private
44
+
45
+ attr_accessor :entry_action, :exit_action, :name, :transitions
46
+
47
+ end
48
+
49
+ def self.build(observer, &definition)
50
+ builder = Dotpretty::StateMachineBuilder.new(observer)
51
+ builder.instance_eval(&definition)
52
+ return builder.build
53
+ end
54
+
55
+ def initialize(observer)
56
+ self.observer = observer
57
+ self.states = {}
58
+ end
59
+
60
+ def state(name, &definition)
61
+ state = StateDetailsBuilder.build(name, &definition)
62
+ states[name] = state
63
+ self.initial_state = name if !initial_state
64
+ end
65
+
66
+ def build
67
+ Dotpretty::StateMachine.new({
68
+ initial_state: initial_state,
69
+ observer: observer,
70
+ states: states
71
+ })
72
+ end
73
+
74
+ private
75
+
76
+ attr_accessor :initial_state, :observer, :states
77
+
78
+ end
79
+ end
data/lib/dotpretty.rb ADDED
@@ -0,0 +1 @@
1
+ require "dotpretty/parser"
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dotpretty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eric Meyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem to parse and improve the output of the dotnet command
14
+ email:
15
+ executables:
16
+ - dotpretty
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/dotpretty
21
+ - lib/dotpretty.rb
22
+ - lib/dotpretty/parser.rb
23
+ - lib/dotpretty/reporter.rb
24
+ - lib/dotpretty/state_details.rb
25
+ - lib/dotpretty/state_machine.rb
26
+ - lib/dotpretty/state_machine_builder.rb
27
+ homepage: https://github.com/ericmeyer/dotpretty
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 3.0.3
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: A gem to improve dotnet output
50
+ test_files: []