ringc 0.1.0

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: c65462ec53b82b36ee866841855bfe11e16255e5
4
+ data.tar.gz: 273d3b79ae3e497a81089d1cd486c8d58e8de543
5
+ SHA512:
6
+ metadata.gz: 99001b507013172d16e4c1dd9959f4f07eb780fe7fa15207e8c21de92b6eb56f5b193bdfcdae411f6dcda840add8ca484244eecdd3c9431c123a867b57bb9d09
7
+ data.tar.gz: 3c3b8f7f9c49ad0756fb5151c4d71493b62baa0a51c08a9cc2ab0d9d819a88eacf96607e64948086f16c442c03a3e33c3252693d67a7195378d4496255be1dcb
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ringc.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 nownabe
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ # Ringc
2
+
3
+ Ringc executes commands with rich stats.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ringc'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ringc
20
+
21
+ ## Usage
22
+
23
+ ```irb
24
+ >> require "ringc"
25
+ >> result = Ringc.ring("ls -a")
26
+
27
+ >> result.success?
28
+ => true
29
+
30
+ >> puts result.stdout
31
+ .
32
+ ..
33
+ .git
34
+ .gitignore
35
+ .rspec
36
+ .travis.yml
37
+ Gemfile
38
+ Gemfile.lock
39
+ README.md
40
+ Rakefile
41
+ bin
42
+ lib
43
+ ringc.gemspec
44
+ spec
45
+ => nil
46
+
47
+ >> puts result.stderr
48
+
49
+ => nil
50
+
51
+ >> result.total
52
+ => 0.23999999999999994
53
+
54
+ >> result.utime
55
+ => 0.0
56
+
57
+ >> result.stime
58
+ => 0.0
59
+
60
+ >> result.cutime
61
+ => 0.19999999999999996
62
+
63
+ >> result.cstime
64
+ => 0.03999999999999998
65
+ ```
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nownabe/ringc.
70
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ringc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ require "ringc/version"
2
+ require "ringc/executor"
3
+ require "ringc/executors"
4
+
5
+ module Ringc
6
+ class << self
7
+ def ring(command, options = {})
8
+ Executor.new(:systemu, options).execute(command)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ require "memoist"
2
+
3
+ module Ringc
4
+ class Executor
5
+ extend Memoist
6
+
7
+ attr_reader :type, :options
8
+
9
+ def initialize(type, options)
10
+ @type = type
11
+ @options = options
12
+ end
13
+
14
+ def execute(command)
15
+ executor.run(command)
16
+ end
17
+
18
+ private
19
+
20
+ def executor
21
+ executor_class.new
22
+ end
23
+ memoize :executor
24
+
25
+ def executor_class
26
+ case type
27
+ when :systemu
28
+ require "ringc/executors/systemu"
29
+ Executors::Systemu
30
+ else
31
+ fail
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ module Ringc
2
+ module Executors
3
+ end
4
+ end
@@ -0,0 +1,49 @@
1
+ require "ringc/result"
2
+
3
+ module Ringc
4
+ module Executors
5
+ class Base
6
+ def initialize
7
+ @result = Result.new
8
+ end
9
+
10
+ def run(command)
11
+ @result.set_output(*measure { execute(command) })
12
+ @result
13
+ end
14
+
15
+ def execute
16
+ fail(NotImplementError)
17
+ end
18
+
19
+ private
20
+
21
+ def finish
22
+ @finish_times = Process.times
23
+ @result.finish_time = Time.now
24
+ set_times
25
+ end
26
+
27
+ def measure
28
+ start
29
+ result = yield
30
+ finish
31
+ result
32
+ end
33
+
34
+ def set_times
35
+ @result.set_times(
36
+ @finish_times.utime - @start_times.utime,
37
+ @finish_times.stime - @start_times.stime,
38
+ @finish_times.cutime - @start_times.cutime,
39
+ @finish_times.cstime - @start_times.cstime
40
+ )
41
+ end
42
+
43
+ def start
44
+ @result.start_time = Time.now
45
+ @start_times = Process.times
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ require "systemu"
2
+ require "ringc/executors/base"
3
+
4
+ module Ringc
5
+ module Executors
6
+ class Systemu < Base
7
+ def execute(command)
8
+ systemu(command)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,48 @@
1
+ require "memoist"
2
+
3
+ module Ringc
4
+ class Result
5
+ extend Memoist
6
+
7
+ attr_accessor :start_time, :finish_time
8
+ attr_reader :status, :stdout, :stderr
9
+ attr_reader :user_time, :system_time
10
+ attr_reader :children_user_time, :children_system_time
11
+
12
+ def initialize
13
+ end
14
+
15
+ def real_time
16
+ finish_time - start_time
17
+ end
18
+ memoize :real_time
19
+ alias_method :real, :real_time
20
+
21
+ def set_output(status, stdout, stderr)
22
+ @status = status
23
+ @stdout = stdout
24
+ @stderr = stderr
25
+ end
26
+
27
+ def set_times(utime, stime, cutime, cstime)
28
+ @user_time = utime
29
+ @system_time = stime
30
+ @children_user_time = cutime
31
+ @children_system_time = cstime
32
+ end
33
+ alias_method :utime, :user_time
34
+ alias_method :stime, :system_time
35
+ alias_method :cutime, :children_user_time
36
+ alias_method :cstime, :children_system_time
37
+
38
+ def success?
39
+ status == 0
40
+ end
41
+
42
+ def total_time
43
+ utime + stime + cutime + cstime
44
+ end
45
+ memoize :total_time
46
+ alias_method :total, :total_time
47
+ end
48
+ end
@@ -0,0 +1,3 @@
1
+ module Ringc
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ringc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ringc"
8
+ spec.version = Ringc::VERSION
9
+ spec.authors = ["nownabe"]
10
+ spec.email = ["nownabe@gmail.com"]
11
+
12
+ spec.summary = %q{Ringc executes commands with rich stats.}
13
+ spec.homepage = ""
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+
24
+ spec.add_dependency "memoist"
25
+ spec.add_dependency "systemu"
26
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ringc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - nownabe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
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: rake
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: rspec
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: memoist
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: systemu
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
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
+ - nownabe@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/ringc.rb
100
+ - lib/ringc/executor.rb
101
+ - lib/ringc/executors.rb
102
+ - lib/ringc/executors/base.rb
103
+ - lib/ringc/executors/systemu.rb
104
+ - lib/ringc/result.rb
105
+ - lib/ringc/version.rb
106
+ - ringc.gemspec
107
+ homepage: ''
108
+ licenses: []
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.5
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Ringc executes commands with rich stats.
130
+ test_files: []
131
+ has_rdoc: