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