Cross Reference: combination.rb
xref
: /
ontohub
/
app
/
fake_records
/
combination.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
combination.rb revision e17f3b48ced85fb8b25c7ca5b76cf093d089e264
294
N/A
class
Combination
<
FakeRecord
294
N/A
DEFAULT_NAME
=
'
combinations.dol
'
787
N/A
789
N/A
attr_reader
:
nodes
789
N/A
attr_reader
:
target_repository
, :
error
789
N/A
1336
N/A
def
initialize
(
target_repository
,
combination_hash
)
789
N/A
@
target_repository
=
target_repository
789
N/A
from_combination_hash
(
combination_hash
)
873
N/A
end
789
N/A
877
N/A
def
save
!
789
N/A
ontology
294
N/A
rescue
StandardError
=>
error
873
N/A
@
error
=
error
873
N/A
raise
RecordNotSavedError
,
"Couldn't create combination!"
789
N/A
end
789
N/A
789
N/A
def
file_name
873
N/A
@
file_name
||=
DEFAULT_NAME
789
N/A
end
789
N/A
789
N/A
def
commit_message
789
N/A
@
commit_message
||=
commit_message_erb.result
(
binding
)
789
N/A
end
789
N/A
789
N/A
def
combination_name
789
N/A
"combination"
789
N/A
end
1336
N/A
1336
N/A
def
ontology
789
N/A
@
ontology
||=
create_ontology
!
873
N/A
end
1336
N/A
1336
N/A
private
1336
N/A
def
from_combination_hash
(
hash
)
1336
N/A
@
nodes
=
hash.fetch
(:
nodes
, [])
1336
N/A
@
file_name
=
hash
[:
file_name
]
1336
N/A
@
commit_message
=
hash
[:
commit_message
]
1336
N/A
end
1336
N/A
1336
N/A
def
create_ontology
!
1336
N/A
repository_file
=
build_repository_file
1336
N/A
repository_file.save
!
1336
N/A
target_repository.ontologies
.
1336
N/A
with_path
(
repository_file.target
_path
)
.
1336
N/A
without_parent.first
1336
N/A
end
1336
N/A
1336
N/A
def
build_repository_file
1336
N/A
target_directory
=
File.dirname
(
file_name
)
873
N/A
target_directory
=
nil
if
target_directory
==
'.'
873
N/A
target_filename
=
File.basename
(
file_name
)
873
N/A
file
=
RepositoryFile.new
\
789
N/A
temp_file
:
dol_tempfile
,
787
N/A
target_directory
:
target_directory
,
294
N/A
target_filename
:
target_filename
,
1336
N/A
repository_id
:
target_repository.path
,
1336
N/A
repository_file
: {
repository_id
:
target_repository.path
},
1336
N/A
user
:
User.first
,
1336
N/A
message
:
commit_message
1337
N/A
end
294
N/A
294
N/A
def
named_nodes
294
N/A
nodes.map
do
|
node
|
1336
N/A
[
node.split
(
'/'
)
.last.split
(
'?'
)
.
first
,
node
]
1336
N/A
end
1337
N/A
end
1337
N/A
1337
N/A
def
dol_tempfile
1337
N/A
file
=
Tempfile.new
(
file_name
)
1337
N/A
file.write
(
dol_representation_erb.result
(
binding
)
)
1337
N/A
file.rewind
1337
N/A
file
1337
N/A
end
1337
N/A
1336
N/A
def
dol_representation_erb
1337
N/A
template_file
=
Rails.root.join
(
'
lib
/
combinations
/
dol.erb
'
)
1337
N/A
ERB.new
(
template_file.read
,
nil
,
'<>'
)
1337
N/A
end
294
N/A
294
N/A
def
commit_message_erb
294
N/A
template_file
=
Rails.root.join
(
'
lib
/
combinations
/
commit_message.erb
'
)
294
N/A
ERB.new
(
template_file.read
,
nil
,
'>'
)
789
N/A
end
294
N/A
end
1109
N/A