u8 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
+ SHA1:
3
+ metadata.gz: 8dac835625be402f82da5a3d2b9d175478e3ecfd
4
+ data.tar.gz: 9c613c20d60b1642704dda0d100ab8e03609943b
5
+ SHA512:
6
+ metadata.gz: 2b26be60df15b899b35d89b23108303c970ede65a777feaacfda89a3cc3d5b2954f1225ce3e3e17cbbf56b59eac78c91f64ec648c51abab45145db6c7f5d8ca4
7
+ data.tar.gz: c59f8a5fc70827e698dd396a818e8679c98d2b9ffbbdc22c4bfcb9dda67f08900b82d1e774eebb366615a403b45e71c3465aaaa468aa94d6c7740b9a659eb51e
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # eval-U8 shell commands in ruby code!
2
+
3
+ Evaluate an `ls` and put it's contents (a list of files) into the files variable.
4
+
5
+ files = U8.ls
6
+
7
+ If you want to drop the U8 namespace, you can `shell` and refer to commands directly. For instance:
8
+
9
+ Eval an ls, then map the elements to the contents of each file.
10
+
11
+ U8.shell do
12
+
13
+ ls.map{|file| cat file}
14
+
15
+ end
16
+
17
+ `U8.interactive` will allow you to run arbitrary commands, and print their results.
18
+
19
+ Try running `rash` from the `bin` directory if you would like to try the poor man's ruby shell.
20
+
21
+ Building a shell wrapper?
22
+
23
+ git = U8.command :git
24
+
25
+ git :add, filename
26
+ git :commit
27
+
28
+ Or
29
+
30
+ curl = U8.command :curl, prefix: '--'
31
+ curl 'http://www.awesome.com'
data/bin/rash ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/u8'
4
+
5
+ U8.interactive
data/lib/u8.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'u8/command'
2
+
3
+ module U8
4
+ class << self
5
+
6
+ def _
7
+ @_
8
+ end
9
+
10
+ def echo *args
11
+ args = args.is_a?(Array) ? args.join("\n") : args
12
+ puts args.to_s
13
+ end
14
+
15
+ #def config
16
+ def command cmd, args={}
17
+ U8::Command.new(cmd,args)
18
+ end
19
+
20
+ def shell &block
21
+ U8.instance_eval &block
22
+ end
23
+
24
+ def interactive
25
+ while 1
26
+ echo eval(gets)
27
+ end
28
+ rescue StandardError => e
29
+ echo e.message
30
+ interactive
31
+ end
32
+
33
+ private
34
+
35
+ def exec name, args
36
+ `cd #{@dir};#{exec_s(name,args_to_s(args))}`
37
+ end
38
+
39
+ def exec_s name, args
40
+ "#{name} #{args_to_s(args)}"
41
+ end
42
+
43
+ def method_missing(name, *args, &block)
44
+ #move to own method
45
+ @_ = exec(name,args).split("\n")
46
+ end
47
+
48
+ def args_to_s options, args
49
+ if args.is_a? Hash
50
+ options[:equals] = '=' if options[:equals] == true
51
+ equals = options[:equals]
52
+ equals ||= ' '
53
+ args = args.collect{|k,v|
54
+ args[k] = "#{k}#{equals}#{v}"
55
+ }
56
+
57
+ end
58
+
59
+ prefix = options[:prefix] || ''
60
+
61
+ args.map{ |arg|
62
+ "#{prefix}#{arg}"
63
+ }.join(" ")
64
+ end
65
+
66
+ end
67
+ end
data/lib/u8/command.rb ADDED
@@ -0,0 +1,14 @@
1
+ module U8
2
+ class Command
3
+
4
+ def initialize cmd, args={}
5
+ @cmd = cmd.to_sym
6
+ @options = args
7
+ end
8
+
9
+ def method_missing *args
10
+ @options
11
+ U8.class_eval :exec, @cmd, args
12
+ end
13
+ end
14
+ end
data/lib/u8/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module U8
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe U8::Command do
4
+ context 'no args' do
5
+ let(:git) { U8.command :git }
6
+
7
+ it 'returns a U8::Command' do
8
+ expect(git).to be_a(U8::Command)
9
+ end
10
+
11
+ it 'sets cmd' do
12
+ expect(git.instance_variable_get(:@cmd)).to eq(:git)
13
+ end
14
+
15
+ it 'sets options' do
16
+ expect(git.instance_variable_get(:@options)).to be_a(Hash)
17
+ end
18
+
19
+ end
20
+
21
+ context 'args' do
22
+ let(:git) { U8.command :git, equals: true }
23
+
24
+ it 'sets options' do
25
+ options = git.instance_variable_get(:@options)
26
+ expect(options[:equals]).to eq(true)
27
+ end
28
+ end
29
+
30
+ context 'executes' do
31
+ let(:git) { U8.command :git }
32
+
33
+ before do
34
+ #allow(git).to_receive(:git)
35
+ git.stub(:exec)#.with(:git, {equals:true})
36
+ end
37
+
38
+ it 'execs without options' do
39
+ #expect(git()).to receive(:exec)#.with(:git, {equals:true})
40
+ end
41
+
42
+ it 'execs with array options' do
43
+ pending 'implement arrays'
44
+ expect(
45
+ git.call :commit
46
+ ).to receive(:exec).with(:git, {equals:true})
47
+
48
+ expect(
49
+ git.call :commit, '--add', '--amend'
50
+ ).to receive(:exec)#.with(:git, {equals:true})
51
+ end
52
+
53
+ end
54
+
55
+ context 'execs with hash options' do
56
+ let(:curl) { U8.command :curl, { config: 'filename' } }
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ require_relative '../lib/u8'
2
+ require 'rspec'
data/spec/u8_spec.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe U8 do
4
+ it 'concats string args' do
5
+ #expect(args_to_s 'var1=val1', 'var2=val2').to be("var1=val1 var2=val2")
6
+ end
7
+
8
+ context 'equals' do
9
+ let(:options){ {equals: true} }
10
+
11
+ it 'puts equals on args' do
12
+ expect(
13
+ args_to_s(options, {
14
+ var1: :val1,
15
+ var2: :val2
16
+ })
17
+ ).to eq("var1=val1 var2=val2")
18
+ end
19
+
20
+ end
21
+
22
+ context 'equals and prefix' do
23
+ let(:options){ {equals: true, prefix: '--'} }
24
+
25
+ it 'puts equals and prefix on args' do
26
+ expect(
27
+ args_to_s(options, {
28
+ var1: :val1,
29
+ var2: :val2
30
+ })
31
+ ).to eq("--var1=val1 --var2=val2")
32
+ end
33
+
34
+ end
35
+
36
+ def args_to_s options, args
37
+ U8.class_eval do
38
+ args_to_s options, args
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: u8
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Trevor Grayson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-06 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: :runtime
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: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
41
+ description: Run shell commands with models instead of running strings
42
+ email: trevor@ipsumllc.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - README.md
48
+ - bin/rash
49
+ - lib/u8.rb
50
+ - lib/u8/command.rb
51
+ - lib/u8/version.rb
52
+ - spec/command_spec.rb
53
+ - spec/spec_helper.rb
54
+ - spec/u8_spec.rb
55
+ homepage: http://github.com/trevorgrayson/u8
56
+ licenses: []
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.4.5.1
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Eval-U8 BASH commands in clean ruby
78
+ test_files: []