Class: Wad::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/wad/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Compiler

Constructs a new compiler which will do its work in root/vendor, copying vendor/bundle to vendor/lib.



24
25
26
27
28
# File 'lib/wad/compiler.rb', line 24

def initialize root
  @root = root
  @reporter = Reporter.new
  @bundle = Bundle.new
end

Instance Attribute Details

#bundleObject (readonly)

Returns the value of attribute bundle.



17
18
19
# File 'lib/wad/compiler.rb', line 17

def bundle
  @bundle
end

#reporterObject (readonly)

Returns the value of attribute reporter.



16
17
18
# File 'lib/wad/compiler.rb', line 16

def reporter
  @reporter
end

#rootObject (readonly)

Returns the value of attribute root.



15
16
17
# File 'lib/wad/compiler.rb', line 15

def root
  @root
end

Instance Method Details

#bundle_installObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/wad/compiler.rb', line 44

def bundle_install
  status = false # declare local var

  reporter.report_bundle_install do
    status = bundle.install do |line|
      reporter.report_bundle_install_line(line)
    end
  end

  status
end

#compileObject



30
31
32
33
34
35
36
# File 'lib/wad/compiler.rb', line 30

def compile
  target = Target.new(root, 'vendor/lib', reporter)

  empty(target)
  bundle_install or raise "Please fix bundler failures first."
  copy_files(target)
end

#copy_files(target) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/wad/compiler.rb', line 56

def copy_files target
  reporter.report_copy_phase(target)

  # my editor messes up highlighting upon encountering 'gem'... so ghem it is. 
  each_gem do |ghem| 
    reporter.report_copy_for(ghem) do
      ghem.each_lib_file do |file|
        # We can't 'copy' directories
        next if file.directory?

        file.copy(target)
      end
    end
  end
end

#empty(target) ⇒ Object



38
39
40
41
42
# File 'lib/wad/compiler.rb', line 38

def empty target
  reporter.report_emptying(target)
  # Danger.
  FileUtils.rm_rf(target.path)
end