Class: Basis::Repo
- Inherits:
-
Object
- Object
- Basis::Repo
- Defined in:
- lib/basis/repo.rb
Instance Attribute Summary collapse
-
#home ⇒ Object
readonly
Returns the value of attribute home.
Instance Method Summary collapse
- #add(url, name = nil) ⇒ Object
-
#initialize(home = "~/.basis") ⇒ Repo
constructor
A new instance of Repo.
- #remove(name) ⇒ Object
- #rename(old, new) ⇒ Object
- #templates(pattern = nil) ⇒ Object
- #update(pattern = nil) ⇒ Object
Constructor Details
#initialize(home = "~/.basis") ⇒ Repo
Returns a new instance of Repo.
10 11 12 |
# File 'lib/basis/repo.rb', line 10 def initialize home = "~/.basis" @home = File. home end |
Instance Attribute Details
#home ⇒ Object (readonly)
Returns the value of attribute home.
8 9 10 |
# File 'lib/basis/repo.rb', line 8 def home @home end |
Instance Method Details
#add(url, name = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/basis/repo.rb', line 14 def add url, name = nil name ||= File.basename(url, ".git").downcase.sub(/^basis[-_]/, "") if templates.keys.include? name raise Basis::Oops, "Template '#{name}' already exists!" end FileUtils.mkdir_p template_path git :clone, url, template_path(name) @templates = nil end |
#remove(name) ⇒ Object
27 28 29 30 31 |
# File 'lib/basis/repo.rb', line 27 def remove name FileUtils.rm_rf template_path(name) @templates = nil end |
#rename(old, new) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/basis/repo.rb', line 33 def rename old, new unless File.directory? template_path(old) raise Basis::Oops, "Unknown template: #{old}" end FileUtils.mv template_path(old), template_path(new) end |
#templates(pattern = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/basis/repo.rb', line 41 def templates pattern = nil unless @templates @templates = {} Dir[template_path("*")].each do |d| next unless File.directory? d template = Basis::Template.new d @templates[File.basename d] = template end end Hash[@templates.select { |n, t| pattern.nil? || /#{pattern}/ =~ n }] end |
#update(pattern = nil) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/basis/repo.rb', line 56 def update pattern = nil templates.each do |name, template| next unless pattern.nil? || /#{pattern}/ =~ name Dir.chdir(template.srcdir) { git :pull } end end |