Class: Hobo::Lib::Seed::Seed
- Inherits:
-
Object
- Object
- Hobo::Lib::Seed::Seed
- Includes:
- Hobo::Logging
- Defined in:
- lib/hobo/lib/seed/seed.rb
Class Method Summary collapse
Instance Method Summary collapse
- #export(path, opts = {}) ⇒ Object
-
#initialize(seed_path, url) ⇒ Seed
constructor
A new instance of Seed.
- #tags ⇒ Object
- #update ⇒ Object
- #version ⇒ Object
- #vm_ip ⇒ Object
Methods included from Hobo::Logging
Constructor Details
#initialize(seed_path, url) ⇒ Seed
Returns a new instance of Seed.
7 8 9 10 |
# File 'lib/hobo/lib/seed/seed.rb', line 7 def initialize(seed_path, url) @seed_path = seed_path @url = url end |
Class Method Details
.name_to_url(name) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/hobo/lib/seed/seed.rb', line 93 def name_to_url name path = File. name if name.match(/^(\.|\/|~)/) && path path else "[email protected]:inviqa/hobo-seed-#{name}" end end |
Instance Method Details
#export(path, opts = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/hobo/lib/seed/seed.rb', line 21 def export path, opts = {} opts = { :name => 'seed', :ref => 'master' }.merge(opts) path = File.(path) FileUtils.mkdir_p path Hobo.ui.success "Exporting #{opts[:name]} to #{path}" tmp_path = Dir.mktmpdir("hobo-seed-export") Dir.chdir @seed_path do Hobo::Helper.shell "git clone --branch #{opts[:ref].shellescape} . #{tmp_path}" end Dir.chdir tmp_path do Hobo::Helper.shell "git archive #{opts[:ref].shellescape} | tar -x -C #{path.shellescape}" submodules = Hobo::Helper.shell "git submodule status", :capture => true, :strip => false next if submodules.empty? Hobo.ui.success "Cloning submodules" Hobo::Helper.shell "git submodule update --init", :realtime => true, :indent => 2 # Export submodules # git submodule foreach does not play nice on windows so we fake it here submodules.split("\n").each do |line| matches = line.match /^[\s-][a-z0-9]+ (.+)/ next unless matches submodule_path = matches[1] Hobo.ui.success "Exporting '#{submodule_path}' #{opts[:name]} submodule" Hobo::Helper.shell "cd #{tmp_path}/#{submodule_path.shellescape} && git archive HEAD | tar -x -C #{path}/#{submodule_path.shellescape}" end end FileUtils.rm_f tmp_path end |
#tags ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/hobo/lib/seed/seed.rb', line 12 def = [] Dir.chdir @seed_path do tag_output = Hobo::Helper.shell "git tag", :capture => true = tag_output.split("\n") end end |
#update ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/hobo/lib/seed/seed.rb', line 62 def update Hobo.ui.success "Fetching / Updating seed" FileUtils.mkdir_p @seed_path if File.exists? File.join(@seed_path, 'HEAD') Dir.chdir @seed_path do logger.info "Updating seed in #{@seed_path}" # Need to be specific here as GH for windows adds an invalid "upstream" remote to all repos Hobo::Helper.shell 'git', 'fetch', 'origin' end else logger.info "Cloning seed from #{@url} to #{@seed_path}" Hobo::Helper.shell 'git', 'clone', @url, @seed_path, '--mirror' end end |
#version ⇒ Object
86 87 88 89 90 |
# File 'lib/hobo/lib/seed/seed.rb', line 86 def version Dir.chdir @seed_path do Hobo::Helper.shell 'git', 'rev-parse', '--short', 'HEAD', :capture => true end end |
#vm_ip ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/hobo/lib/seed/seed.rb', line 77 def vm_ip [ 10, [*0..255].sample, [*0..255].sample, [*2..255].sample ].join('.') end |