Class: Raykit::Project

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProject

Returns a new instance of Project.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/raykit/project.rb', line 11

def initialize()
    
    @directory=RAKE_DIRECTORY
    

    git_directory=Raykit::Git::Directory.new(@directory)
    @remote=git_directory.remote

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#commitObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/raykit/project.rb', line 46

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

#directoryObject



27
28
29
# File 'lib/raykit/project.rb', line 27

def directory
    @directory
end

#infoObject



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

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
end

#pullObject



74
75
76
77
78
79
# File 'lib/raykit/project.rb', line 74

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

#pushObject



63
64
65
66
67
68
69
70
71
72
# File 'lib/raykit/project.rb', line 63

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

#remoteObject



35
36
37
# File 'lib/raykit/project.rb', line 35

def remote
    @remote
end

#run(command, quit_on_failure = true) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/raykit/project.rb', line 94

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

#tagObject



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/raykit/project.rb', line 81

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")
        end
    end
    self
end

#versionObject



31
32
33
# File 'lib/raykit/project.rb', line 31

def version
    @version
end