Class: Lfs::FileTransformer
- Inherits:
-
Object
- Object
- Lfs::FileTransformer
- Defined in:
- app/services/lfs/file_transformer.rb
Overview
Usage: Calling ‘new_file` check to see if a file should be in LFS and
return a transformed result with `content` and `encoding` to commit.
The `repository` passed to the initializer can be a Repository or
class that inherits from Repository.
The `repository_type` property will be one of the types named in
`Gitlab::GlRepository.types`, and is recorded on the `LfsObjectsProject`
in order to identify the repository location of the blob.
For LFS an LfsObject linked to the project is stored and an LFS
pointer returned. If the file isn't in LFS the untransformed content
is returned to save in the commit.
transformer = Lfs::FileTransformer.new(project, repository, @branch_name) content_or_lfs_pointer = transformer.new_file(file_path, content).content create_transformed_commit(content_or_lfs_pointer)
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#branch_name ⇒ Object
readonly
Returns the value of attribute branch_name.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
-
#repository_type ⇒ Object
readonly
Returns the value of attribute repository_type.
Instance Method Summary collapse
-
#initialize(project, repository, branch_name) ⇒ FileTransformer
constructor
A new instance of FileTransformer.
- #new_file(file_path, file_content, encoding: nil, detect_content_type: false) ⇒ Object
Constructor Details
#initialize(project, repository, branch_name) ⇒ FileTransformer
Returns a new instance of FileTransformer.
25 26 27 28 29 30 |
# File 'app/services/lfs/file_transformer.rb', line 25 def initialize(project, repository, branch_name) @project = project @repository = repository @repository_type = repository.repo_type.name @branch_name = branch_name end |
Instance Attribute Details
#branch_name ⇒ Object (readonly)
Returns the value of attribute branch_name.
23 24 25 |
# File 'app/services/lfs/file_transformer.rb', line 23 def branch_name @branch_name end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
23 24 25 |
# File 'app/services/lfs/file_transformer.rb', line 23 def project @project end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
23 24 25 |
# File 'app/services/lfs/file_transformer.rb', line 23 def repository @repository end |
#repository_type ⇒ Object (readonly)
Returns the value of attribute repository_type.
23 24 25 |
# File 'app/services/lfs/file_transformer.rb', line 23 def repository_type @repository_type end |
Instance Method Details
#new_file(file_path, file_content, encoding: nil, detect_content_type: false) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/services/lfs/file_transformer.rb', line 32 def new_file(file_path, file_content, encoding: nil, detect_content_type: false) if project.lfs_enabled? && lfs_file?(file_path) file_content = parse_file_content(file_content, encoding: encoding) lfs_pointer_file = Gitlab::Git::LfsPointerFile.new(file_content) lfs_object = create_lfs_object!(lfs_pointer_file, file_content, detect_content_type) link_lfs_object!(lfs_object) Result.new(content: lfs_pointer_file.pointer, encoding: 'text') else Result.new(content: file_content, encoding: encoding) end end |