iruby 0.7.3 → 0.8.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 +4 -4
- data/.github/workflows/ci.yml +119 -0
- data/CHANGES.md +28 -0
- data/README.md +59 -51
- data/Rakefile +2 -1
- data/exe/iruby +7 -0
- data/ext/Rakefile +19 -0
- data/iruby.gemspec +7 -1
- data/lib/iruby/application.rb +380 -0
- data/lib/iruby/backend.rb +11 -2
- data/lib/iruby/error.rb +12 -0
- data/lib/iruby/jupyter.rb +4 -1
- data/lib/iruby/kernel.rb +4 -2
- data/lib/iruby/kernel_app.rb +108 -0
- data/lib/iruby/logger.rb +12 -2
- data/lib/iruby/session/mixin.rb +1 -1
- data/lib/iruby/session.rb +2 -0
- data/lib/iruby/session_adapter.rb +3 -2
- data/lib/iruby/version.rb +1 -1
- data/test/helper.rb +22 -3
- data/test/integration_test.rb +7 -1
- data/test/iruby/application/application_test.rb +32 -0
- data/test/iruby/application/console_test.rb +97 -0
- data/test/iruby/application/helper.rb +38 -0
- data/test/iruby/application/kernel_test.rb +93 -0
- data/test/iruby/application/register_test.rb +139 -0
- data/test/iruby/application/unregister_test.rb +77 -0
- data/test/iruby/jupyter_test.rb +27 -15
- data/test/iruby/kernel_test.rb +0 -2
- data/test/iruby/multi_logger_test.rb +13 -0
- data/test/iruby/session_adapter_test.rb +0 -28
- data/test/iruby/session_test.rb +0 -4
- data/test/run-test.rb +1 -0
- metadata +57 -15
- data/.github/workflows/ubuntu.yml +0 -69
- data/bin/iruby +0 -5
- data/lib/iruby/command.rb +0 -190
- data/lib/iruby/session_adapter/pyzmq_adapter.rb +0 -77
- data/test/iruby/command_test.rb +0 -207
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Mendler
|
8
8
|
- The SciRuby developers
|
9
|
-
autorequire:
|
10
|
-
bindir:
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: data_uri
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: logger
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: mime-types
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,6 +95,20 @@ dependencies:
|
|
81
95
|
- - "~>"
|
82
96
|
- !ruby/object:Gem::Version
|
83
97
|
version: '1.11'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: native-package-installer
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
84
112
|
- !ruby/object:Gem::Dependency
|
85
113
|
name: pycall
|
86
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,32 +170,35 @@ email:
|
|
142
170
|
- mail@daniel-mendler.de
|
143
171
|
executables:
|
144
172
|
- iruby
|
145
|
-
extensions:
|
173
|
+
extensions:
|
174
|
+
- ext/Rakefile
|
146
175
|
extra_rdoc_files: []
|
147
176
|
files:
|
148
|
-
- ".github/workflows/
|
177
|
+
- ".github/workflows/ci.yml"
|
149
178
|
- ".gitignore"
|
150
179
|
- CHANGES.md
|
151
180
|
- Gemfile
|
152
181
|
- LICENSE
|
153
182
|
- README.md
|
154
183
|
- Rakefile
|
155
|
-
- bin/iruby
|
156
184
|
- ci/Dockerfile.base.erb
|
157
185
|
- ci/Dockerfile.main.erb
|
158
186
|
- ci/requirements.txt
|
159
187
|
- docker/setup.sh
|
160
188
|
- docker/test.sh
|
189
|
+
- exe/iruby
|
190
|
+
- ext/Rakefile
|
161
191
|
- iruby.gemspec
|
162
192
|
- lib/iruby.rb
|
193
|
+
- lib/iruby/application.rb
|
163
194
|
- lib/iruby/assets/kernel.css
|
164
195
|
- lib/iruby/assets/kernel.js
|
165
196
|
- lib/iruby/assets/logo-32x32.png
|
166
197
|
- lib/iruby/assets/logo-64x64.png
|
167
198
|
- lib/iruby/backend.rb
|
168
199
|
- lib/iruby/comm.rb
|
169
|
-
- lib/iruby/command.rb
|
170
200
|
- lib/iruby/display.rb
|
201
|
+
- lib/iruby/error.rb
|
171
202
|
- lib/iruby/event_manager.rb
|
172
203
|
- lib/iruby/formatter.rb
|
173
204
|
- lib/iruby/input.rb
|
@@ -191,6 +222,7 @@ files:
|
|
191
222
|
- lib/iruby/input/widget.rb
|
192
223
|
- lib/iruby/jupyter.rb
|
193
224
|
- lib/iruby/kernel.rb
|
225
|
+
- lib/iruby/kernel_app.rb
|
194
226
|
- lib/iruby/logger.rb
|
195
227
|
- lib/iruby/ostream.rb
|
196
228
|
- lib/iruby/session.rb
|
@@ -200,7 +232,6 @@ files:
|
|
200
232
|
- lib/iruby/session_adapter.rb
|
201
233
|
- lib/iruby/session_adapter/cztop_adapter.rb
|
202
234
|
- lib/iruby/session_adapter/ffirzmq_adapter.rb
|
203
|
-
- lib/iruby/session_adapter/pyzmq_adapter.rb
|
204
235
|
- lib/iruby/session_adapter/test_adapter.rb
|
205
236
|
- lib/iruby/utils.rb
|
206
237
|
- lib/iruby/version.rb
|
@@ -211,8 +242,13 @@ files:
|
|
211
242
|
- tasks/ci.rake
|
212
243
|
- test/helper.rb
|
213
244
|
- test/integration_test.rb
|
245
|
+
- test/iruby/application/application_test.rb
|
246
|
+
- test/iruby/application/console_test.rb
|
247
|
+
- test/iruby/application/helper.rb
|
248
|
+
- test/iruby/application/kernel_test.rb
|
249
|
+
- test/iruby/application/register_test.rb
|
250
|
+
- test/iruby/application/unregister_test.rb
|
214
251
|
- test/iruby/backend_test.rb
|
215
|
-
- test/iruby/command_test.rb
|
216
252
|
- test/iruby/display_test.rb
|
217
253
|
- test/iruby/event_manager_test.rb
|
218
254
|
- test/iruby/jupyter_test.rb
|
@@ -229,8 +265,9 @@ files:
|
|
229
265
|
homepage: https://github.com/SciRuby/iruby
|
230
266
|
licenses:
|
231
267
|
- MIT
|
232
|
-
metadata:
|
233
|
-
|
268
|
+
metadata:
|
269
|
+
msys2_mingw_dependencies: zeromq
|
270
|
+
post_install_message:
|
234
271
|
rdoc_options: []
|
235
272
|
require_paths:
|
236
273
|
- lib
|
@@ -245,15 +282,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
282
|
- !ruby/object:Gem::Version
|
246
283
|
version: '0'
|
247
284
|
requirements: []
|
248
|
-
rubygems_version: 3.
|
249
|
-
signing_key:
|
285
|
+
rubygems_version: 3.5.11
|
286
|
+
signing_key:
|
250
287
|
specification_version: 4
|
251
288
|
summary: Ruby Kernel for Jupyter
|
252
289
|
test_files:
|
253
290
|
- test/helper.rb
|
254
291
|
- test/integration_test.rb
|
292
|
+
- test/iruby/application/application_test.rb
|
293
|
+
- test/iruby/application/console_test.rb
|
294
|
+
- test/iruby/application/helper.rb
|
295
|
+
- test/iruby/application/kernel_test.rb
|
296
|
+
- test/iruby/application/register_test.rb
|
297
|
+
- test/iruby/application/unregister_test.rb
|
255
298
|
- test/iruby/backend_test.rb
|
256
|
-
- test/iruby/command_test.rb
|
257
299
|
- test/iruby/display_test.rb
|
258
300
|
- test/iruby/event_manager_test.rb
|
259
301
|
- test/iruby/jupyter_test.rb
|
@@ -1,69 +0,0 @@
|
|
1
|
-
name: CI
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches:
|
6
|
-
- master
|
7
|
-
pull_request:
|
8
|
-
types:
|
9
|
-
- opened
|
10
|
-
- synchronize
|
11
|
-
- reopened
|
12
|
-
|
13
|
-
jobs:
|
14
|
-
test:
|
15
|
-
name: Test
|
16
|
-
runs-on: ${{ matrix.os }}
|
17
|
-
|
18
|
-
strategy:
|
19
|
-
fail-fast: false
|
20
|
-
matrix:
|
21
|
-
os:
|
22
|
-
- ubuntu-20.04
|
23
|
-
- ubuntu-latest
|
24
|
-
ruby:
|
25
|
-
- 3.0
|
26
|
-
- 2.7
|
27
|
-
- 2.6
|
28
|
-
- 2.5
|
29
|
-
- 2.4
|
30
|
-
- 2.3
|
31
|
-
- debug
|
32
|
-
|
33
|
-
steps:
|
34
|
-
- uses: actions/checkout@v2
|
35
|
-
with:
|
36
|
-
fetch-depth: 1
|
37
|
-
|
38
|
-
- uses: ruby/setup-ruby@v1
|
39
|
-
with:
|
40
|
-
ruby-version: ${{ matrix.ruby }}
|
41
|
-
|
42
|
-
- name: Install requirements on ubuntu
|
43
|
-
run: |
|
44
|
-
sudo apt update
|
45
|
-
sudo apt install -y --no-install-recommends \
|
46
|
-
libczmq-dev \
|
47
|
-
python3 \
|
48
|
-
python3-pip \
|
49
|
-
python3-setuptools
|
50
|
-
sudo pip3 install wheel
|
51
|
-
sudo pip3 install -r ci/requirements.txt
|
52
|
-
|
53
|
-
- run: gem install bundler
|
54
|
-
|
55
|
-
- run: bundle install --jobs 4 --retry 3
|
56
|
-
|
57
|
-
- name: Run tests
|
58
|
-
env:
|
59
|
-
PYTHON: python3
|
60
|
-
ADAPTERS: cztop ffi-rzmq pyzmq
|
61
|
-
run: |
|
62
|
-
for adapter in $ADAPTERS; do
|
63
|
-
export IRUBY_TEST_SESSION_ADAPTER_NAME=$adapter
|
64
|
-
bundle exec rake test TESTOPTS=-v
|
65
|
-
done
|
66
|
-
|
67
|
-
- run: rake build
|
68
|
-
|
69
|
-
- run: gem install pkg/*.gem
|
data/bin/iruby
DELETED
data/lib/iruby/command.rb
DELETED
@@ -1,190 +0,0 @@
|
|
1
|
-
require 'iruby'
|
2
|
-
|
3
|
-
module IRuby
|
4
|
-
class Command
|
5
|
-
def initialize(args)
|
6
|
-
@args = args
|
7
|
-
|
8
|
-
@ipython_dir = File.expand_path("~/.ipython")
|
9
|
-
@kernel_dir = resolve_kernelspec_dir.freeze
|
10
|
-
@kernel_file = File.join(@kernel_dir, 'kernel.json').freeze
|
11
|
-
@iruby_path = File.expand_path $0
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_reader :ipython_dir, :kernel_dir, :kernel_file
|
15
|
-
|
16
|
-
def ipython_kernel_dir
|
17
|
-
File.join(File.expand_path(@ipython_dir), 'kernels', 'ruby')
|
18
|
-
end
|
19
|
-
|
20
|
-
def run
|
21
|
-
case @args.first
|
22
|
-
when 'version', '-v', '--version'
|
23
|
-
require 'iruby/version'
|
24
|
-
puts "IRuby #{IRuby::VERSION}, Ruby #{RUBY_VERSION}"
|
25
|
-
when 'help', '-h', '--help'
|
26
|
-
print_help
|
27
|
-
when 'register'
|
28
|
-
force_p = @args.include?('--force')
|
29
|
-
if registered_iruby_path && !force_p
|
30
|
-
STDERR.puts "#{@kernel_file} already exists!\nUse --force to force a register."
|
31
|
-
exit 1
|
32
|
-
end
|
33
|
-
register_kernel(force_p)
|
34
|
-
when 'unregister'
|
35
|
-
unregister_kernel
|
36
|
-
when 'kernel'
|
37
|
-
run_kernel
|
38
|
-
else
|
39
|
-
run_ipython
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def resolve_kernelspec_dir
|
46
|
-
if ENV.has_key?('JUPYTER_DATA_DIR')
|
47
|
-
if ENV.has_key?('IPYTHONDIR')
|
48
|
-
warn 'both JUPYTER_DATA_DIR and IPYTHONDIR are supplied; IPYTHONDIR is ignored.'
|
49
|
-
end
|
50
|
-
if @args.find {|x| /\A--ipython-dir=/ =~ x }
|
51
|
-
warn 'both JUPYTER_DATA_DIR and --ipython-dir are supplied; --ipython-dir is ignored.'
|
52
|
-
end
|
53
|
-
jupyter_data_dir = ENV['JUPYTER_DATA_DIR']
|
54
|
-
return File.join(jupyter_data_dir, 'kernels', 'ruby')
|
55
|
-
end
|
56
|
-
|
57
|
-
if ENV.has_key?('IPYTHONDIR')
|
58
|
-
warn 'IPYTHONDIR is deprecated. Use JUPYTER_DATA_DIR instead.'
|
59
|
-
ipython_dir = ENV['IPYTHONDIR']
|
60
|
-
end
|
61
|
-
|
62
|
-
@args.each do |arg|
|
63
|
-
next unless /\A--ipython-dir=(.*)\Z/ =~ arg
|
64
|
-
ipython_dir = Regexp.last_match[1]
|
65
|
-
warn '--ipython-dir is deprecated. Use JUPYTER_DATA_DIR environment variable instead.'
|
66
|
-
break
|
67
|
-
end
|
68
|
-
|
69
|
-
if ipython_dir
|
70
|
-
@ipython_dir = ipython_dir
|
71
|
-
ipython_kernel_dir
|
72
|
-
else
|
73
|
-
File.join(Jupyter.kernelspec_dir, 'ruby')
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def print_help
|
78
|
-
puts %{
|
79
|
-
Usage:
|
80
|
-
iruby register Register IRuby kernel in #{@kernel_file}.
|
81
|
-
iruby unregister Unregister IRuby kernel.
|
82
|
-
iruby console Launch the IRuby terminal-based console.
|
83
|
-
iruby notebook Launch the IRuby HTML notebook server.
|
84
|
-
... Same as IPython.
|
85
|
-
|
86
|
-
Please note that IRuby accepts the same parameters as IPython.
|
87
|
-
Try `ipython help` for more information.
|
88
|
-
}
|
89
|
-
end
|
90
|
-
|
91
|
-
def run_kernel
|
92
|
-
IRuby.logger = MultiLogger.new(*Logger.new(STDOUT))
|
93
|
-
STDOUT.sync = true # FIXME: This can make the integration test.
|
94
|
-
|
95
|
-
@args.reject! {|arg| arg =~ /\A--log=(.*)\Z/ && IRuby.logger.loggers << Logger.new($1) }
|
96
|
-
IRuby.logger.level = @args.delete('--debug') ? Logger::DEBUG : Logger::INFO
|
97
|
-
|
98
|
-
raise(ArgumentError, 'Not enough arguments to the kernel') if @args.size < 2 || @args.size > 4
|
99
|
-
config_file, boot_file, working_dir = @args[1..-1]
|
100
|
-
Dir.chdir(working_dir) if working_dir
|
101
|
-
|
102
|
-
require boot_file if boot_file
|
103
|
-
check_bundler {|e| IRuby.logger.warn "Could not load bundler: #{e.message}" }
|
104
|
-
|
105
|
-
require 'iruby'
|
106
|
-
Kernel.new(config_file).run
|
107
|
-
rescue Exception => e
|
108
|
-
IRuby.logger.fatal "Kernel died: #{e.message}\n#{e.backtrace.join("\n")}"
|
109
|
-
raise
|
110
|
-
end
|
111
|
-
|
112
|
-
def check_version
|
113
|
-
required = '3.0.0'
|
114
|
-
version = `ipython --version`.chomp
|
115
|
-
if version < required
|
116
|
-
STDERR.puts "Your IPython version #{version} is too old, at least #{required} is required"
|
117
|
-
exit 1
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def run_ipython
|
122
|
-
# If no command is given, we use the console to launch the whole 0MQ-client-server stack
|
123
|
-
@args = %w(console) + @args if @args.first.to_s !~ /\A\w/
|
124
|
-
@args += %w(--kernel ruby) if %w(console qtconsole).include? @args.first
|
125
|
-
|
126
|
-
check_version
|
127
|
-
check_registered_kernel
|
128
|
-
check_bundler {|e| STDERR.puts "Could not load bundler: #{e.message}" }
|
129
|
-
|
130
|
-
Process.exec('ipython', *@args)
|
131
|
-
end
|
132
|
-
|
133
|
-
def check_registered_kernel
|
134
|
-
if (kernel = registered_iruby_path)
|
135
|
-
STDERR.puts "#{@iruby_path} differs from registered path #{registered_iruby_path}.
|
136
|
-
This might not work. Run 'iruby register --force' to fix it." if @iruby_path != kernel
|
137
|
-
else
|
138
|
-
register_kernel
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def check_bundler
|
143
|
-
require 'bundler'
|
144
|
-
raise %q{iruby is missing from Gemfile. This might not work.
|
145
|
-
Add `gem 'iruby'` to your Gemfile to fix it.} unless Bundler.definition.specs.any? {|s| s.name == 'iruby' }
|
146
|
-
Bundler.setup
|
147
|
-
rescue LoadError
|
148
|
-
rescue Exception => e
|
149
|
-
yield(e)
|
150
|
-
end
|
151
|
-
|
152
|
-
def register_kernel(force_p=false)
|
153
|
-
if force_p
|
154
|
-
unregister_kernel_in_ipython_dir
|
155
|
-
else
|
156
|
-
return unless check_existing_kernel_in_ipython_dir
|
157
|
-
end
|
158
|
-
FileUtils.mkpath(@kernel_dir)
|
159
|
-
unless RUBY_PLATFORM =~ /mswin(?!ce)|mingw|cygwin/
|
160
|
-
File.write(@kernel_file, MultiJson.dump(argv: [ @iruby_path, 'kernel', '{connection_file}' ],
|
161
|
-
display_name: "Ruby #{RUBY_VERSION}", language: 'ruby'))
|
162
|
-
else
|
163
|
-
ruby_path, iruby_path = [RbConfig.ruby, @iruby_path].map{|path| path.gsub('/', '\\\\')}
|
164
|
-
File.write(@kernel_file, MultiJson.dump(argv: [ ruby_path, iruby_path, 'kernel', '{connection_file}' ],
|
165
|
-
display_name: "Ruby #{RUBY_VERSION}", language: 'ruby'))
|
166
|
-
end
|
167
|
-
|
168
|
-
FileUtils.copy(Dir[File.join(__dir__, 'assets', '*')], @kernel_dir) rescue nil
|
169
|
-
end
|
170
|
-
|
171
|
-
def check_existing_kernel_in_ipython_dir
|
172
|
-
return true unless File.file?(File.join(ipython_kernel_dir, 'kernel.json'))
|
173
|
-
warn "IRuby kernel file already exists in the deprecated IPython's data directory."
|
174
|
-
warn "Using --force, you can replace the old kernel file with the new one in Jupyter's data directory."
|
175
|
-
false
|
176
|
-
end
|
177
|
-
|
178
|
-
def registered_iruby_path
|
179
|
-
File.exist?(@kernel_file) && MultiJson.load(File.read(@kernel_file))['argv'].first
|
180
|
-
end
|
181
|
-
|
182
|
-
def unregister_kernel
|
183
|
-
FileUtils.rm_rf(@kernel_dir)
|
184
|
-
end
|
185
|
-
|
186
|
-
def unregister_kernel_in_ipython_dir
|
187
|
-
FileUtils.rm_rf(ipython_kernel_dir)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
module IRuby
|
2
|
-
module SessionAdapter
|
3
|
-
class PyzmqAdapter < BaseAdapter
|
4
|
-
|
5
|
-
class << self
|
6
|
-
def load_requirements
|
7
|
-
require 'pycall'
|
8
|
-
import_pyzmq
|
9
|
-
end
|
10
|
-
|
11
|
-
def import_pyzmq
|
12
|
-
@zmq = PyCall.import_module('zmq')
|
13
|
-
rescue PyCall::PyError => error
|
14
|
-
raise LoadError, error.message
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :zmq
|
18
|
-
end
|
19
|
-
|
20
|
-
def make_router_socket(protocol, host, port)
|
21
|
-
make_socket(:ROUTER, protocol, host, port)
|
22
|
-
end
|
23
|
-
|
24
|
-
def make_pub_socket(protocol, host, port)
|
25
|
-
make_socket(:PUB, protocol, host, port)
|
26
|
-
end
|
27
|
-
|
28
|
-
def heartbeat_loop(sock)
|
29
|
-
PyCall.sys.path.append(File.expand_path('../pyzmq', __FILE__))
|
30
|
-
heartbeat = PyCall.import_module('iruby.heartbeat')
|
31
|
-
@heartbeat_thread = heartbeat.Heartbeat.new(sock)
|
32
|
-
@heartbeat_thread.start
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def socket_type(type_symbol)
|
38
|
-
case type_symbol
|
39
|
-
when :ROUTER, :PUB, :REP
|
40
|
-
zmq[type_symbol]
|
41
|
-
else
|
42
|
-
raise ArgumentError, "Unknown ZMQ socket type: #{type_symbol}"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def make_socket(type_symbol, protocol, host, port)
|
47
|
-
type = socket_type(type_symbol)
|
48
|
-
sock = zmq_context.socket(type)
|
49
|
-
bind_socket(sock, protocol, host, port)
|
50
|
-
sock
|
51
|
-
end
|
52
|
-
|
53
|
-
def bind_socket(sock, protocol, host, port)
|
54
|
-
iface = "#{protocol}://#{host}"
|
55
|
-
case protocol
|
56
|
-
when 'tcp'
|
57
|
-
if port <= 0
|
58
|
-
port = sock.bind_to_random_port(iface)
|
59
|
-
else
|
60
|
-
sock.bind("#{iface}:#{port}")
|
61
|
-
end
|
62
|
-
else
|
63
|
-
raise ArgumentError, "Unsupported protocol: #{protocol}"
|
64
|
-
end
|
65
|
-
[sock, port]
|
66
|
-
end
|
67
|
-
|
68
|
-
def zmq_context
|
69
|
-
zmq.Context.instance
|
70
|
-
end
|
71
|
-
|
72
|
-
def zmq
|
73
|
-
self.class.zmq
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|