Cross Reference: files.rb
xref
: /
ontohub
/
lib
/
git_repository
/
files.rb
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
files.rb revision 73ec6b43b29b5c85f21c9aea6645eed485e0a0e2
38
N/A
module
GitRepository
::
Files
38
N/A
# depends on GitRepository
38
N/A
extend
ActiveSupport
::
Concern
38
N/A
38
N/A
class
GitFile
38
N/A
attr_reader
:
path
, :
oid
, :
mime_type
, :
mime_category
38
N/A
38
N/A
def
initialize
(
repository
,
rugged_commit
,
path
)
38
N/A
@
path
=
path
38
N/A
self.repository
=
repository
38
N/A
if
repository.empty
?
38
N/A
@
path
=
'/'
38
N/A
@
content
= []
38
N/A
@
rugged_commit
=
nil
38
N/A
@
rugged_object
=
nil
38
N/A
return
38
N/A
end
38
N/A
if
!
repository.path
_exists
?
(
path
,
rugged_commit.oid
)
38
N/A
raise
GitRepository
::
PathNotFoundError
,
"Path doesn't exist: #{path}"
38
N/A
end
38
N/A
self.rugged
_object
=
repository.get
_object
(
rugged_commit
,
path
)
38
N/A
38
N/A
@
oid
=
rugged_commit.oid
38
N/A
38
N/A
if
file
?
38
N/A
mime_info
=
repository.class.mime
_info
(
name
)
38
N/A
@
mime_type
=
mime_info
[:
mime_type
]
38
N/A
@
mime_category
=
mime_info
[:
mime_category
]
38
N/A
end
42
N/A
end
49
N/A
38
N/A
def
size
38
N/A
case
type
38
N/A
when
:
file
38
N/A
rugged_object.size
38
N/A
when
:
dir
38
N/A
content.size
38
N/A
end
38
N/A
end
38
N/A
42
N/A
def
content
42
N/A
@
content
||=
case
type
42
N/A
when
:
file
42
N/A
rugged_object.content
42
N/A
when
:
dir
42
N/A
repository.folder
_contents
(
oid
,
path
)
38
N/A
end
42
N/A
end
42
N/A
42
N/A
def
file
?
42
N/A
type
== :
file
42
N/A
end
42
N/A
49
N/A
def
dir
?
49
N/A
type
== :
dir
42
N/A
end
42
N/A
42
N/A
def
type
42
N/A
return
:
dir
if
rugged_object.nil
?
42
N/A
case
rugged_object.type
42
N/A
when
:
blob
42
N/A
:
file
40
N/A
when
:
tree
40
N/A
:
dir
49
N/A
end
49
N/A
end
49
N/A
49
N/A
def
name
49
N/A
@
name
||=
path.split
(
'/'
)
[-
1
]
49
N/A
end
49
N/A
49
N/A
def
last_change
49
N/A
@
last_change
||=
repository.entry
_info
(
path
,
oid
)
49
N/A
end
49
N/A
49
N/A
def
==
(
other
)
49
N/A
[:
repository
, :
path
, :
oid
].
all
?
do
|
attr
|
49
N/A
self.send
(
attr
)
==
other.send
(
attr
)
49
N/A
end
49
N/A
end
49
N/A
49
N/A
protected
49
N/A
attr_accessor
:
repository
, :
rugged_object
49
N/A
end
38
N/A
end
38
N/A