module Gash::Helpers
Attributes
mode[RW]
parent[RW]
sha1[RW]
Public Class Methods
new(opts = {})
click to toggle source
Sets the accessors using a Hash:
tree = Gash::Tree.new(:sha1 => "some thing", :mode => "some thing", :parent => "some parent") tree.sha1 == "some thing" tree.mode == "some thing" tree.parent == "some parent"
# File lib/gash.rb, line 71 def initialize(opts = {}) opts.each do |key, value| send("#{key}=", value) end end
Public Instance Methods
blob?()
click to toggle source
Checks if this is a Blob
.
# File lib/gash.rb, line 78 def blob?; self.class == Gash::Blob end
changed!()
click to toggle source
Mark this, and all parents as changed.
# File lib/gash.rb, line 84 def changed!; @sha1 = nil;parent.changed! if parent end
changed?()
click to toggle source
Checks if this object has been changed (since last commit).
# File lib/gash.rb, line 82 def changed?; !@sha1 end
gash()
click to toggle source
Returns the Gash-object (top-parent).
# File lib/gash.rb, line 86 def gash; parent.gash if parent end
normalize(value)
click to toggle source
Converts the value
to a Tree
or a Blob
, using some rules:
If value
is already a Tree
or a Blob:¶ ↑
-
If
value
comes from another repo, we load it and return a deep copy. -
If
value
got no parent, we simply return the same tree. -
If
value
‘s parent isself
, we also return the same tree. -
If
value
‘s parent is something else, we return a duplicated tree.
If it’s something else:¶ ↑
-
If
value
is a Hash, we create aTree
from it. -
If it’s not any of the former rules, we turn it into a string and create a
Blob
from it.
# File lib/gash.rb, line 101 def normalize(value) case value when Tree, Blob, Gash if value.parent && value.parent != self if (g = value.gash) && self.gash == g value.dup else normalize(value.tree? ? value.to_hash : value.to_s) end else value end when Hash Tree[value] else Blob.new(:content => value.to_s) end end
tree?()
click to toggle source
Checks if this is a Tree
.
# File lib/gash.rb, line 80 def tree?; self.class == Gash::Tree end