class Grundstein::Generator::Repository
Manages the generator repository. Implemented as a singleton (see `instance` method). It uses git to keep the repository up to date. It will check the repo out to '~/.grundstein'. It also creates a file in this directory named 'last_update' where the timestamp of the last update is kept. If this time stamp is too long ago, it will update the repo.
Use this class by using the instance method: `Generator::Repository.instance`
Constants
- OUTDATED_THRESHOLD
Public Class Methods
instance()
click to toggle source
# File lib/grundstein/generator/repository.rb, line 15 def self.instance @instance ||= Repository.new(File.expand_path("~/.grundstein")) return @instance end
new(path)
click to toggle source
The constructor will check if the repository is there and create it if necessary. If the repo is outdated, it will update it.
# File lib/grundstein/generator/repository.rb, line 42 def initialize(path) @path = path @git = Git.open(@path) # , :log => Logger.new(STDOUT)) update if outdated? rescue ArgumentError => _ setup retry end
Public Instance Methods
generator_path(name)
click to toggle source
# File lib/grundstein/generator/repository.rb, line 34 def generator_path(name) return File.join(generators_path, name) end
generators()
click to toggle source
Iteratates through all generators and yields the block with the |name, desc|.
# File lib/grundstein/generator/repository.rb, line 21 def generators result = [] Dir.foreach(generators_path) do |dir| next if dir.start_with?('.', '#') result << dir end return result end
generators_path()
click to toggle source
# File lib/grundstein/generator/repository.rb, line 30 def generators_path return File.join(@path, 'generators') end
Protected Instance Methods
last_update_file_path()
click to toggle source
# File lib/grundstein/generator/repository.rb, line 75 def last_update_file_path return File.join(@path, 'last_update') end
outdated?()
click to toggle source
# File lib/grundstein/generator/repository.rb, line 51 def outdated? return DateTime.parse(File.read(last_update_file_path)) < (DateTime.now - OUTDATED_THRESHOLD) rescue => _ return true end
setup()
click to toggle source
# File lib/grundstein/generator/repository.rb, line 63 def setup puts "Initializing generator repository...".c_warning @git = Git.init(@path) @git.add_remote('origin', 'https://github.com/motine/grundstein.git') # TODO: make sure git > 1.7 # let's only checkout the generators @git.config('core.sparsecheckout', true) File.write(File.join(@git.repo.path, 'info', 'sparse-checkout'), 'generators') update end
update()
click to toggle source
# File lib/grundstein/generator/repository.rb, line 57 def update puts "Updating generator repository..." @git.pull File.write(last_update_file_path, DateTime.now.to_s) end