Class: Gill::Git
Instance Attribute Summary collapse
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#category_path ⇒ Object
readonly
Returns the value of attribute category_path.
-
#repo_name ⇒ Object
readonly
Returns the value of attribute repo_name.
-
#repo_path ⇒ Object
readonly
Returns the value of attribute repo_path.
Instance Method Summary collapse
-
#build_category_folder ⇒ Object
Create the repository category folder if it does not exist.
-
#bundle_from_gemfile(path) ⇒ Object
Bundle.
-
#clone(bundle_install = true) ⇒ Object
Clone the passed repository uri name.
-
#initialize(category, repo_name, repo_uri) ⇒ Git
constructor
Initialize New Git Object.
-
#update ⇒ Object
Update/Bundle Repository.
-
#update_cache ⇒ Object
Update Cache.
Methods included from Helper
#ask, #basename, #blue, #folder_empty?, #green, #parent, #red
Constructor Details
#initialize(category, repo_name, repo_uri) ⇒ Git
Initialize New Git Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gill/git.rb', line 23 def initialize(category,repo_name,repo_uri) @repo_uri, @category, @repo_name = repo_uri, category, repo_name @category ||= File.basename(Gill.config.default_path) @category_path = File.join(Gill.config.source_path, @category) if @repo_name @repo_path = File.join(@category_path, @repo_name) else @repo_path = @category_path end end |
Instance Attribute Details
#category ⇒ Object (readonly)
Returns the value of attribute category.
12 13 14 |
# File 'lib/gill/git.rb', line 12 def category @category end |
#category_path ⇒ Object (readonly)
Returns the value of attribute category_path.
12 13 14 |
# File 'lib/gill/git.rb', line 12 def category_path @category_path end |
#repo_name ⇒ Object (readonly)
Returns the value of attribute repo_name.
12 13 14 |
# File 'lib/gill/git.rb', line 12 def repo_name @repo_name end |
#repo_path ⇒ Object (readonly)
Returns the value of attribute repo_path.
12 13 14 |
# File 'lib/gill/git.rb', line 12 def repo_path @repo_path end |
Instance Method Details
#build_category_folder ⇒ Object
Create the repository category folder if it does not exist.
64 65 66 |
# File 'lib/gill/git.rb', line 64 def build_category_folder FileUtils.mkdir_p(@category_path) end |
#bundle_from_gemfile(path) ⇒ Object
Bundle
73 74 75 76 77 78 79 80 |
# File 'lib/gill/git.rb', line 73 def bundle_from_gemfile(path) Dir.chdir(path) do return unless File.exists?('Gemfile') ask "Would you like to `bundle install`?", :default => true do system('bundle install') end end end |
#clone(bundle_install = true) ⇒ Object
Clone the passed repository uri name.
102 103 104 105 106 107 108 |
# File 'lib/gill/git.rb', line 102 def clone(bundle_install=true) raise(DirectoryError, "destination path '#{@repo_path}' already exists and is not an empty directory.") if File.directory?(@repo_path) build_category_folder ENV_BLACKLIST.each(&(ENV.method(:delete))) update_cache if system('git', 'clone', @repo_uri, @repo_path) bundle_from_gemfile(@repo_path) if bundle_install end |
#update ⇒ Object
Update/Bundle Repository
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gill/git.rb', line 85 def update paths = Dir[File.join(Gill.config.source_path, '**', "*#{@repo_name}*")] paths.each do |path| if Gill.config.paths.include?(path) ask "Update #{basename(path)} => #{green(path)}?", :default => true do Dir.chdir(path) do system('git', 'pull', 'origin', 'master') bundle_from_gemfile(path) end end end end end |
#update_cache ⇒ Object
Update Cache
Update the gill cache of a successful clone
and write changes to the Gill global cache.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/gill/git.rb', line 44 def update_cache cache = Gill.config.cache cache[:categories][@category.to_sym] ||= {} cache[:categories][@category.to_sym].merge!( @repo_name.to_sym => { :repo => @repo_uri, :path => @repo_path } ) Gill.config.write_cache(cache) end |