Class: Rbdock::Application
- Inherits:
-
Object
- Object
- Rbdock::Application
- Defined in:
- lib/rbdock/application.rb
Class Method Summary collapse
Instance Method Summary collapse
- #checked_system(command, action) ⇒ Object
- #clone_path ⇒ Object
- #cloned? ⇒ Boolean
- #execute ⇒ Object
- #git? ⇒ Boolean
- #git_clone ⇒ Object
- #git_update ⇒ Object
-
#initialize(url) ⇒ Application
constructor
A new instance of Application.
- #local? ⇒ Boolean
- #replace ⇒ Object
- #same_application? ⇒ Boolean
Constructor Details
#initialize(url) ⇒ Application
Returns a new instance of Application.
11 12 13 14 15 |
# File 'lib/rbdock/application.rb', line 11 def initialize url @logger = Log4r::Logger.new("rbdock::application") @logger.info("Preparing application at #{url}") @url = url end |
Class Method Details
.prepare(url) ⇒ Object
7 8 9 |
# File 'lib/rbdock/application.rb', line 7 def self.prepare url new(url).execute end |
Instance Method Details
#checked_system(command, action) ⇒ Object
86 87 88 89 90 |
# File 'lib/rbdock/application.rb', line 86 def checked_system command, action if not system(command) raise StandardError, "#{action} #{@url} is failed." end end |
#clone_path ⇒ Object
65 66 67 |
# File 'lib/rbdock/application.rb', line 65 def clone_path @clone_path ||= '.rbdock_app' end |
#cloned? ⇒ Boolean
57 58 59 |
# File 'lib/rbdock/application.rb', line 57 def cloned? File.exist? clone_path end |
#execute ⇒ Object
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 43 44 45 46 47 |
# File 'lib/rbdock/application.rb', line 17 def execute if local? raise ArgumentError, "Application path #{@url} is not exist" if not File.exist?(@url) @logger.debug("Use local application at #{@url}") return @url end if git? raise StandardError, "Command git not found." if `which git`.empty? @logger.debug("Use `git` to clone application") if cloned? and same_application? @logger.debug("Update application at #{@url}") git_update end if cloned? and not same_application? @logger.debug("Replace application at #{@url}") replace end if not cloned? @logger.debug("Clone application at #{@url}") git_clone end end return clone_path end |
#git? ⇒ Boolean
53 54 55 |
# File 'lib/rbdock/application.rb', line 53 def git? @url.include?(".git") || @url.include?("github.com") || @url.include?("git@") end |
#git_clone ⇒ Object
69 70 71 72 |
# File 'lib/rbdock/application.rb', line 69 def git_clone checked_system("git clone -q #{@url} #{clone_path}", "Clone") STDERR.puts "Clone #{@url} to #{clone_path}/" end |
#git_update ⇒ Object
74 75 76 77 |
# File 'lib/rbdock/application.rb', line 74 def git_update checked_system("cd #{clone_path}; git pull -q", "Update") STDERR.puts "Update #{@url}" end |
#local? ⇒ Boolean
49 50 51 |
# File 'lib/rbdock/application.rb', line 49 def local? not URI.regexp =~ @url end |
#replace ⇒ Object
79 80 81 82 83 84 |
# File 'lib/rbdock/application.rb', line 79 def replace checked_system("rm -fr #{clone_path}", "Replace") git_clone STDERR.puts "Delete old application and clone #{@url} to #{clone_path}/" clone_path end |
#same_application? ⇒ Boolean
61 62 63 |
# File 'lib/rbdock/application.rb', line 61 def same_application? @url == `git --git-dir=#{clone_path}/.git config --get remote.origin.url`.chomp end |