rb 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: 44c5ae957bef55382c62dd4e5b5b5da9187df773
4
+ data.tar.gz: 503f9e7b9285906ee2ec3bd3ae215434fa7b70a8
5
+ SHA512:
6
+ metadata.gz: defb984288f226ee5ba38f382be2e5805488e5763a32e2b28d7cc9278184a41aad5acaf1cfa4bb1b564c0c24b9870a88dede244be32c3240b48a8cef76bde59b
7
+ data.tar.gz: f61d3a326f804efd951ed95e589953b140c210d1352ebf5304900ea683d778d521b5586fde81990cf531f847d0c64ad5634eeb64813de4f084351bf4152d43ea
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rb.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 James Brennan
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,67 @@
1
+ # RB
2
+
3
+ irb, shorthand.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rb'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rb
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ $ rb --help
23
+ Usage: rb [options]
24
+ -f, --filter Filter lines from STDIN, as `line`
25
+ -a, --apply Apply commands to lines from STDIN, as `line`
26
+ -j, --json [OPTIONAL] Preprocess input or ouput as JSON
27
+
28
+ $ rb 1 + 1
29
+ 2
30
+
31
+ $ ls | rb -a '"file: #{line}"'
32
+ file: Gemfile
33
+ file: LICENSE.txt
34
+ file: README.md
35
+ file: Rakefile
36
+ file: bin
37
+ file: lib
38
+ file: rb.gemspec
39
+
40
+ $ ls | rb -f 'line == "Gemfile"'
41
+ Gemfile
42
+
43
+ $ ls | bin/rb -a --json output '{ basename: File.basename(line), extname: File.extname(line) }'
44
+ {"basename":"Gemfile","extname":""}
45
+ {"basename":"LICENSE.txt","extname":".txt"}
46
+ {"basename":"README.md","extname":".md"}
47
+ {"basename":"Rakefile","extname":""}
48
+ {"basename":"bin","extname":""}
49
+ {"basename":"lib","extname":""}
50
+ {"basename":"rb.gemspec","extname":".gemspec"}
51
+ ```
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it ( https://github.com/jpb/rb/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
60
+
61
+ ## Author
62
+
63
+ [James Brennan](jamesbrennan.ca)
64
+
65
+ ## Thanks
66
+
67
+ Inspired by [phythonpy](https://github.com/Russell91/pythonpy).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/rb ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ require 'optparse'
7
+ require 'rb/runner'
8
+
9
+ options = {}
10
+
11
+ OptionParser.new do |opts|
12
+
13
+ opts.on('-f', '--filter', 'Filter lines from STDIN, as `line`') do |f|
14
+ options[:filter] = f
15
+ end
16
+
17
+ opts.on('-a', '--apply', 'Apply commands to lines from STDIN, as `line`') do |a|
18
+ options[:apply] = a
19
+ end
20
+
21
+ opts.on('-j [OPTIONAL]', '--json [OPTIONAL]', ['input', 'output'], 'Preprocess input or ouput as JSON') do |j|
22
+ options[:json_input] = (j != 'output')
23
+ options[:json_output] = (j != 'input')
24
+ end
25
+
26
+ end.parse!
27
+
28
+ command = ARGV.join(' ')
29
+ RB::Runner.new(options).run(command)
@@ -0,0 +1,2 @@
1
+ module RB
2
+ end
@@ -0,0 +1,62 @@
1
+ require 'json'
2
+
3
+ module RB
4
+ class Runner
5
+
6
+ def initialize(options)
7
+ @options = options
8
+ end
9
+
10
+ def run(command)
11
+ @command = command
12
+
13
+ case true
14
+ when options[:filter]
15
+ filter
16
+ when options[:apply]
17
+ STDIN.tty? ? apply_to_tty : apply_to_stdin
18
+ else
19
+ puts eval(command)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :options, :command
26
+
27
+ def filter
28
+ STDIN.select do |line|
29
+ line = process_input(line)
30
+ eval(command)
31
+ end.each do |line|
32
+ puts process_output(line)
33
+ end
34
+ end
35
+
36
+ def apply_to_tty
37
+ while line = STDIN.gets do
38
+ line = process_input(line)
39
+ puts "=> #{eval(command)}"
40
+ end
41
+ end
42
+
43
+ def apply_to_stdin
44
+ STDIN.each_line do |line|
45
+ line = process_input(line)
46
+ puts process_output(eval(command))
47
+ end
48
+ end
49
+
50
+ def process_input(line)
51
+ line.strip!
52
+ line = JSON.load(line) if options[:json_input]
53
+ line
54
+ end
55
+
56
+ def process_output(line)
57
+ line = JSON.dump(line) if options[:json_output]
58
+ line
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module RB
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rb'
8
+ spec.version = RB::VERSION
9
+ spec.authors = ['James Brennan']
10
+ spec.email = ['james@jamesbrennan.ca']
11
+ spec.summary = 'irb, shorthand'
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split("\n")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.6'
21
+ spec.add_development_dependency 'rake'
22
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - James Brennan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-11 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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
+ description:
42
+ email:
43
+ - james@jamesbrennan.ca
44
+ executables:
45
+ - rb
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/rb
55
+ - lib/rb.rb
56
+ - lib/rb/runner.rb
57
+ - lib/rb/version.rb
58
+ - rb.gemspec
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: irb, shorthand
83
+ test_files: []
84
+ has_rdoc: