ult 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c08777dc4baf5747a4506a2de04f3e8f576cc951
4
+ data.tar.gz: 0c61e2d7cdf7544e230c05780ba71c15b197f278
5
+ SHA512:
6
+ metadata.gz: 054633a1c3519563e41df7096ebba7f071a61a2b548ae6f5940baa223da414b65d10f08ecee6c8fba7cd204721b06657d4c90da8157cb4bf8d4025c3b31e6024
7
+ data.tar.gz: 9d4fe1e8a393640d2e9a9b4d0b4b7fa686cb58c033321eb0ef8490c0ff3c893b8e217bb31f682664d84663cf63c839ff96f7539d730ade1d75fe31accac9505a
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /sample/__tmp__/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ult.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 liveralmask
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Ult
2
+
3
+ Ultimate tools that work anywhere.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ult'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install ult
20
+
21
+ ## Usage
22
+
23
+ [Please check here](https://github.com/liveralmask/ult/tree/master/sample)
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/liveralmask/ult.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ult"
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/ult.rb ADDED
@@ -0,0 +1,44 @@
1
+ require "ult/version"
2
+
3
+ module Ult
4
+ extend self
5
+
6
+ require "ult/execute"
7
+ module_function :execute, :shell
8
+
9
+ require "ult/path"
10
+ module_function :fullpath
11
+
12
+ require "ult/option"
13
+ module_function :option
14
+
15
+ require "ult/file"
16
+ module_function :file?, :filename, :extname, :mkfile, :rmfile
17
+
18
+ require "ult/dir"
19
+ module_function :dir?, :dirname, :direach, :dir, :pwd, :mkdir, :rmdir, :rmkdir
20
+
21
+ require "ult/find"
22
+ module_function :find
23
+
24
+ require "ult/platform"
25
+ module_function :platform, :mac?, :linux?, :windows?
26
+
27
+ require "ult/replica"
28
+ module_function :replica
29
+
30
+ require "ult/copy"
31
+ module_function :copy
32
+
33
+ require "ult/remove"
34
+ module_function :remove
35
+
36
+ require "ult/watchdog"
37
+ module_function :watchdog
38
+
39
+ require "ult/assert"
40
+ module_function :assert
41
+
42
+ require "ult/safety"
43
+ module_function :safety
44
+ end
data/lib/ult/assert.rb ADDED
@@ -0,0 +1,3 @@
1
+ def assert( condition, msg, error_type = RuntimeError )
2
+ raise( error_type, msg, caller( 1 ) ) if ! condition
3
+ end
data/lib/ult/copy.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "fileutils"
2
+ require "ult/dir"
3
+
4
+ def copy( src, dst )
5
+ dir?( src ) ? FileUtils.cp_r( src, dst ) : FileUtils.copy( src, dst )
6
+ end
data/lib/ult/dir.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "fileutils"
2
+ require "ult/path"
3
+
4
+ def dir?( path )
5
+ Dir.exist?( path )
6
+ end
7
+
8
+ def dirname( path )
9
+ File.dirname( path )
10
+ end
11
+
12
+ def direach( path )
13
+ Dir::foreach( path ){|name|
14
+ case name
15
+ when ".", ".."
16
+ else
17
+ yield( name, fullpath( name, path ) )
18
+ end
19
+ }
20
+ end
21
+
22
+ def dir( path, &block )
23
+ Dir.chdir( path, &block )
24
+ end
25
+
26
+ def pwd
27
+ Dir.pwd
28
+ end
29
+
30
+ def mkdir( path, &block )
31
+ FileUtils.mkdir_p( path ) if ! dir?( path )
32
+ dir( path, &block )
33
+ end
34
+
35
+ def rmdir( path )
36
+ FileUtils.rm_rf( path ) if dir?( path )
37
+ end
38
+
39
+ def rmkdir( path )
40
+ rmdir( path )
41
+ mkdir( path )
42
+ end
@@ -0,0 +1,65 @@
1
+ def execute( command, input = "", &block )
2
+ status = -1
3
+ block = lambda{|type, io, msg| io.print msg} if ! block_given?
4
+ begin
5
+ i_r, i_w = IO.pipe
6
+ o_r, o_w = IO.pipe
7
+ e_r, e_w = IO.pipe
8
+
9
+ pid = Process.fork{
10
+ i_w.close
11
+ STDIN.reopen( i_r )
12
+ STDOUT.reopen( o_w )
13
+ STDERR.reopen( e_w )
14
+ exec( command )
15
+ }
16
+ o_w.close
17
+ e_w.close
18
+ i_r.close
19
+ i_w.write input
20
+ i_w.close
21
+
22
+ # IOブロックによるプロセス停止を防ぐため、スレッドで定期的に読み取る
23
+ block.call( :cmd, $stdout, "#{command}\n" )
24
+ out_thread = Thread.start{
25
+ chars = []
26
+ o_r.each_char{|c|
27
+ chars.push c
28
+ case c
29
+ when /[\r\n]/
30
+ block.call( :out, $stdout, chars.join )
31
+ chars = []
32
+ end
33
+ }
34
+ block.call( :out, $stdout, chars.join ) if ! chars.empty?
35
+ }
36
+ err_thread = Thread.start{
37
+ chars = []
38
+ e_r.each_char{|c|
39
+ chars.push c
40
+ case c
41
+ when /[\r\n]/
42
+ block.call( :err, $stderr, chars.join )
43
+ chars = []
44
+ end
45
+ }
46
+ block.call( :err, $stderr, chars.join ) if ! chars.empty?
47
+ }
48
+
49
+ Process.waitpid( pid )
50
+ status = $?.exitstatus
51
+ out_thread.join
52
+ err_thread.join
53
+ end
54
+ status
55
+ end
56
+
57
+ def shell( command, &block )
58
+ status = execute( command )
59
+ if block_given?
60
+ status = block.call( status )
61
+ else
62
+ raise "#{command} => #{status}" if 0 != status
63
+ end
64
+ status
65
+ end
data/lib/ult/file.rb ADDED
@@ -0,0 +1,21 @@
1
+ def file?( path )
2
+ File.exist?( path )
3
+ end
4
+
5
+ def filename( path )
6
+ File.basename( path )
7
+ end
8
+
9
+ def extname( path )
10
+ /^\.?.+?\.(.+)$/ =~ path ? $1 : ""
11
+ end
12
+
13
+ def mkfile( path, mode, &block )
14
+ open( path, mode ){|file|
15
+ block.call( file ) if block_given?
16
+ }
17
+ end
18
+
19
+ def rmfile( path )
20
+ File.delete( path ) if file?( path )
21
+ end
data/lib/ult/find.rb ADDED
@@ -0,0 +1,3 @@
1
+ def find( pattern )
2
+ Dir.glob( pattern )
3
+ end
data/lib/ult/option.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "optparse"
2
+
3
+ def option( *args, &block )
4
+ OptionParser.new( *args ).instance_eval( &block )
5
+ end
data/lib/ult/path.rb ADDED
@@ -0,0 +1,3 @@
1
+ def fullpath( name, dir = "." )
2
+ File.expand_path( name, dir )
3
+ end
@@ -0,0 +1,15 @@
1
+ def platform
2
+ RUBY_PLATFORM
3
+ end
4
+
5
+ def mac?
6
+ ! platform.match( /darwin/ ).nil?
7
+ end
8
+
9
+ def linux?
10
+ ! platform.match( /linux/ ).nil?
11
+ end
12
+
13
+ def windows?
14
+ mac? ? false : ! platform.match( /win/ ).nil?
15
+ end
data/lib/ult/remove.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "ult/dir"
2
+ require "ult/file"
3
+
4
+ def remove( path )
5
+ dir?( path ) ? rmdir( path ) : rmfile( path )
6
+ end
@@ -0,0 +1,21 @@
1
+ require "ult/dir"
2
+ require "ult/file"
3
+ require "ult/copy"
4
+ require "ult/remove"
5
+
6
+ def replica( count, prefix, suffix = "" )
7
+ src = "#{prefix}#{suffix}"
8
+ if dir?( src )
9
+ count.times{|index|
10
+ dst = "#{prefix}#{index + 1}#{suffix}"
11
+ remove( dst )
12
+ copy( src, dst )
13
+ }
14
+ elsif file?( src )
15
+ count.times{|index|
16
+ dst = "#{prefix}#{index + 1}#{suffix}"
17
+ remove( dst )
18
+ copy( src, dst )
19
+ }
20
+ end
21
+ end
data/lib/ult/safety.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "ult/dir"
2
+
3
+ def safety( &block )
4
+ root_dir = pwd
5
+ begin
6
+ block.call
7
+ rescue Exception => e
8
+ dir( root_dir )
9
+ raise e
10
+ rescue StandardError => e
11
+ dir( root_dir )
12
+ raise e
13
+ end
14
+ dir( root_dir )
15
+ end
@@ -0,0 +1,3 @@
1
+ module Ult
2
+ VERSION = "0.0.7"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "ult/execute"
2
+
3
+ def watchdog( command, input = "", &block )
4
+ loop{
5
+ status, outputs, errors = execute( command, input )
6
+ break if ! block.call( status, outputs, errors )
7
+ }
8
+ end
data/sample/assert.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "ult"
2
+ extend Ult
3
+
4
+ assert( true == false, "true != false" )
data/sample/dir.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "ult"
2
+ extend Ult
3
+
4
+ puts "__FILE__=#{__FILE__}"
5
+ puts "dir?=#{dir?( __FILE__ )}"
6
+ puts "dirname=#{dirname( __FILE__ )}"
7
+ direach( "." ){|name, path|
8
+ puts "name=#{name} path=#{path}"
9
+ }
10
+ dir( "/" ){
11
+ puts "pwd=#{pwd}"
12
+ }
13
+ puts "#{pwd}"
14
+ dir( "/" )
15
+ puts "#{pwd}"
data/sample/execute.rb ADDED
@@ -0,0 +1,24 @@
1
+ require "ult"
2
+ extend Ult
3
+
4
+ args = ARGV.empty? ? [ "date" ] : ARGV
5
+ puts "----- execute start [#{args.join( ' ' )}] -----"
6
+ status = execute( *args )
7
+ puts "\n----- execute end [#{args.join( ' ' )}] status=#{status} -----"
8
+
9
+ puts "----- execute start [#{args.join( ' ' )}] -----"
10
+ execute( *args ){|type, io, msg|
11
+ p [ type, io, msg ]
12
+ }
13
+ puts "----- execute end [#{args.join( ' ' )}] -----"
14
+
15
+ puts "----- shell start [#{args.join( ' ' )}] -----"
16
+ status = shell( *args ){|status|
17
+ puts "\nshell status=#{status}"
18
+ "success"
19
+ }
20
+ puts "----- shell end [#{args.join( ' ' )}] status=#{status} -----"
21
+
22
+ puts "----- shell start [#{args.join( ' ' )}] -----"
23
+ shell( *args )
24
+ puts "\n----- shell end [#{args.join( ' ' )}] -----"
data/sample/file.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "ult"
2
+ extend Ult
3
+
4
+ puts "__FILE__=#{__FILE__}"
5
+ puts "file?=#{file?( __FILE__ )}"
6
+ puts "filename=#{filename( __FILE__ )}"
7
+ puts "extname=#{extname( __FILE__ )}"
data/sample/find.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "ult"
2
+ extend Ult
3
+
4
+ puts find( "*" )
data/sample/option.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "ult"
2
+ extend Ult
3
+
4
+ option{
5
+ on( "-o VALUE", "--option VALUE" ){|value|
6
+ puts "option=#{value}"
7
+ }
8
+ on( "--version" ){
9
+ puts "version=#{Ult::VERSION}"
10
+ }
11
+ parse!( ARGV )
12
+ }
13
+ puts "ARGV=#{ARGV}"
@@ -0,0 +1,7 @@
1
+ require "ult"
2
+ extend Ult
3
+
4
+ puts "platform=#{platform}"
5
+ puts "mac?=#{mac?}"
6
+ puts "linux?=#{linux?}"
7
+ puts "windows?=#{windows?}"
data/sample/replica.rb ADDED
@@ -0,0 +1,13 @@
1
+ require "ult"
2
+ extend Ult
3
+
4
+ tmp_dir = "__tmp__"
5
+ mkdir( tmp_dir ){
6
+ mkdir( "dir" ){
7
+ mkfile( "file.txt", "w" )
8
+ replica( 3, "file", ".txt" )
9
+ }
10
+ replica( 2, "dir" )
11
+ status, outputs = execute( "ls -laR" )
12
+ puts outputs
13
+ }
data/sample/safety.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "ult"
2
+ extend Ult
3
+
4
+ safety{
5
+ puts "pwd=#{pwd}"
6
+ }
7
+
8
+ safety{
9
+ dir( ".." ){
10
+ xyz
11
+ }
12
+ }
@@ -0,0 +1,9 @@
1
+ require "ult"
2
+ extend Ult
3
+
4
+ count = 0
5
+ watchdog( "date" ){|status, outputs, errors|
6
+ p [ count, status, outputs, errors ]
7
+ count += 1
8
+ ( count < 3 )
9
+ }
data/ult.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ult/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ult"
8
+ spec.version = Ult::VERSION
9
+ spec.licenses = [ "MIT" ]
10
+ spec.authors = ["liveralmask"]
11
+ spec.email = ["liveralmask.lisk@gmail.com"]
12
+
13
+ spec.summary = %q{Ultimate tools that work anywhere.}
14
+ spec.description = %q{Ultimate tools that work anywhere.}
15
+ spec.homepage = "https://github.com/liveralmask/ult"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ult
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ platform: ruby
6
+ authors:
7
+ - liveralmask
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-04 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: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Ultimate tools that work anywhere.
42
+ email:
43
+ - liveralmask.lisk@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/ult.rb
56
+ - lib/ult/assert.rb
57
+ - lib/ult/copy.rb
58
+ - lib/ult/dir.rb
59
+ - lib/ult/execute.rb
60
+ - lib/ult/file.rb
61
+ - lib/ult/find.rb
62
+ - lib/ult/option.rb
63
+ - lib/ult/path.rb
64
+ - lib/ult/platform.rb
65
+ - lib/ult/remove.rb
66
+ - lib/ult/replica.rb
67
+ - lib/ult/safety.rb
68
+ - lib/ult/version.rb
69
+ - lib/ult/watchdog.rb
70
+ - sample/assert.rb
71
+ - sample/dir.rb
72
+ - sample/execute.rb
73
+ - sample/file.rb
74
+ - sample/find.rb
75
+ - sample/option.rb
76
+ - sample/platform.rb
77
+ - sample/replica.rb
78
+ - sample/safety.rb
79
+ - sample/watchdog.rb
80
+ - ult.gemspec
81
+ homepage: https://github.com/liveralmask/ult
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.5.2.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Ultimate tools that work anywhere.
105
+ test_files: []