Class: Minirails::Builder

Inherits:
Struct
  • Object
show all
Defined in:
lib/minirails.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#specfileObject

Returns the value of attribute specfile

Returns:

  • (Object)

    the current value of specfile



64
65
66
# File 'lib/minirails.rb', line 64

def specfile
  @specfile
end

Instance Method Details

#define(name = nil, opts = {}, &block) ⇒ Object

DSL API



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/minirails.rb', line 67

def define(name = nil, opts = {}, &block)
  type = opts[:type] || :rails
  klazz = {
    rails:  RailsApp,
    rack:   RackApp,
    blank:  App
  }[type]

  if opts[:initialize]
    parent = apps.find {|a| a.name == opts[:initialize] }
    apps << WrappedApp.new(klazz.new(name, block), parent)
  else
    apps << klazz.new(name, block)
  end
end

#spawnObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/minirails.rb', line 90

def spawn
  boot

  require "foreman/engine/cli"

  engine = Foreman::Engine::CLI.new
  apps.each.with_index do |app, index|
    engine.register(
      app.name || "web-#{index}",
      "#{File.expand_path($0)} #{File.expand_path(specfile)} #{index}",
      cwd: Dir.pwd
    )
  end

  engine.start
end

#start(num) ⇒ Object

internals



84
85
86
87
88
# File 'lib/minirails.rb', line 84

def start(num)
  boot
  apps[num].init
  apps[num].call
end