class GemOnDemand::Checkout
Constants
- CACHE_DURATION
- DIR
- NOT_FOUND
- NotFound
- UPDATED_AT
Attributes
project[RW]
user[RW]
Public Class Methods
new(user, project)
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 11 def initialize(user, project) self.user = user self.project = project Utils.ensure_directory(dir) end
Public Instance Methods
cache()
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 22 def cache @cache ||= FileCache.new("#{dir}/cache") end
chdir(&block)
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 17 def chdir(&block) clone_or_refresh Dir.chdir(dir, &block) end
Private Instance Methods
clone()
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 65 def clone Utils.remove_directory(dir) cloned = Utils.sh "git clone git@github.com:#{user}/#{project}.git #{dir}", :fail => :allow Utils.ensure_directory(dir) if cloned fresh! else not_found! end end
clone_or_refresh()
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 49 def clone_or_refresh if cloned? refresh if need_refresh? elsif was_not_found? not_found! else clone end end
cloned?()
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 76 def cloned? File.directory?("#{dir}/.git") end
dir()
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 28 def dir "#{DIR}/#{user}/#{project}" end
fresh!()
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 45 def fresh! cache.write(UPDATED_AT, Time.now.to_i) end
need_refresh?()
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 41 def need_refresh? cache.read(UPDATED_AT).to_i < Time.now.to_i - CACHE_DURATION end
not_found!()
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 36 def not_found! cache.write(NOT_FOUND, true) raise NotFound end
refresh()
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 59 def refresh Dir.chdir(dir) { Utils.sh "git fetch origin" } cache.delete Project::DEPENDENCIES fresh! end
was_not_found?()
click to toggle source
# File lib/gem_on_demand/checkout.rb, line 32 def was_not_found? cache.read(NOT_FOUND) end