Skip to content

Commit

Permalink
closes #55 Fix require of stream protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmelt committed Feb 12, 2015
1 parent f4070ee commit bde12fa
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 36 deletions.
4 changes: 2 additions & 2 deletions lib/cosmos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
saved_verbose = $VERBOSE; $VERBOSE = nil
begin
require 'dl'
rescue LoadError
rescue Exception
end
$VERBOSE = saved_verbose

Expand All @@ -58,6 +58,6 @@

begin
require 'user_version'
rescue LoadError
rescue Exception
# Not defined
end
22 changes: 1 addition & 21 deletions lib/cosmos/interfaces/stream_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,7 @@ def initialize(stream_protocol_type, *stream_protocol_args)
super()

stream_protocol_class = stream_protocol_type.to_s.capitalize << 'StreamProtocol'
klass = stream_protocol_class.to_class
unless klass
begin
require stream_protocol_class.class_name_to_filename
# If the stream protocol doesn't exist require will throw a LoadError
rescue LoadError => err
msg = "Unable to require " \
"#{stream_protocol_class.class_name_to_filename} due to #{err.message}. " \
"Ensure #{stream_protocol_class.class_name_to_filename} "\
"is in the COSMOS lib directory."
Logger.instance.error msg
raise msg
# If the stream protocol exists but has problems we rescue those here
rescue => err
msg = "Unable to require " \
"#{stream_protocol_class.class_name_to_filename} due to #{err.message}."
Logger.instance.error msg
raise msg
end
end

klass = Cosmos.require_class(stream_protocol_class.class_name_to_filename)
@stream_protocol = klass.new(*stream_protocol_args)
@stream_protocol.interface = self
end
Expand Down
12 changes: 1 addition & 11 deletions lib/cosmos/io/tcpip_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,7 @@ def initialize(write_port,
@read_timeout = @read_timeout.to_f if @read_timeout

stream_protocol_class = stream_protocol_type.to_s.capitalize << 'StreamProtocol'
@stream_protocol_class = stream_protocol_class.to_class
unless @stream_protocol_class
begin
require "cosmos/streams/#{stream_protocol_class.class_name_to_filename}"
@stream_protocol_class = stream_protocol_class.to_class
rescue LoadError => err
Logger.instance.error "Unable to require #{stream_protocol_class.class_name_to_filename} due to #{err.message}. Ensure #{stream_protocol_class.class_name_to_filename} is in the COSMOS lib directory."
raise "Unable to require #{stream_protocol_class.class_name_to_filename} due to #{err.message}. Ensure #{stream_protocol_class.class_name_to_filename} is in the COSMOS lib directory."
end
end

@stream_protocol_class = Cosmos.require_class(stream_protocol_class.class_name_to_filename)
@stream_protocol_args = stream_protocol_args

@listen_sockets = []
Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/system/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def process_file(filename)
parser.verify_num_parameters(1, 1, usage)
begin
require parameters[0]
rescue LoadError => err
rescue Exception => err
msg = "Unable to require #{parameters[0]} due to #{err.message}. " +
"Ensure #{parameters[0]} is in the COSMOS lib directory."
Logger.instance.error msg
Expand Down
2 changes: 1 addition & 1 deletion lib/cosmos/top_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ def self.require_class(class_filename)
return class_name.to_class if class_name.to_class and defined? class_name.to_class
begin
require class_filename
rescue LoadError => err
rescue Exception => err
msg = "Unable to require #{class_filename} due to #{err.message}. Ensure #{class_filename} is in the COSMOS lib directory."
Logger.error msg
raise msg
Expand Down

0 comments on commit bde12fa

Please sign in to comment.