Class: Vorx::Store
- Inherits:
-
Object
- Object
- Vorx::Store
- Defined in:
- lib/vorx/store.rb
Instance Method Summary collapse
- #add(git_reference) ⇒ Object
- #all ⇒ Object
- #delete(git_reference) ⇒ Object
- #delete_all ⇒ Object
- #fetch(git_reference) ⇒ Object
- #fetch_all ⇒ Object
- #find(git_reference) ⇒ Object
-
#initialize(base_path = '~/.vorx/store', stderr: $stderr, store_file: 'vorx_store.yml', repository_prefix: '') ⇒ Store
constructor
A new instance of Store.
- #reload ⇒ Object
Constructor Details
#initialize(base_path = '~/.vorx/store', stderr: $stderr, store_file: 'vorx_store.yml', repository_prefix: '') ⇒ Store
Returns a new instance of Store.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/vorx/store.rb', line 7 def initialize(base_path = '~/.vorx/store', stderr: $stderr, store_file: 'vorx_store.yml', repository_prefix: '') @base_path = Pathname.new(base_path.to_s) @stderr = stderr @repository_prefix = repository_prefix @base_path.mkpath @store = YAML::Store.new(@base_path.join(store_file).to_s) @store.transaction { @store[:repositories] ||= Set.new } end |
Instance Method Details
#add(git_reference) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/vorx/store.rb', line 32 def add(git_reference) git_repository = resolve_git_reference(git_reference) @store.transaction { @store[:repositories] << git_repository } git_repository end |
#all ⇒ Object
62 63 64 |
# File 'lib/vorx/store.rb', line 62 def all @store.transaction { @store[:repositories] } end |
#delete(git_reference) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/vorx/store.rb', line 48 def delete(git_reference) git_repository = resolve_git_reference(git_reference) `rm -rf #{git_folder(git_repository)}` @store.transaction { @store[:repositories].delete(git_repository) } end |
#delete_all ⇒ Object
56 57 58 59 60 |
# File 'lib/vorx/store.rb', line 56 def delete_all all.each do |repo| delete(repo) end end |
#fetch(git_reference) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/vorx/store.rb', line 18 def fetch(git_reference) git_repository = find(git_reference) || add(git_reference) git_fetch_references(git_repository) update_repository(git_repository, cloned: true) end |
#fetch_all ⇒ Object
26 27 28 29 30 |
# File 'lib/vorx/store.rb', line 26 def fetch_all all.each do |repo| fetch(repo) end end |
#find(git_reference) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/vorx/store.rb', line 40 def find(git_reference) git_repository = resolve_git_reference(git_reference) git_repositories.detect do |gr| gr == git_repository end end |
#reload ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vorx/store.rb', line 66 def reload @store.transaction do repos = @store[:repositories] repos.select { |r| git_folder(r).exist? }.each do |repo| repos.delete(repo) repos << repo.update(cloned: true) end end end |