Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
move rescue into annotation/namespace definitions
Browse files Browse the repository at this point in the history
refs #100
  • Loading branch information
Anthony Bargnesi committed Feb 10, 2016
1 parent b03f6a7 commit 14c8ca2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 39 deletions.
18 changes: 17 additions & 1 deletion lib/bel/annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,23 @@ def to_bel
private

def reload(url)
@values = BEL::read_resource(url)
begin
@values = BEL::read_resource(url)
rescue OpenURI::HTTPError, SocketError, Errno::ENOENT, Errno::EACCES => err
# warn: indicate what the URL was that triggered the error
warn <<-MSG.gsub(/^\s{12}/, '')
=====================================================================
Could not retrieve annotation.
Annotation:
#{url}
Error:
#{err}
=====================================================================
MSG

# re-raise the network error
raise err
end
end
end

Expand Down
18 changes: 17 additions & 1 deletion lib/bel/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,23 @@ def to_bel
private

def reload(url)
@values = BEL::read_resource(url)
begin
@values = BEL::read_resource(url)
rescue OpenURI::HTTPError, SocketError, Errno::ENOENT, Errno::EACCES => err
# warn: indicate what the URL was that triggered the error
warn <<-MSG.gsub(/^\s{12}/, '')
=====================================================================
Could not retrieve namespace.
Namespace:
#{url}
Error:
#{err}
=====================================================================
MSG

# re-raise the network error
raise err
end
end
end

Expand Down
58 changes: 21 additions & 37 deletions lib/bel/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,28 @@ module BEL
# (e.g. lung disease|O) and a database value identifier for a BEL annotation
# file (e.g. lung|UBERON_0002048).
def self.read_resource(url)
begin
resource_lines = BEL::read_lines(url)

# Drop until the delimiter line and extract the delimiter, e.g.
# DelimiterString=|
delimiter_line = resource_lines.take(100).find { |l| l.start_with?("DelimiterString") }
delimiter =
if delimiter_line
delimiter_line.strip.split('=')[1]
else
DEFAULT_RESOURCE_VALUE_DELIMITER
end
resource_lines = BEL::read_lines(url)

# Drop until the delimiter line and extract the delimiter, e.g.
# DelimiterString=|
delimiter_line = resource_lines.take(100).find { |l| l.start_with?("DelimiterString") }
delimiter =
if delimiter_line
delimiter_line.strip.split('=')[1]
else
DEFAULT_RESOURCE_VALUE_DELIMITER
end

# Extract namespace values based on the delimiter.
Hash[
resource_lines.
drop_while { |l| !l.start_with?("[Values]") }.
drop(1).
map { |s|
val_enc = s.strip!.split(delimiter).map(&:to_sym)
val_enc[0..1]
}
]
rescue OpenURI::HTTPError, SocketError, Errno::ENOENT, Errno::EACCES => err
# warn: indicate what the URL was that triggered the error
warn <<-MSG.gsub(/^\s{12}/, '')
=====================================================================
Could not retrieve namespace.
Namespace:
#{url}
Error:
#{err}
=====================================================================
MSG

# re-raise the network error
raise err
end
# Extract namespace values based on the delimiter.
Hash[
resource_lines.
drop_while { |l| !l.start_with?("[Values]") }.
drop(1).
map { |s|
val_enc = s.strip!.split(delimiter).map(&:to_sym)
val_enc[0..1]
}
]
end

def self.read_all(reference, options = {})
Expand Down

0 comments on commit 14c8ca2

Please sign in to comment.