Cross Reference:
xref
: /
ontohub
/
app
/
models
/
upload_file.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
upload_file.rb revision cffc92f13f7dabf3958b39ace4edec5b41001b78
class
UploadFile
class
PathValidator
<
ActiveModel
::
Validator
def
validate
(
record
)
if
record.repository.is
_below_file
?
(
record.filepath
)
record.errors
[:
path
] =
"Error! This path points to a file."
end
end
end
include
ActiveModel
::
Conversion
include
ActiveModel
::
Validations
extend
ActiveModel
::
Naming
attr_accessor
:
path
, :
message
, :
file
, :
repository
validates
:
message
, :
file
,
presence
:
true
validates_with
PathValidator
, :
if
=> :
file_exists
?
def
initialize
(
attributes
=
nil
)
attributes
||= {}
attributes.each
do
|
name
,
value
|
send
(
"#{name}="
,
value
)
end
end
def
persisted
?
false
end
def
filename
file.original
_filename
end
def
filepath
str
=
path
str
=
str
[
1
,-
1
]
if
path.starts
_with
?
(
"/"
)
str
=
str
[
0
,-
2
]
if
path.ends
_with
?
(
"/"
)
str
+=
"/"
unless
path.empty
?
str
+=
filename
end
def
file_exists
?
file.present
?
end
end