replr 0.1.0
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 +7 -0
- data/Gemfile +0 -0
- data/bin/replr +4 -0
- data/lib/Dockerfile +10 -0
- data/lib/replr-bootstrap.rb +5 -0
- data/lib/replr.rb +120 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 58a0543730c0372f9d5eecf116cf3ec4102d2bdba7284f236ab4947632fb5ec4
|
4
|
+
data.tar.gz: 8b2c8f16734f430ced519d19ed88da31a53cdf143e8cfedc81bdcf050f49b8e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d158e76fc4ce5d56aadd0e3de342fed7747aaee553dd707e1936ac5a8a33aa8bf201c71b1f2ae8e5a9b223996a1cf67f02cf23152504d31832a26108907bfe8
|
7
|
+
data.tar.gz: 4e7aeb75471a39496cc0b04f2958982eb46986fa3f733576255f06231b0fa5c58436f90c23854fda64e3b8043eef4ff76bb4d4655758cd0753404c53e76f385d
|
data/Gemfile
ADDED
File without changes
|
data/bin/replr
ADDED
data/lib/Dockerfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
FROM ruby:2.3.1-alpine
|
2
|
+
ADD Gemfile /app/
|
3
|
+
RUN apk --update add --virtual build-dependencies ruby-dev build-base && \
|
4
|
+
gem install bundler --no-ri --no-rdoc && \
|
5
|
+
cd /app ; bundle install --without development test && \
|
6
|
+
apk del build-dependencies
|
7
|
+
ADD . /app
|
8
|
+
ENV RACK_ENV production
|
9
|
+
WORKDIR /app
|
10
|
+
CMD ["bundle", "exec", "ruby", "replr-bootstrap.rb"]
|
data/lib/replr.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
# :nodoc:
|
5
|
+
class Replr
|
6
|
+
attr_reader :arguments, :workdir, :docker_image_tag
|
7
|
+
|
8
|
+
def start
|
9
|
+
@arguments = ARGV.map { |argument| argument.downcase.strip }
|
10
|
+
|
11
|
+
check_docker!
|
12
|
+
check_argument_length!
|
13
|
+
check_stack!
|
14
|
+
|
15
|
+
@workdir = Dir.mktmpdir
|
16
|
+
@docker_image_tag = "replr/ruby-#{libraries.join('-')}"
|
17
|
+
|
18
|
+
copy_library_file
|
19
|
+
copy_docker_file
|
20
|
+
initialize_docker_repl
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def check_argument_length!
|
26
|
+
if arguments.empty?
|
27
|
+
puts_error 'Usage: replr <stack> <libraries...>'
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def check_stack!
|
33
|
+
unless arguments[0] == 'ruby'
|
34
|
+
puts_error 'Only supports ruby for now'
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def check_docker!
|
40
|
+
unless system('which docker >/dev/null')
|
41
|
+
puts_error 'Needs docker installed & in path to work.'
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def puts_error(string)
|
47
|
+
STDERR.puts(string)
|
48
|
+
end
|
49
|
+
|
50
|
+
def copy_library_file
|
51
|
+
Dir.chdir(workdir) do
|
52
|
+
File.open('Gemfile', 'w') do |f|
|
53
|
+
f.write(library_file_with(libraries))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def copy_docker_file
|
59
|
+
docker_file = "#{__dir__}/Dockerfile"
|
60
|
+
bootstrap_file = "#{__dir__}/replr-bootstrap.rb"
|
61
|
+
FileUtils.cp(docker_file, workdir)
|
62
|
+
FileUtils.cp(bootstrap_file, workdir)
|
63
|
+
end
|
64
|
+
|
65
|
+
def libraries
|
66
|
+
arguments[1..-1]
|
67
|
+
end
|
68
|
+
|
69
|
+
def library_file_with(libraries)
|
70
|
+
gemfile = "source 'https://rubygems.org/'\n"
|
71
|
+
libraries.each do |library|
|
72
|
+
gemfile << "gem '#{library}'\n"
|
73
|
+
end
|
74
|
+
gemfile
|
75
|
+
end
|
76
|
+
|
77
|
+
def initialize_docker_repl
|
78
|
+
Dir.chdir(workdir) do
|
79
|
+
build_command = "docker build -t #{docker_image_tag} ."
|
80
|
+
run_command = "docker run --rm -it #{docker_image_tag}"
|
81
|
+
matching = Regexp.union([/upgrading/i, /installing/i, /gem/i])
|
82
|
+
not_matching = Regexp.union([/step/i])
|
83
|
+
execute_filtered_process(build_command, matching,
|
84
|
+
not_matching) do |stderr, process_thread|
|
85
|
+
execute_command_if_not_stderr(run_command, stderr, process_thread)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Runs *command* and only prints those lines that match
|
91
|
+
# *matching_regex* and doesn't match *not_matching_regex*. After
|
92
|
+
# execution, it passes *stderr* and the waiting *process_thread*
|
93
|
+
# to a block.
|
94
|
+
def execute_filtered_process(command, matching_regex,
|
95
|
+
not_matching_regex, &_block)
|
96
|
+
Open3.popen3(command) do |_stdin, stdout, stderr, process_thread|
|
97
|
+
stdout.each_line do |outline|
|
98
|
+
if outline.match(matching_regex) &&
|
99
|
+
!outline.match(not_matching_regex)
|
100
|
+
puts outline
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
# Yield to block to process next set of commands or handle stderr
|
105
|
+
yield(stderr, process_thread)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Executes *new_command* if the previous *process_thread* had a
|
110
|
+
# non-zero return. Otherwise prints out *stderr* of the previous
|
111
|
+
# process to *STDERR*
|
112
|
+
def execute_command_if_not_stderr(new_command, stderr, process_thread)
|
113
|
+
outerror = stderr.read.chomp
|
114
|
+
if process_thread.value.to_i.zero?
|
115
|
+
system(new_command)
|
116
|
+
else
|
117
|
+
STDERR.puts outerror
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: replr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vishnu Gopal
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: vg@vishnugopal.com
|
15
|
+
executables:
|
16
|
+
- replr
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- Gemfile
|
21
|
+
- bin/replr
|
22
|
+
- lib/Dockerfile
|
23
|
+
- lib/replr-bootstrap.rb
|
24
|
+
- lib/replr.rb
|
25
|
+
homepage: https://github.com/vishnugopal/replr
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.7.7
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: A single line REPL for your favorite languages & libraries.
|
49
|
+
test_files: []
|