Class: GitXplorer::GitObject::File

Inherits:
GitXplorer::GitObject show all
Defined in:
lib/git_xplorer/git_object/file.rb

Instance Attribute Summary

Attributes inherited from GitXplorer::GitObject

#name, #parent

Instance Method Summary collapse

Methods inherited from GitXplorer::GitObject

#absolute_path, #exist?, #get, #get_completions, #has_child?, #tab_complete, #to_s

Constructor Details

#initialize(name, parent) ⇒ File

Returns a new instance of File.



41
42
43
# File 'lib/git_xplorer/git_object/file.rb', line 41

def initialize(name, parent)
    super(name, parent)
end

Instance Method Details

#childrenObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/git_xplorer/git_object/file.rb', line 2

def children
    if (@kids.nil?)
        # Initialize
        @kids = Array.new

        # Create git command
        cmd = [
            "git log --date=format-local:\"%F_%I:%M:%S_%P\"",
            "--diff-filter=AC",
            "--full-history",
            "--pretty=tformat:\"{{%H}}{{%s}}{{%cd}}{{%an}}\"",
            "--",
            absolute_path
        ].join(" ")

        # Loop thru results creating a revision object for each
        %x(#{cmd}).split("\n").each do |line|
            line.match(/{{(.+)}}{{(.+)}}{{(.+)}}{{(.+)}}/) do |m|
                @kids.push(
                    GitXplorer::GitObject::Revision.new(
                        m[1],
                        self,
                        m[2],
                        m[3],
                        m[4]
                    )
                )
            end
        end
    end

    return @kids
end

#descObject



36
37
38
39
# File 'lib/git_xplorer/git_object/file.rb', line 36

def desc
    return "#{newest.name} #{newest.date}" if (newest)
    return nil
end

#newestObject



45
46
47
# File 'lib/git_xplorer/git_object/file.rb', line 45

def newest
    return children[0]
end