Class: Stack::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/stack/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
12
13
# File 'lib/stack/runner.rb', line 8

def initialize(argv)
  @argv = argv
  @options = { }
  
  parse!
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



5
6
7
# File 'lib/stack/runner.rb', line 5

def arguments
  @arguments
end

#commandObject

Returns the value of attribute command.



4
5
6
# File 'lib/stack/runner.rb', line 4

def command
  @command
end

#configurationObject

Returns the value of attribute configuration.



3
4
5
# File 'lib/stack/runner.rb', line 3

def configuration
  @configuration
end

#generatorObject

Returns the value of attribute generator.



6
7
8
# File 'lib/stack/runner.rb', line 6

def generator
  @generator
end

Instance Method Details

#parse!Object

Parse options, command and arguments



16
17
18
19
20
21
22
23
# File 'lib/stack/runner.rb', line 16

def parse!
  options = Stack::parse! @argv
  
  @configuration = Stack::Configuration.new(options)
  
  @command = @argv.shift
  @arguments = @argv
end

#run!Object

Run stack!



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/stack/runner.rb', line 26

def run!
  if @command.nil?
    @command = "generate"
  end
  
  if Stack::COMMANDS.include?(@command)
    run_command
  else
    abort "Unknown command: #{@command}. Use one of #{Stack::COMMANDS.join(", ")}."
  end
end

#run_commandObject

Runs the specified command



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/stack/runner.rb', line 39

def run_command
  @generator = Stack::Generator.new(Stack::runner.configuration.source, Stack::runner.configuration.target)
  
  case self.command
  when /(generate|gen)/
    @generator.transform!
  when /(server)/
    # make a watcher
    watcher = Stack::Watcher.new(@generator)
    watcher.keep_alive = false
    watcher.observe
    # and a server
    server = Stack::Server.new(@generator)
    server.observe
  when /(watch)/
    # setup a watcher
    watcher = Stack::Watcher.new(@generator)
    watcher.observe
  end
end