Class: Raykit::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/raykit/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Project

Returns a new instance of Project.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/raykit/project.rb', line 11

def initialize()
    @remote=''
    if(Dir.exist?(RAKE_DIRECTORY))
        @directory=RAKE_DIRECTORY
        if(Dir.exist?("#{RAKE_DIRECTORY}/.git") && Dir.exist?(@directory))
            git_directory=Raykit::Git::Directory.new(@directory)
            @remote=git_directory.remote
        end
    else
        @directory=''
        #@remote=''
    end

    

    if(defined?(NAME))
        @name=NAME 
    else
        remote_parts = @remote.split('/')
        if(remote_parts.length > 0)
            @name=remote_parts[-1].gsub('.git','')
        end
    end
    @version=Raykit::Version.detect(@name)
end

Instance Attribute Details

#name ⇒ Object

Returns the value of attribute name.



6
7
8
# File 'lib/raykit/project.rb', line 6

def name
  @name
end

Instance Method Details

#commit ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/raykit/project.rb', line 71

def commit
    Dir.chdir(@directory) do
        if(File.exist?('.gitignore'))
            status=`git status`
            if(status.include?('Changes not staged for commit:'))
                run("git add --all")
                if(GIT_DIRECTORY.outstanding_commit?)
                    run("git commit -m'update'")
                end  
            end
        else
            puts "warning: .gitignore not found."
        end
    end
    self
end

#directory ⇒ Object



37
38
39
# File 'lib/raykit/project.rb', line 37

def directory
    @directory
end

#elapsed ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/raykit/project.rb', line 49

def elapsed
    elapsed=TIMER.elapsed
    if(elapsed < 1.0)
        "%.1f" % (TIMER.elapsed) + "s"
    else
        "%.0f" % (TIMER.elapsed) + "s"
    end
end

#info ⇒ Object



58
59
60
61
62
63
64
# File 'lib/raykit/project.rb', line 58

def info
    puts ''
    puts "PROJECT.name = " + Rainbow(PROJECT.name).yellow.bright
    puts "PROJECT.version = " + Rainbow(PROJECT.version).yellow.bright
    puts "PROJECT.remote = " + Rainbow(PROJECT.remote).yellow.bright
    puts "PROJECT.elapsed = " + Rainbow(PROJECT.elapsed).yellow.bright
end

#pull ⇒ Object



99
100
101
102
103
104
# File 'lib/raykit/project.rb', line 99

def pull
    Dir.chdir(@directory) do
        run('git pull')
    end
    self
end

#push ⇒ Object



88
89
90
91
92
93
94
95
96
97
# File 'lib/raykit/project.rb', line 88

def push
    Dir.chdir(@directory) do
        status=`git status`
        if(status.include?('use "git push"'))
            run('git push')
            run('git push --tags')
        end
    end
    self
end

#remote ⇒ Object



45
46
47
# File 'lib/raykit/project.rb', line 45

def remote
    @remote
end

#run(command, quit_on_failure = true) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/raykit/project.rb', line 120

def run(command,quit_on_failure=true) 
    if(command.kind_of?(Array))
        command.each{|subcommand| run(subcommand,quit_on_failure)}
    else
        cmd = Command.new(command)
        elapsed_str = Timer.get_elapsed_str(cmd.elapsed,0)
        if(cmd.exitstatus == 0)
            puts elapsed_str + " " +  Rainbow(cmd.command).yellow.bright
            return elapsed_str + " " + cmd.command
        else
            puts "\r\n" + cmd.command + "\r\n"
            system(cmd.command)
            puts ''
            if(quit_on_failure)
                abort Rainbow(elapsed_str).red.bright + " " +  Rainbow(cmd.command).white
            end
        end
    end
end

#summary ⇒ Object



66
67
68
69
# File 'lib/raykit/project.rb', line 66

def summary
    
    puts "[" + elapsed + "] " + Rainbow(@name).yellow.bright + " " + Rainbow(version).yellow.bright
end

#tag ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/raykit/project.rb', line 106

def tag
    Dir.chdir(@directory) do
        tag = `git describe --abbrev=0 --tags`.strip
        if(@version != tag)
            #run('git add --all')
            run("git tag #{@version} -m'#{@version}'")
            #run('git push')
            #run("git push --tags")
            push
        end
    end
    self
end

#version ⇒ Object



41
42
43
# File 'lib/raykit/project.rb', line 41

def version
    @version
end