Class: Gash
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Gash
- Defined in:
- lib/gash.rb
Overview
What is Gash?
-
Gash lets you access a Git-repo as a Hash.
-
Gash doesn’t touch your working directory
-
Gash only cares about the data, not the commits.
-
Gash only cares about the latest data.
-
Gash can commit.
-
Gash will automatically create branches if they don’t exists.
-
Gash only loads what it needs, so it handles large repos well.
-
Gash got pretty good documentation.
-
Gash got a bug tracker.
-
Gash is being developed at GitHub.
Some of these “rules” might change it the future.
How do you use it?
gash = Gash.new
gash["README"] = "new content"
gash.commit("Some changes...")
It’s also important to remember that a Gash is simply a Tree, so you can also call those methods.
See also: #new, #commit, Tree
Credits
This code is based upon git-shelve, and is released under the same license; LGPL.
Defined Under Namespace
Modules: Errors, Helpers Classes: Blob, Tree
Instance Attribute Summary collapse
-
#branch ⇒ Object
Returns the value of attribute branch.
-
#repository ⇒ Object
Returns the value of attribute repository.
Instance Method Summary collapse
-
#branch_exists? ⇒ Boolean
Checks if the current branch exists.
-
#changed! ⇒ Object
:nodoc:.
-
#commit(msg) ⇒ Object
Commit the current changes and returns the commit-hash.
-
#gash ⇒ Object
:nodoc:.
-
#initialize(repo = ".git", branch = "master") ⇒ Gash
constructor
Opens the
repo
with the specifiedbranch
. -
#inspect ⇒ Object
:nodoc:.
-
#update! ⇒ Object
Fetch the latest data from Git; you can use this as a
clear
-method.
Constructor Details
#initialize(repo = ".git", branch = "master") ⇒ Gash
Opens the repo
with the specified branch
.
Please note: The repo
must link to the actual repo, not the working directory!
333 334 335 336 337 338 |
# File 'lib/gash.rb', line 333 def initialize(repo = ".git", branch = "master") @branch = branch @repository = File.(repo) __setobj__(Tree.new(:parent => self)) update! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object (private)
448 449 450 451 452 453 454 |
# File 'lib/gash.rb', line 448 def method_missing(meth, *args, &blk) target = self.__getobj__ unless target.respond_to?(meth) Object.instance_method(:method_missing).bind(self).call(meth, *args, &blk) end target.__send__(meth, *args, &blk) end |
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch.
327 328 329 |
# File 'lib/gash.rb', line 327 def branch @branch end |
#repository ⇒ Object
Returns the value of attribute repository.
327 328 329 |
# File 'lib/gash.rb', line 327 def repository @repository end |
Instance Method Details
#branch_exists? ⇒ Boolean
Checks if the current branch exists
388 389 390 391 392 393 |
# File 'lib/gash.rb', line 388 def branch_exists? git('rev-parse', @branch, '2>&1') true rescue Errors::Git false end |
#changed! ⇒ Object
:nodoc:
344 345 346 |
# File 'lib/gash.rb', line 344 def changed! #:nodoc: @sha1 = nil end |
#commit(msg) ⇒ Object
Commit the current changes and returns the commit-hash.
Returns nil
if nothing has changed.
380 381 382 383 384 385 |
# File 'lib/gash.rb', line 380 def commit(msg) return unless changed? commit = commit_tree(to_tree!, msg) @sha1 = git_tree_sha1 commit end |
#gash ⇒ Object
:nodoc:
340 341 342 |
# File 'lib/gash.rb', line 340 def gash #:nodoc: self end |
#inspect ⇒ Object
:nodoc:
395 396 397 |
# File 'lib/gash.rb', line 395 def inspect #:nodoc: __getobj__.inspect end |
#update! ⇒ Object
Fetch the latest data from Git; you can use this as a clear
-method.
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/gash.rb', line 349 def update! clear self.sha1 = git_tree_sha1 git_tree do |line| line.strip! mode = line[0, 6] type = line[7] sha1 = line[12, 40] name = line[53..-1] if name[0] == ?" && name[-1] == ?" name = eval(name) end name = name[/[^\/]+$/] parent = if $`.empty? self else self[$`.chomp("/")] end parent[name, true] = case type when ?b Blob.new(:sha1 => sha1, :mode => mode) when ?t Tree.new(:sha1 => sha1, :mode => mode) end end self end |