Cross Reference: parsing.rb
xref
: /
ontohub
/
app
/
models
/
ontology_version
/
parsing.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
parsing.rb revision 9c9b4f0d0199c3b1dbff564b87435b6693b7e692
module
OntologyVersion
::
Parsing
extend
ActiveSupport
::
Concern
included
do
@
queue
= :
hets
after_create
:
parse_async
end
def
parse
raise
ArgumentError.new
(
'No raw_file set.'
)
unless
raw_file
?
do_or_set_failed
do
@
path
=
Hets.parse
(
self.raw_file.current
_path
)
end
self.xml
_file
=
File.open
(@
path
)
save
!
do_or_set_failed
do
self.ontology.import
_latest_version
end
File.delete
(@
path
)
update_state
! :
done
end
def
parse_async
async
:
parse
end
protected
def
do_or_set_failed
(&
block
)
raise
ArgumentError.new
(
'No block given.'
)
unless
block_given
?
begin
yield
rescue
Exception
=> e
update_state
! :
failed
,
e.message
raise
e
end
end
def
update_state
!
(
state
,
error_message
=
nil
)
ontology.state
=
state.to
_s
ontology.save
!
self.last
_error
=
error_message
save
!
end
end