Class: GitObjectBrowser::Models::GitObject
- Defined in:
- lib/git-object-browser/models/git_object.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#sha1 ⇒ Object
readonly
Returns the value of attribute sha1.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input) ⇒ GitObject
constructor
A new instance of GitObject.
- #parse ⇒ Object
- #parse_inflated(content) ⇒ Object
- #to_hash ⇒ Object
Methods inherited from Bindata
#binstr, #byte, #bytes, #find_char, #hex, #int, #peek, #raw, #seek, #skip, #switch_source
Constructor Details
#initialize(input) ⇒ GitObject
Returns a new instance of GitObject.
11 12 13 |
# File 'lib/git-object-browser/models/git_object.rb', line 11 def initialize(input) super(input) end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
8 9 10 |
# File 'lib/git-object-browser/models/git_object.rb', line 8 def contents @contents end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
8 9 10 |
# File 'lib/git-object-browser/models/git_object.rb', line 8 def entries @entries end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
9 10 11 |
# File 'lib/git-object-browser/models/git_object.rb', line 9 def end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
9 10 11 |
# File 'lib/git-object-browser/models/git_object.rb', line 9 def properties @properties end |
#sha1 ⇒ Object (readonly)
Returns the value of attribute sha1.
8 9 10 |
# File 'lib/git-object-browser/models/git_object.rb', line 8 def sha1 @sha1 end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
8 9 10 |
# File 'lib/git-object-browser/models/git_object.rb', line 8 def size @size end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/git-object-browser/models/git_object.rb', line 8 def type @type end |
Class Method Details
.path?(relpath) ⇒ Boolean
58 59 60 |
# File 'lib/git-object-browser/models/git_object.rb', line 58 def self.path?(relpath) relpath =~ %r{\Aobjects/[0-9a-f]{2}/[0-9a-f]{38}\z} end |
Instance Method Details
#parse ⇒ Object
15 16 17 18 19 |
# File 'lib/git-object-browser/models/git_object.rb', line 15 def parse content = Zlib::Inflate.inflate(@in.read(nil)) parse_inflated(content) self end |
#parse_inflated(content) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/git-object-browser/models/git_object.rb', line 21 def parse_inflated(content) @sha1 = Digest::SHA1.hexdigest(content) @in = StringIO.new(content) @type = find_char ' ' @size = find_char "\0" @type = type @size = size if @type == 'tree' @entries = parse_tree_entries else @content = @in.read(nil) if @type == 'commit' or @type == 'tag' (@properties, ) = parse_contents end @content = force_utf8(@content) @content = @content[0, 3000] + "\n..." if @content.length > 3000 end self end |
#to_hash ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/git-object-browser/models/git_object.rb', line 46 def to_hash return { :type => @type, :sha1 => @sha1, :size => @size, :entries => @entries, :content => @content, :properties => @properties, :message => } end |