diff options
author | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-08 17:07:04 -0800 |
---|---|---|
committer | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-08 17:07:04 -0800 |
commit | 1f63953f05a4afe74f881d54f69f77da513939d5 (patch) | |
tree | 5fabd81a82d8aa3df0e9cdc10b0ed7f6ff141b8a /lib/git/object.rb | |
parent | b18bca3b853dee6a7bc86f09921aa3b1ee3f3d7b (diff) | |
download | third_party-ruby-git-1f63953f05a4afe74f881d54f69f77da513939d5.tar.gz third_party-ruby-git-1f63953f05a4afe74f881d54f69f77da513939d5.tar.xz third_party-ruby-git-1f63953f05a4afe74f881d54f69f77da513939d5.zip |
moved the git objects into the object.rb file
Diffstat (limited to 'lib/git/object.rb')
-rw-r--r-- | lib/git/object.rb | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/lib/git/object.rb b/lib/git/object.rb index 0252fdb..9346b87 100644 --- a/lib/git/object.rb +++ b/lib/git/object.rb @@ -1,16 +1,68 @@ module Git class Object - attr_accessor :sha, :type - def initialize(sha) - @sha = sha - end + class AbstractObject + attr_accessor :sha, :size, :type + + @base = nil + + def initialize(base, sha) + @base = base + @sha = sha + @size = @base.lib.object_size(@sha) + setup + end - def cat_file + def contents + @base.lib.object_contents(@sha) + end + + def contents_array + self.contents.split("\n") + end + + def setup + raise NotImplementedError + end + end + - def raw + class Blob < AbstractObject + def setup + @type = 'blob' + end + end + + class Tree < AbstractObject + def setup + @type = 'tree' + end + end + + class Commit < AbstractObject + def setup + @type = 'commit' + end end + + + class << self + # if we're calling this, we don't know what type it is yet + # so this is our little factory method + def new(base, objectish) + sha = base.lib.revparse(objectish) + type = base.lib.object_type(sha) + + klass = + case type + when /blob/: Blob + when /commit/: Commit + when /tree/: Tree + end + klass::new(base, sha) + end + end end end
\ No newline at end of file |