Cross Reference: importing.rb
xref
: /
ontohub
/
app
/
models
/
repository
/
importing.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
importing.rb revision a9a0428a54199be3b810a0871c947383c2f916d3
1516
N/A
module
Repository
::
Importing
1452
N/A
extend
ActiveSupport
::
Concern
1452
N/A
1452
N/A
SOURCE_TYPES
= %w
(
git
svn
)
1452
N/A
STATES
= %w
(
pending
processing
done
failed
)
1452
N/A
1452
N/A
included
do
1452
N/A
include
StateUpdater
1452
N/A
1452
N/A
@
queue
=
'import'
1452
N/A
1452
N/A
validates_inclusion_of
:
state
,
in
:
STATES
1452
N/A
validates_inclusion_of
:
source_type
,
in
:
SOURCE_TYPES
,
if
: :
remote
?
1452
N/A
1452
N/A
after_create
:
async_clone
,
if
: :
remote
?
1452
N/A
end
1452
N/A
1452
N/A
def
remote
?
1452
N/A
source_address
?
1452
N/A
end
1452
N/A
1452
N/A
# do not allow new actions if running
1452
N/A
def
locked
?
1452
N/A
%w
(
pending
processing
)
.
include
?
(
state
)
1452
N/A
end
1452
N/A
1452
N/A
# enqueues a clone job
1452
N/A
def
async_clone
1452
N/A
async_remote
:
clone
1452
N/A
end
1452
N/A
1452
N/A
# enqueues a synchronize job
1452
N/A
def
async_synchronize
1452
N/A
async_remote
:
synchronize
1452
N/A
end
1452
N/A
1452
N/A
# enqueues a remote job
1452
N/A
def
async_remote
(
method
)
1452
N/A
raise
"object is #{state}"
if
locked
?
1452
N/A
update_state
!
'pending'
1452
N/A
async
:
remote_send
,
method
1452
N/A
end
1452
N/A
1452
N/A
def
remote_send
(
method
)
1452
N/A
update_state
!
'processing'
1452
N/A
do_or_set_failed
do
1452
N/A
remote_repository.send
method
1452
N/A
update_state
!
'done'
1452
N/A
end
1452
N/A
end
1452
N/A
1452
N/A
def
remote_repository
1452
N/A
RemoteRepository.instance
(
self
,
user
)
1452
N/A
end
1452
N/A
1452
N/A
module
ClassMethods
1452
N/A
# creates a new repository and imports the contents from the remote repository
1452
N/A
def
import_remote
(
type
,
user
,
source
,
name
,
params
={})
1452
N/A
raise
ArgumentError
,
"invalid source type: #{type}"
unless
SOURCE_TYPES.include
?
(
type
)
1452
N/A
raise
Repository
::
ImportError
,
"#{source} is not a #{type} repository"
unless
GitRepository.send
"is_#{type}_repository?"
,
source
1452
N/A
1452
N/A
params
[:
name
] =
name
1452
N/A
params
[:
source_type
] =
type
1452
N/A
params
[:
source_address
] =
source
1452
N/A
1452
N/A
r =
Repository.create
!
(
params
)
1452
N/A
r.user
=
user
1452
N/A
r.save
!
1452
N/A
r
1452
N/A
1452
N/A
end
1452
N/A
end
1452
N/A
1452
N/A
end