rubbish 0.0.0 → 0.1.191210

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8565ae6a8568b45b54f587bba2544ae209f45fbc
4
- data.tar.gz: 8d9b86fac434eb9ceb98e5297ed1e865bdbd2e95
2
+ SHA256:
3
+ metadata.gz: 042fd02674603c2c64373010fa131f5de23e83d677f0439450eb7956275340f0
4
+ data.tar.gz: 82f9d9dc31a0ab7dcb14c9483f79bbe46d1cd5b002d53e00a9e374032593d5b6
5
5
  SHA512:
6
- metadata.gz: c13205744c577ea582537f5753fab0e929c52df2bb503e9148d2851c6c90bf901806954eefa75bba7c78f84fddf8a5b7f4a26bc91bf9e455045e25677a2f4f88
7
- data.tar.gz: da1ab0a3ac56ac2d48349eb7b243eff6754bc282ff25413a31a63552c2d9595eee1641e8f88d16d2f8488110bd35b4e1cd483b1c05f08509fcc22dbd86e32ce4
6
+ metadata.gz: 6429a13123d6f33359074e9a3ce23b2841b6f64a800a9f2463fd18f5fa7112bd869ceb1d7faa206875dd6f2c03a4d8c248829125de6c8f9fdf28b17a90573fc1
7
+ data.tar.gz: 9e7d8a4138c34a0c96801cf4f2cf8b97052402d238f8fc2353f0ecf7f0380071a092c70423e2000c020fe946d8c0729563c95af8bff7760476508c5dc378a41d
@@ -1,34 +1,51 @@
1
- = rubbish
1
+ # rubbish
2
2
 
3
- == DESCRIPTION:
3
+ ## DESCRIPTION:
4
4
 
5
5
  A ruby-ish way to go to the shell.
6
6
 
7
7
  Bash and Fish aware.
8
8
 
9
- == SYNOPSIS:
9
+ ## SYNOPSIS:
10
+
11
+ Although it's easy enough to access the system's default shell from ruby,
12
+ you may want to run a specific shell like fish for it's unique features:
10
13
 
11
14
  require 'rubbish'
12
- extend Rubbish::Fish
13
- a = fish <<FISH
14
- echo "But why???"
15
- FISH
16
- puts a+'Because!!!!'
17
15
 
18
- == FEATURES:
16
+ # Fish features the double splat...
17
+ # reads output and returns it.
18
+ ls_lib = Rubbish.fish('ls lib/**.rb').split #=> ["lib/good.rb", "lib/good/bad.rb", "lib/good/ugly.rb"]
19
+
20
+ # Run a bash script, have it output to STDOUT(read: false)...
21
+ Rubbish.bash <<-BASH, read: false
22
+ echo "Date/Time now: "
23
+ date
24
+ BASH
25
+
26
+ # Rubbish will accept :fish and :bash calls, but
27
+ # you can add other shells... say... ruby?
28
+ # sure, why not:
29
+ Rubbish::SHELL_VERSION[:ruby] = '2.0' # Ensures it's ruby ~>2.0.
30
+ answer = Rubbish.ruby <<-RUBY #=> "11"
31
+ a = 5
32
+ b = 6
33
+ puts a+b
34
+ RUBY
35
+
36
+ ## FEATURES:
19
37
 
20
- Read by default:
38
+ Read(read: true) by default:
21
39
 
22
40
  * Rubbish.shell('bash','echo "OK"') #=> OK
23
- * Rubbish.shell('bash'){|p| p.puts 'echo "OK"'} #=> OK
41
+ * Rubbish.shell('fish'){|p| p.puts 'echo "OK"'} #=> OK
24
42
  * Rubbish.bash('echo "OK"') #=> OK
25
43
  * Rubbish.fish('true') #=> ''
26
- * Rubbish.fish('false') #=> ''
27
44
 
28
- Passing false will not read, but get the exit status instead:
45
+ Exit status instead when not reading(read: false):
29
46
 
30
- * Rubbish.fish('true', false) #=> true
31
- * Rubbish.fish('false', false) #=> false
47
+ * Rubbish.fish('true', read: false) #=> true
48
+ * Rubbish.fish('false', read: false) #=> false
32
49
 
33
50
  An edge case:
34
51
 
@@ -42,15 +59,15 @@ An edge case:
42
59
  puts b # Good
43
60
  puts a # Day!
44
61
 
45
- == INSTALL:
62
+ ## INSTALL:
46
63
 
47
- $ sudo gem install rubbish
64
+ $ gem install rubbish
48
65
 
49
66
  == LICENSE:
50
67
 
51
68
  (The MIT License)
52
69
 
53
- Copyright (c) 2015 carlosjhr64
70
+ Copyright (c) 2019 carlosjhr64
54
71
 
55
72
  Permission is hereby granted, free of charge, to any person obtaining
