Class: Mason::Buildpack

Inherits:
Object
  • Object
show all
Defined in:
lib/mason/buildpack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Buildpack

Returns a new instance of Buildpack.



10
11
12
13
14
15
16
# File 'lib/mason/buildpack.rb', line 10

def initialize(dir)
  @dir = dir
  Dir.chdir(@dir) do
    @name = File.basename(@dir)
    @url  = %x{ git config remote.origin.url }.chomp
  end
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



8
9
10
# File 'lib/mason/buildpack.rb', line 8

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/mason/buildpack.rb', line 8

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/mason/buildpack.rb', line 8

def url
  @url
end

Instance Method Details

#<=>(other) ⇒ Object



18
19
20
# File 'lib/mason/buildpack.rb', line 18

def <=>(other)
  self.name <=> other.name
end

#compile(app, env_file = nil, cache = nil) ⇒ Object



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
# File 'lib/mason/buildpack.rb', line 29

def compile(app, env_file=nil, cache=nil)
  cache_dir = cache || "#{app}/.git/cache"
  puts "  caching in #{cache_dir}"
  compile_dir = Dir.mktmpdir
  FileUtils.rm_rf compile_dir
  FileUtils.cp_r app, compile_dir, :preserve => true
  FileUtils.mkdir_p cache_dir
  Dir.chdir(compile_dir) do
    IO.popen(%{ #{script("compile")} "#{compile_dir}" "#{cache_dir}" }) do |io|
      until io.eof?
        data = io.gets
        data.gsub!(/^-----> /, "  + ")
        data.gsub!(/^       /, "      ")
        data.gsub!(/^\s+\!\s+$/, "")
        data.gsub!(/^\s+\!\s+/, "  ! ")
        data.gsub!(/^\s+$/, "")
        print data
      end
    end
    raise "compile failed" unless $?.exitstatus.zero?
  end
  release = YAML.load(`#{script('release')} "#{compile_dir}"`)
  write_env(compile_dir, release, env_file)
  write_procfile(compile_dir, release)
  [compile_dir, release]
end

#detect(app) ⇒ Object



22
23
24
25
26
27
# File 'lib/mason/buildpack.rb', line 22

def detect(app)
  mkchtmpdir do
    output = %x{ #{script("detect")} "#{app}" }
    $?.exitstatus.zero? ? output.chomp : nil
  end
end