Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publish version 0.1.0 #17

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ gem "rubocop", "~> 1.21"

gem "async", "~> 2.9"

gem "wampproto", "~> 0.1.1", require: true

gem "debug", "~> 1.9", groups: %i[development test]
37 changes: 29 additions & 8 deletions bin/xconn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require "wamp"

require "optparse"

options = { host: "127.0.0.1", port: 8080, realm: "realm1", directory: "." }
options = { host: "127.0.0.1", port: 8080, realm: "realm1", directory: ".", app: "App" }
OptionParser.new do |opts|
opts.banner = "Usage: xconn [options]"

Expand All @@ -22,15 +22,24 @@ OptionParser.new do |opts|
options[:port] = port
end

opts.on("-dDIRECTORY", "--directory Directory", 'Directory (default: ".")') do |directory|
opts.on("-dDIRECTORY", "--directory DIRECTORY", 'Directory (default: ".")') do |directory|
options[:directory] = directory
end

opts.on("-aAPP", "--app App", 'App (default: "App")') do |app|
opts.on("-aAPP", "--app APP", 'App (default: "App")') do |app|
options[:app] = app
end

opts.on("-v", "--version", "Gem Version") do |version|
options[:version] = version
end
end.parse!

if options.include?(:version)
puts "Xconn v#{Wamp::VERSION}"
exit 0
end

def create_client_session(router)
session = Wamp::Connection::Session.new

Expand All @@ -46,12 +55,24 @@ router = Wamp::Router::Base.new
router.add_realm(options.fetch(:realm))

client = create_client_session(router).tap(&:on_open)
Pathname.new(options[:directory]).glob("**/*.rb").each { |file| require file.to_s }
app = Object.const_get(options[:app])
app.new.procedures.each do |procedure, func|
client.api.register(procedure, func) do
puts "Registered procedure: #{procedure}"

begin
Pathname.new(options[:directory]).glob("**/*.rb").each { |file| require file.to_s }
rescue LoadError => e
puts e.message
exit 1
end

begin
app = Object.const_get(options[:app])
app.new.procedures.each do |procedure, func|
client.api.register(procedure, func) do
puts "Registered procedure: #{procedure}"
end
end
rescue StandardError => e
puts e.message
exit 1
end

server = Wamp::Router::Server.new(router, options)
Expand Down
3 changes: 2 additions & 1 deletion wamp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require_relative "lib/wamp/version"

Gem::Specification.new do |spec|
spec.name = "wamp"
spec.name = "xconn"
spec.version = Wamp::VERSION
spec.authors = ["Ismail Akram"]
spec.email = ["[email protected]"]
Expand Down Expand Up @@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "ed25519", "~> 1.3"
spec.add_dependency "msgpack", "~> 1.7.2"
spec.add_dependency "nio4r", "~> 2.7"
spec.add_dependency "wampproto", "~> 0.1.1"
spec.add_dependency "websocket-driver", "~> 0.7"
spec.metadata["rubygems_mfa_required"] = "true"
end