Module: Gash::Helpers
Overview
Some common methods used by both Tree and Blob.
Instance Attribute Summary collapse
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#sha1 ⇒ Object
Returns the value of attribute sha1.
Instance Method Summary collapse
-
#blob? ⇒ Boolean
Checks if this is a Blob.
-
#changed! ⇒ Object
Mark this, and all parents as changed.
-
#changed? ⇒ Boolean
Checks if this object has been changed (since last commit).
-
#gash ⇒ Object
Returns the Gash-object (top-parent).
-
#initialize(opts = {}) ⇒ Object
Sets the accessors using a Hash:.
-
#normalize(value) ⇒ Object
Converts the
value
to a Tree or a Blob, using some rules:. -
#tree? ⇒ Boolean
Checks if this is a Tree.
Instance Attribute Details
#mode ⇒ Object
Returns the value of attribute mode.
62 63 64 |
# File 'lib/gash.rb', line 62 def mode @mode end |
#parent ⇒ Object
Returns the value of attribute parent.
62 63 64 |
# File 'lib/gash.rb', line 62 def parent @parent end |
#sha1 ⇒ Object
Returns the value of attribute sha1.
62 63 64 |
# File 'lib/gash.rb', line 62 def sha1 @sha1 end |
Instance Method Details
#blob? ⇒ Boolean
Checks if this is a Blob.
78 |
# File 'lib/gash.rb', line 78 def blob?; self.class == Gash::Blob end |
#changed! ⇒ Object
Mark this, and all parents as changed.
84 |
# File 'lib/gash.rb', line 84 def changed!; @sha1 = nil;parent.changed! if parent end |
#changed? ⇒ Boolean
Checks if this object has been changed (since last commit).
82 |
# File 'lib/gash.rb', line 82 def changed?; !@sha1 end |
#gash ⇒ Object
Returns the Gash-object (top-parent).
86 |
# File 'lib/gash.rb', line 86 def gash; parent.gash if parent end |
#initialize(opts = {}) ⇒ Object
71 72 73 74 75 |
# File 'lib/gash.rb', line 71 def initialize(opts = {}) opts.each do |key, value| send("#{key}=", value) end end |
#normalize(value) ⇒ Object
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 a Tree from it. -
If it’s not any of the former rules, we turn it into a string and create a Blob from it.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# 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 |