rvm2-ui 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b5f6425992ae9e1c4ed457d91464499d8feecd2
4
+ data.tar.gz: a5278539ab6f31e28204f3a3ee1c5b0355d90b12
5
+ SHA512:
6
+ metadata.gz: 02f871b65ebe50095edfccf90e0e05ce66b3292a5bd806d2ac743bba372e4f448226c852dc06f1c87883459f155b5f239505f105f12593760c0c6269eded07e3
7
+ data.tar.gz: 66415ddcf05e009ce9c3645711f70af90726a38a2f3d30e05e19134fc061fac50c9fe38b143a365ba548c51ef480d58b9414912d8ff298ed5001ff5babe5b988
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ coverage/
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - ruby
4
+ notifications:
5
+ irc:
6
+ channels:
7
+ - "irc.freenode.org#rvm-test"
8
+ email:
9
+ recipients:
10
+ - mpapis@gmail.com
11
+ on_failure: change
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ #ruby=ruby
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2013-2014 Michal Papis
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,9 @@
1
+ # Rvm2::Ui
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rvm2-ui.png)](http://rubygems.org/gems/rvm2-ui)
4
+ [![Code Climate](https://codeclimate.com/github/rvm/rvm2-ui.png)](https://codeclimate.com/github/rvm/rvm2-ui)
5
+ [![Coverage Status](https://coveralls.io/repos/rvm/rvm2-ui/badge.png?branch=master)](https://coveralls.io/r/rvm/rvm2-ui?branch=master)
6
+ [![Build Status](https://travis-ci.org/rvm/rvm2-ui.png?branch=master)](https://travis-ci.org/rvm/rvm2-ui)
7
+ [![Dependency Status](https://gemnasium.com/rvm/rvm2-ui.png)](https://gemnasium.com/rvm/rvm2-ui)
8
+ [![Documentation](https://f.cloud.github.com/assets/23423/241231/303578dc-899b-11e2-84e7-50387dcc3abe.png)](http://rubydoc.info/gems/rvm2-ui/frames)
9
+
@@ -0,0 +1,9 @@
1
+ require "rake/testtask"
2
+
3
+ task :default => [:test]
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.verbose = true
7
+ t.libs.push("demo", "test")
8
+ t.pattern = "test/**/*_test.rb"
9
+ end
@@ -0,0 +1,85 @@
1
+ module Rvm2
2
+ module Ui
3
+ module Output
4
+ class Console
5
+
6
+ module ConsoleIO
7
+ attr_accessor :was_new_line
8
+
9
+ def console_parent=(value)
10
+ @was_new_line = true
11
+ @console_parent = value
12
+ end
13
+
14
+ def write(string)
15
+ super("\n") if !@was_new_line and !string.start_with?("\r")
16
+ super(indent(string))
17
+ @was_new_line = true
18
+ end
19
+
20
+ def indent(string)
21
+ if levels > 0
22
+ ends_with_n = string.end_with?("\n")
23
+ string = string.split(/\n/).map do |s|
24
+ s.sub(/^(\r?)/,"\\1#{" "*levels}")
25
+ end.join("\n")
26
+ string << "\n" if ends_with_n
27
+ end
28
+ string
29
+ end
30
+
31
+ def levels
32
+ @console_parent.levels
33
+ end
34
+ end
35
+
36
+ attr_reader :stdout, :stderr
37
+
38
+ def levels
39
+ @names.size
40
+ end
41
+
42
+ def initialize(stdout = $stdout, stderr = $stderr)
43
+ @stdout = stdout.extend(ConsoleIO)
44
+ @stdout.console_parent = self
45
+ @stderr = stderr.extend(ConsoleIO)
46
+ @stderr.console_parent = self
47
+ @names = []
48
+ end
49
+
50
+ def start(name)
51
+ @stdout.write(group_message(name, " "))
52
+ @stdout.was_new_line = false
53
+ @names.push(name)
54
+ end
55
+
56
+ def finish(status)
57
+ name = @names.pop
58
+ @stdout.puts("\r#{group_message(name, status ? "v" : "x")}")
59
+ end
60
+
61
+ def log(message, type = :log)
62
+ case type
63
+ when :log
64
+ @stdout.puts(message)
65
+ when :warn
66
+ @stdout.puts("Warning: #{message}")
67
+ when :warn_important
68
+ @stdout.puts("WARNING! #{message}")
69
+ when :error
70
+ @stderr.puts("Error: #{message}")
71
+ else
72
+ @stdout.puts("#{type.to_s.capitalize}: #{message}")
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def group_message(name, result)
79
+ "[#{result}] #{name}"
80
+ end
81
+
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,62 @@
1
+ require 'stringio'
2
+
3
+ module Rvm2
4
+ module Ui
5
+ module Output
6
+ class Fake
7
+
8
+ class Element
9
+ attr_reader :list, :message, :type, :parent
10
+ attr_accessor :status
11
+ def initialize(message, type = :log, parent = nil)
12
+ @message = message
13
+ @type = type
14
+ @parent = parent
15
+ @list = [] if type == :group
16
+ end
17
+ end
18
+
19
+ class StringElements < StringIO
20
+ def initialize(parent, type)
21
+ @parent = parent
22
+ @type = type
23
+ super("","w")
24
+ end
25
+ def write(string)
26
+ @parent.current.list << Element.new(string, @type)
27
+ end
28
+ end
29
+
30
+ attr_reader :root, :current
31
+ def initialize
32
+ @root = Element.new(nil, :group, nil)
33
+ @current = @root
34
+ end
35
+
36
+ def start(name)
37
+ created = Element.new(name, :group, @current)
38
+ @current.list << created
39
+ @current = created
40
+ end
41
+
42
+ def finish(status)
43
+ @current.status = status
44
+ @current = @current.parent
45
+ end
46
+
47
+ def log(message, type = :log)
48
+ @current.list << Element.new(message, type)
49
+ end
50
+
51
+ def stdout
52
+ @stdout ||= StringElements.new(self, :stdout)
53
+ end
54
+
55
+ def stderr
56
+ @stderr ||= StringElements.new(self, :stderr)
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,28 @@
1
+ require 'hooks'
2
+ require 'hooks/instance_hooks'
3
+
4
+ module Rvm2
5
+ module Ui
6
+ class Router
7
+ define_hooks :on_start, :on_finish, :on_log
8
+
9
+ # ui.command "bla" { do_something; }
10
+ def command(name, &block)
11
+ raise "No block given" unless block_given?
12
+ run_hook(:on_start, name)
13
+ status = block.call
14
+ run_hook(:on_finish, status)
15
+ status
16
+ end
17
+
18
+ # ui.log 'message'
19
+ # ui.log 'message', :important
20
+ # standard types => :log, :warn, :important, :error
21
+ # in case unsupported type is used :log will be used
22
+ def log(message, type = :log)
23
+ run_hook(:on_log, message, type)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module Rvm2
2
+ module Ui
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ require File.expand_path("../lib/rvm2/ui/version.rb", __FILE__)
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "rvm2-ui"
8
+ s.version = Rvm2::Ui::VERSION
9
+ s.authors = ["Michal Papis"]
10
+ s.email = ["mpapis@gmail.com"]
11
+ s.homepage = "https://github.com/rvm/rvm2-ui"
12
+ s.summary = "Abstract user interface handling in RVM2"
13
+ s.license = "Apache 2.0"
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.required_ruby_version = ">= 2.0.0"
17
+ %w{rake minitest simplecov coveralls redcarpet}.each do |name|
18
+ s.add_development_dependency(name)
19
+ end
20
+ # s.add_development_dependency("smf-gem")
21
+ end
@@ -0,0 +1,113 @@
1
+ require 'test_helper'
2
+ require 'plugins/rvm2/ui/output/console'
3
+ require 'stringio'
4
+
5
+ describe Rvm2::Ui::Output::Console do
6
+ before do
7
+ @stdout = StringIO.new
8
+ @stderr = StringIO.new
9
+ end
10
+
11
+ subject do
12
+ Rvm2::Ui::Output::Console.new(@stdout, @stderr)
13
+ end
14
+
15
+ it "adds messages" do
16
+ subject.log("Test me 1")
17
+ subject.log("Test me 2")
18
+ @stderr.string.must_equal("")
19
+ @stdout.string.must_equal(<<-EXPECTED)
20
+ Test me 1
21
+ Test me 2
22
+ EXPECTED
23
+ end
24
+
25
+ it "adds warnings" do
26
+ subject.log("Test me 1", :warn)
27
+ @stderr.string.must_equal("")
28
+ @stdout.string.must_equal(<<-EXPECTED)
29
+ Warning: Test me 1
30
+ EXPECTED
31
+ end
32
+
33
+ it "adds important warnings" do
34
+ subject.log("Test me 1", :warn_important)
35
+ @stderr.string.must_equal("")
36
+ @stdout.string.must_equal(<<-EXPECTED)
37
+ WARNING! Test me 1
38
+ EXPECTED
39
+ end
40
+
41
+ it "adds errors" do
42
+ subject.log("Test me 1", :error)
43
+ @stdout.string.must_equal("")
44
+ @stderr.string.must_equal(<<-EXPECTED)
45
+ Error: Test me 1
46
+ EXPECTED
47
+ end
48
+
49
+ it "adds custom messages" do
50
+ subject.log("Test me 1", :custom)
51
+ @stderr.string.must_equal("")
52
+ @stdout.string.must_equal(<<-EXPECTED)
53
+ Custom: Test me 1
54
+ EXPECTED
55
+ end
56
+
57
+ it "adds groups" do
58
+ subject.start("Group 1")
59
+ subject.finish(true)
60
+ subject.start("Group 2")
61
+ subject.finish(false)
62
+ @stdout.string.must_equal(<<-EXPECTED)
63
+ [ ] Group 1\r[v] Group 1
64
+ [ ] Group 2\r[x] Group 2
65
+ EXPECTED
66
+ end
67
+
68
+ it "nests groups and messages" do
69
+ subject.start("Group 1")
70
+ subject.log("Test me 1")
71
+ subject.start("Group 2")
72
+ subject.finish(false)
73
+ subject.start("Group 3")
74
+ subject.log("Test me 2")
75
+ subject.finish(true)
76
+ subject.finish(true)
77
+ @stdout.string.must_equal(<<-EXPECTED)
78
+ [ ] Group 1
79
+ Test me 1
80
+ [ ] Group 2\r [x] Group 2
81
+ [ ] Group 3
82
+ Test me 2
83
+ \r [v] Group 3
84
+ \r[v] Group 1
85
+ EXPECTED
86
+ end
87
+
88
+ it "adds stdout writes" do
89
+ subject.stdout.puts("Example 1")
90
+ @stdout.string.must_equal(<<-EXPECTED)
91
+ Example 1
92
+ EXPECTED
93
+ end
94
+
95
+ it "adds grouped stdout writes" do
96
+ subject.start("Group 1")
97
+ subject.stdout.puts("Example 1")
98
+ subject.finish(true)
99
+ @stdout.string.must_equal(<<-EXPECTED)
100
+ [ ] Group 1
101
+ Example 1
102
+ \r[v] Group 1
103
+ EXPECTED
104
+ end
105
+
106
+ it "adds stderr writes" do
107
+ subject.stderr.puts("Example 2")
108
+ @stderr.string.must_equal(<<-EXPECTED)
109
+ Example 2
110
+ EXPECTED
111
+ end
112
+
113
+ end
@@ -0,0 +1,67 @@
1
+ require 'test_helper'
2
+ require 'plugins/rvm2/ui/output/fake'
3
+
4
+ describe Rvm2::Ui::Output::Fake do
5
+ subject do
6
+ Rvm2::Ui::Output::Fake.new
7
+ end
8
+
9
+ it "adds messages" do
10
+ subject.root.list.must_equal([])
11
+ subject.log("Test me 1")
12
+ subject.root.list.size.must_equal(1)
13
+ subject.log("Test me 2")
14
+ subject.root.list.size.must_equal(2)
15
+ subject.root.list.map(&:message).must_equal(["Test me 1", "Test me 2"])
16
+ end
17
+
18
+ it "adds groups" do
19
+ subject.root.list.must_equal([])
20
+ subject.start("Group 1")
21
+ subject.finish(true)
22
+ subject.root.list.size.must_equal(1)
23
+ subject.start("Group 2")
24
+ subject.finish(false)
25
+ subject.root.list.size.must_equal(2)
26
+ subject.root.list.map(&:message).must_equal(["Group 1", "Group 2"])
27
+ subject.root.list.map(&:status).must_equal([true, false])
28
+ end
29
+
30
+ it "nests groups and messages" do
31
+ subject.root.list.must_equal([])
32
+ subject.start("Group 1")
33
+ subject.log("Test me 1")
34
+ subject.start("Group 2")
35
+ subject.finish(false)
36
+ subject.finish(true)
37
+ subject.root.list.size.must_equal(1)
38
+ subject.root.list[0].message.must_equal("Group 1")
39
+ subject.root.list[0].status.must_equal(true)
40
+ subject.root.list[0].list.size.must_equal(2)
41
+ subject.root.list[0].list[0].message.must_equal("Test me 1")
42
+ subject.root.list[0].list[1].message.must_equal("Group 2")
43
+ subject.root.list[0].list[1].status.must_equal(false)
44
+ end
45
+
46
+ it "adds stdout writes" do
47
+ subject.stdout.write("Example 1")
48
+ subject.root.list.size.must_equal(1)
49
+ subject.root.list[0].message.must_equal("Example 1")
50
+ end
51
+
52
+ it "adds groups stdout writes" do
53
+ subject.start("Group 1")
54
+ subject.stdout.write("Example 1")
55
+ subject.finish(true)
56
+ subject.stderr.write("Example 1")
57
+ subject.root.list.size.must_equal(2)
58
+ subject.root.list[0].message.must_equal("Group 1")
59
+ subject.root.list[0].status.must_equal(true)
60
+ subject.root.list[0].list.size.must_equal(1)
61
+ subject.root.list[0].list[0].message.must_equal("Example 1")
62
+ subject.root.list[0].list[0].type.must_equal(:stdout)
63
+ subject.root.list[1].message.must_equal("Example 1")
64
+ subject.root.list[1].type.must_equal(:stderr)
65
+ end
66
+
67
+ end
@@ -0,0 +1,17 @@
1
+ require "coveralls"
2
+ require "simplecov"
3
+
4
+ SimpleCov.start do
5
+ formatter SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter,
8
+ ]
9
+ command_name "Unit Tests"
10
+ add_filter "/test/"
11
+ add_filter "/demo/"
12
+ end
13
+
14
+ Coveralls.noisy = true unless ENV['CI']
15
+
16
+ require 'minitest/autorun'
17
+ require 'minitest/unit'
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rvm2-ui
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michal Papis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: redcarpet
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - mpapis@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - lib/plugins/rvm2/ui/output/console.rb
97
+ - lib/plugins/rvm2/ui/output/fake.rb
98
+ - lib/rvm2/ui.rb
99
+ - lib/rvm2/ui/version.rb
100
+ - rvm2-ui.gemspec
101
+ - test/plugins/rvm2/ui/output/console_test.rb
102
+ - test/plugins/rvm2/ui/output/fake_test.rb
103
+ - test/test_helper.rb
104
+ homepage: https://github.com/rvm/rvm2-ui
105
+ licenses:
106
+ - Apache 2.0
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 2.0.0
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.0
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Abstract user interface handling in RVM2
128
+ test_files:
129
+ - test/plugins/rvm2/ui/output/console_test.rb
130
+ - test/plugins/rvm2/ui/output/fake_test.rb
131
+ - test/test_helper.rb