Class: Hem::Lib::Seed::Seed
- Inherits:
-
Object
- Object
- Hem::Lib::Seed::Seed
- Includes:
- Hem::Logging
- Defined in:
- lib/hem/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 Hem::Logging
Constructor Details
#initialize(seed_path, url) ⇒ Seed
Returns a new instance of Seed.
7 8 9 10 |
# File 'lib/hem/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, options = {}) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/hem/lib/seed/seed.rb', line 93 def name_to_url name, = {} = { :use_short_seed_name => true }.merge() path = File. name if name.include?(':') name elsif ![:use_short_seed_name] || (name.match(/^(\.|\/|~)/) && path) path else "[email protected]:inviqa/hem-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/hem/lib/seed/seed.rb', line 21 def export path, opts = {} opts = { :name => 'seed', :ref => 'master' }.merge(opts) path = File.(path) FileUtils.mkdir_p path Hem.ui.success "Exporting #{opts[:name]} to #{path}" tmp_path = Dir.mktmpdir("hem-seed-export") Dir.chdir @seed_path do Hem::Helper.shell "git clone --branch #{opts[:ref].shellescape} . #{tmp_path}" end Dir.chdir tmp_path do Hem::Helper.shell "git archive #{opts[:ref].shellescape} | tar -x -C #{path.shellescape}" submodules = Hem::Helper.shell "git submodule status", :capture => true, :strip => false next if submodules.empty? Hem.ui.success "Cloning submodules" Hem::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] Hem.ui.success "Exporting '#{submodule_path}' #{opts[:name]} submodule" Hem::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/hem/lib/seed/seed.rb', line 12 def = [] Dir.chdir @seed_path do tag_output = Hem::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/hem/lib/seed/seed.rb', line 62 def update Hem.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 Hem::Helper.shell 'git', 'fetch', 'origin' end else logger.info "Cloning seed from #{@url} to #{@seed_path}" Hem::Helper.shell 'git', 'clone', @url, @seed_path, '--mirror' end end |
#version ⇒ Object
86 87 88 89 90 |
# File 'lib/hem/lib/seed/seed.rb', line 86 def version Dir.chdir @seed_path do Hem::Helper.shell 'git', 'rev-parse', '--short', 'HEAD', :capture => true end end |
#vm_ip ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/hem/lib/seed/seed.rb', line 77 def vm_ip [ 10, 10, [*0..255].sample, [*2..255].sample ].join('.') end |