Class: Bringit::Index
- Inherits:
-
Object
- Object
- Bringit::Index
- Defined in:
- lib/bringit/index.rb
Constant Summary collapse
- DEFAULT_MODE =
0o100644
Instance Attribute Summary collapse
-
#raw_index ⇒ Object
readonly
Returns the value of attribute raw_index.
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
- #create(options) ⇒ Object
- #create_dir(options) ⇒ Object
- #delete(options) ⇒ Object
- #dir_exists?(path) ⇒ Boolean
-
#initialize(repository) ⇒ Index
constructor
A new instance of Index.
- #move(options) ⇒ Object
- #update(options) ⇒ Object
- #write_tree ⇒ Object
Constructor Details
#initialize(repository) ⇒ Index
Returns a new instance of Index.
7 8 9 10 |
# File 'lib/bringit/index.rb', line 7 def initialize(repository) @repository = repository @raw_index = repository.rugged.index end |
Instance Attribute Details
#raw_index ⇒ Object (readonly)
Returns the value of attribute raw_index.
5 6 7 |
# File 'lib/bringit/index.rb', line 5 def raw_index @raw_index end |
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
5 6 7 |
# File 'lib/bringit/index.rb', line 5 def repository @repository end |
Instance Method Details
#create(options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bringit/index.rb', line 22 def create() = () file_entry = get([:file_path]) if file_entry raise Bringit::Repository::InvalidBlobName.new("Filename already exists") end add_blob() end |
#create_dir(options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bringit/index.rb', line 33 def create_dir() = () file_entry = get([:file_path]) if file_entry raise Bringit::Repository::InvalidBlobName.new("Directory already exists as a file") end if dir_exists?([:file_path]) raise Bringit::Repository::InvalidBlobName.new("Directory already exists") end = .dup [:file_path] += '/.gitkeep' [:content] = '' add_blob() end |
#delete(options) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bringit/index.rb', line 80 def delete() = () file_entry = get([:file_path]) unless file_entry raise Bringit::Repository::InvalidBlobName.new("File doesn't exist") end raw_index.remove([:file_path]) end |
#dir_exists?(path) ⇒ Boolean
18 19 20 |
# File 'lib/bringit/index.rb', line 18 def dir_exists?(path) raw_index.find { |entry| entry[:path].start_with?("#{path}/") } end |
#move(options) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/bringit/index.rb', line 63 def move() = () file_entry = get([:previous_path]) unless file_entry raise Bringit::Repository::InvalidBlobName.new("File doesn't exist") end if get([:file_path]) raise IndexError, "A file with this name already exists" end raw_index.remove([:previous_path]) add_blob(, mode: file_entry[:mode]) end |
#update(options) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bringit/index.rb', line 52 def update() = () file_entry = get([:file_path]) unless file_entry raise Bringit::Repository::InvalidBlobName.new("File doesn't exist") end add_blob(, mode: file_entry[:mode]) end |
#write_tree ⇒ Object
14 15 16 |
# File 'lib/bringit/index.rb', line 14 def write_tree raw_index.write_tree(repository.rugged) end |