Skip to content

Commit

Permalink
Merge pull request #17 from xconnio/publish
Browse files Browse the repository at this point in the history
publish version 0.1.0
  • Loading branch information
rubyonrails3 authored May 30, 2024
2 parents 2dca3d7 + 26ad50b commit 14e4209
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
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

0 comments on commit 14e4209

Please sign in to comment.