56
73
  a copy of this software and associated documentation files (the
data/lib/rubbish.rb CHANGED
@@ -1,7 +1,47 @@
1
- require 'rubbish/version'
2
- require 'rubbish/rubbish'
3
- require 'rubbish/bash'
4
- require 'rubbish/fish'
1
+ module Rubbish
2
+ VERSION = '0.1.191210'
3
+ SHELL_VERSION = {bash: nil, fish: nil}
4
+
5
+ def self.shell(sh, script=nil, read: true, &block)
6
+ IO.popen(sh, (read)? 'w+' : 'w') do |psh|
7
+ # No matter what, we know we're going to write first.
8
+ writing = true
9
+ if script
10
+ # We were given the script, so we write it and close.
11
+ psh.write script
12
+ psh.close_write
13
+ writing = false
14
+ end
15
+ if block
16
+ block.call(psh)
17
+ # close if we were writing
18
+ psh.close_write if writing
19
+ end
20
+ # Read if reading
21
+ read = psh.read if read
22
+ end
23
+ read || $?.to_i==0
24
+ end
25
+
26
+ def self.method_missing(shell, *args, &block)
27
+ if args.length.between?(0,2) and SHELL_VERSION.has_key? shell
28
+ if minimum = SHELL_VERSION[shell]
29
+ minimum = Gem::Version.new minimum
30
+ if version = `#{shell} --version`.scan(/\d+\.\d+\.\d+/).first
31
+ version = Gem::Version.new version
32
+ bumped = minimum.bump
33
+ raise "Need #{shell} version ~> #{minimum}" unless version >= minimum and version < bumped
34
+ # need to only check once
35
+ SHELL_VERSION[shell] = nil
36
+ else
37
+ raise "Could not get the #{shell} version"
38
+ end
39
+ end
40
+ return Rubbish.shell(shell.to_s, *args, &block)
41
+ end
42
+ super
43
+ end
44
+ end
5
45
 
6
46
  # Requires:
7
47
  #`ruby`
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubbish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.191210
5
5
  platform: ruby
6
6
  authors:
7
7
  - carlosjhr64
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-26 00:00:00.000000000 Z
11
+ date: 2019-12-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  A ruby-ish way to go to the shell.
@@ -17,23 +17,16 @@ description: |
17
17
  email: carlosjhr64@gmail.com
18
18
  executables: []
19
19
  extensions: []
20
- extra_rdoc_files:
21
- - README.rdoc
20
+ extra_rdoc_files: []
22
21
  files:
23
- - README.rdoc
22
+ - README.md
24
23
  - lib/rubbish.rb
25
- - lib/rubbish/bash.rb
26
- - lib/rubbish/fish.rb
27
- - lib/rubbish/rubbish.rb
28
- - lib/rubbish/version.rb
29
24
  homepage: https://github.com/carlosjhr64/rubbish
30
25
  licenses:
31
26
  - MIT
32
27
  metadata: {}
33
28
  post_install_message:
34
- rdoc_options:
35
- - "--main"
36
- - README.rdoc
29
+ rdoc_options: []
37
30
  require_paths:
38
31
  - lib
39
32
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -47,11 +40,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
40
  - !ruby/object:Gem::Version
48
41
  version: '0'
49
42
  requirements:
50
- - 'ruby: ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]'
51
- - 'bash: GNU bash, version 4.2.53(1)-release (x86_64-redhat-linux-gnu)'
52
- - 'fish: 2.1.1'
53
- rubyforge_project:
54
- rubygems_version: 2.4.5.1
43
+ - 'ruby: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]'
44
+ - 'bash: GNU bash, version 5.0.11(1)-release (x86_64-redhat-linux-gnu)'
45
+ - 'fish: fish, version 3.0.2'
46
+ rubygems_version: 3.0.3
55
47
  signing_key:
56
48
  specification_version: 4
57
49
  summary: A ruby-ish way to go to the shell.
data/lib/rubbish/bash.rb DELETED
@@ -1,17 +0,0 @@
1
- module Rubbish
2
-
3
- module Bash
4
- @@sh = 'bash'
5
- def self.sh=(sh)
6
- @@sh = sh
7
- end
8
- def self.sh
9
- @@sh
10
- end
11
- def bash(a=nil, b=nil, &c)
12
- Rubbish.shell(Bash.sh, a, b, &c)
13
- end
14
- end
15
- extend Bash
16
-
17
- end
data/lib/rubbish/fish.rb DELETED
@@ -1,17 +0,0 @@
1
- module Rubbish
2
-
3
- module Fish
4
- @@sh = 'fish'
5
- def self.sh=(sh)
6
- @@sh = sh
7
- end
8
- def self.sh
9
- @@sh
10
- end
11
- def fish(a=nil, b=nil, &c)
12
- Rubbish.shell(Fish.sh, a, b, &c)
13
- end
14
- end
15
- extend Fish
16
-
17
- end
@@ -1,27 +0,0 @@
1
- module Rubbish
2
-
3
- def self.shell(sh, a=nil, b=nil, &block)
4
- script = [a,b].detect{|c|c.kind_of?(String)}
5
- read = [a,b].detect{|c|c==true||c==false}
6
- read = true if read.nil?
7
- IO.popen(sh, (read)? 'w+' : 'w') do |psh|
8
- # No matter what, we know we're going to write first.
9
- writing = true
10
- if script.class == String
11
- # We were given the script, so we write it and close.
12
- psh.write script
13
- psh.close_write
14
- writing = false
15
- end
16
- if block
17
- block.call(psh)
18
- # close if we were writing
19
- psh.close_write if writing
20
- end
21
- # Read if reading
22
- read = psh.read if read
23
- end
24
- read || $?.to_i==0
25
- end
26
-
27
- end
@@ -1,3 +0,0 @@
1
- module Rubbish
2
- VERSION = '0.0.0'
3
- end