Class: Raykit::Project
- Inherits:
-
Object
- Object
- Raykit::Project
- Defined in:
- lib/raykit/project.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#timer ⇒ Object
Returns the value of attribute timer.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #branch ⇒ Object
- #commit ⇒ Object
- #directory ⇒ Object
- #elapsed ⇒ Object
- #get_dev_dir(subdir) ⇒ Object
- #info ⇒ Object
-
#initialize ⇒ Project
constructor
A new instance of Project.
- #last_modified_filename ⇒ Object
- #latest_commit ⇒ Object
- #pull ⇒ Object
- #push ⇒ Object
- #remote ⇒ Object
- #run(command, quit_on_failure = true) ⇒ Object
- #summary ⇒ Object
- #tag ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize ⇒ Project
Returns a new instance of Project.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/raykit/project.rb', line 15 def initialize() @verbose=false @timer=Raykit::Timer.new @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) @repository=Raykit::Git::Repository.new(@remote) 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 |
#timer ⇒ Object
Returns the value of attribute timer.
7 8 9 |
# File 'lib/raykit/project.rb', line 7 def timer @timer end |
#verbose ⇒ Object
Returns the value of attribute verbose.
8 9 10 |
# File 'lib/raykit/project.rb', line 8 def verbose @verbose end |
Instance Method Details
#branch ⇒ Object
51 52 53 |
# File 'lib/raykit/project.rb', line 51 def branch @git_directory.branch end |
#commit ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/raykit/project.rb', line 102 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
48 49 50 |
# File 'lib/raykit/project.rb', line 48 def directory @directory end |
#elapsed ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/raykit/project.rb', line 73 def elapsed elapsed=@timer.elapsed if(elapsed < 1.0) "%.1f" % (@timer.elapsed) + "s" else "%.0f" % (@timer.elapsed) + "s" end end |
#get_dev_dir(subdir) ⇒ Object
44 45 46 |
# File 'lib/raykit/project.rb', line 44 def get_dev_dir(subdir) Raykit::Environment::get_dev_dir(subdir) end |
#info ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/raykit/project.rb', line 82 def info ljust=35 puts '' puts "PROJECT.name".ljust(ljust) + Rainbow(PROJECT.name).yellow.bright puts "PROJECT.version".ljust(ljust) + Rainbow(PROJECT.version).yellow.bright puts "PROJECT.remote".ljust(ljust) + Rainbow(PROJECT.remote).yellow.bright puts "PROJECT.branch".ljust(ljust) + Rainbow(PROJECT.branch).yellow.bright puts "PROJECT.latest_commit".ljust(ljust) + Rainbow(PROJECT.latest_commit).yellow.bright puts "PROJECT.last_modified_filename".ljust(ljust) + Rainbow(PROJECT.last_modified_filename).yellow.bright #puts "PROJECT.elapsed".ljust(ljust) + Rainbow(PROJECT.elapsed).yellow.bright puts '' self end |
#last_modified_filename ⇒ Object
67 68 69 70 71 |
# File 'lib/raykit/project.rb', line 67 def last_modified_filename Dir.chdir(@directory) do Dir.glob("**/*.*").select{|f| File.file?(f)}.max_by {|f| File.mtime(f)} end end |
#latest_commit ⇒ Object
55 56 57 |
# File 'lib/raykit/project.rb', line 55 def latest_commit @repository.latest_commit(branch) end |
#pull ⇒ Object
130 131 132 133 134 135 |
# File 'lib/raykit/project.rb', line 130 def pull Dir.chdir(@directory) do run('git pull') end self end |
#push ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/raykit/project.rb', line 119 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
63 64 65 |
# File 'lib/raykit/project.rb', line 63 def remote @remote end |
#run(command, quit_on_failure = true) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/raykit/project.rb', line 151 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) cmd.summary 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 cmd end end |
#summary ⇒ Object
96 97 98 99 100 |
# File 'lib/raykit/project.rb', line 96 def summary info if(@verbose) puts "[" + elapsed + "] " + Rainbow(@name).yellow.bright + " " + Rainbow(version).yellow.bright end |
#tag ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/raykit/project.rb', line 137 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
59 60 61 |
# File 'lib/raykit/project.rb', line 59 def version @version end |