Class: Isolate::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/isolate/git.rb

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ Git

Returns a new instance of Git.



13
14
15
# File 'lib/isolate/git.rb', line 13

def initialize entry
  @entry = entry
end

Class Method Details

.setup(entry) ⇒ Object



9
10
11
# File 'lib/isolate/git.rb', line 9

def self.setup entry
  new(entry).setup
end

Instance Method Details

#buildObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/isolate/git.rb', line 17

def build
  gemspec_path = Dir['**/*.gemspec'].first.to_s

  # does the repo contain a gemspec? Just build it.
  if File.size? gemspec_path
    sh 'gem', 'build', gemspec_path
  # try running rake package. Projects that use Hoe for example don't come
  # with a gemspec, but one can be built. One may have to add build
  # dependencies to the Isolate file. ie. rake, hoe.
  elsif File.size? 'Rakefile'
    sh 'rake', 'package'
  else
    # don't know what to do
  end

  built_path = Dir['**/*.gem'].first.to_s

  if File.size? built_path
    built_path
  else
    log "unable to build or find #{@entry.name} gem"
    false
  end
end

#cloneObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/isolate/git.rb', line 42

def clone
  src = @entry.options[:git]
  name = @entry.name

  unless sh 'git','clone', src, name
    log "unable to clone #{src}"
  end

  name if File.directory? name
end

#git?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/isolate/git.rb', line 53

def git?
  @entry.options.key? :git
end

#setupObject

For each entry, if options exists try to clone the repo and build the gem. If either fails, warn and let Isolate continue doing it’s normal thing.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/isolate/git.rb', line 60

def setup
  return unless git?

  Dir.chdir source_path do

    path = clone

    Dir.chdir path do

      if name = build then
        file = File.expand_path name

        # private instance variable. When this is set Entry#install looks
        # for a local file instead of trying to download by name
        @entry.instance_variable_set :@file, file
      end

    end if path

  end
end

#source_pathObject

Where to put the git repos.



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/isolate/git.rb', line 83

def source_path
  src = File.join *[
    sandbox.path,
    ('..' if sandbox.multiruby?),
    'src'
  ].compact

  FileUtils.mkdir_p src

  src
end