Class: Stack::Runner
- Inherits:
-
Object
- Object
- Stack::Runner
- Defined in:
- lib/stack/runner.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#command ⇒ Object
Returns the value of attribute command.
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#generator ⇒ Object
Returns the value of attribute generator.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
-
#parse! ⇒ Object
Parse options, command and arguments.
-
#run! ⇒ Object
Run stack!.
-
#run_command ⇒ Object
Runs the specified command.
Constructor Details
#initialize(argv) ⇒ Runner
Returns a new instance of Runner.
8 9 10 11 12 13 14 |
# File 'lib/stack/runner.rb', line 8 def initialize(argv) @argv = argv @options = { } parse! end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
5 6 7 |
# File 'lib/stack/runner.rb', line 5 def arguments @arguments end |
#command ⇒ Object
Returns the value of attribute command.
4 5 6 |
# File 'lib/stack/runner.rb', line 4 def command @command end |
#configuration ⇒ Object
Returns the value of attribute configuration.
3 4 5 |
# File 'lib/stack/runner.rb', line 3 def configuration @configuration end |
#generator ⇒ Object
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
17 18 19 20 21 22 23 24 |
# File 'lib/stack/runner.rb', line 17 def parse! = Stack::parse! @argv @configuration = Stack::Configuration.new() @command = @argv.shift @arguments = @argv end |
#run! ⇒ Object
Run stack!
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/stack/runner.rb', line 27 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_command ⇒ Object
Runs the specified command
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/stack/runner.rb', line 40 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 if Stack::runner.configuration.server_watch watcher = Stack::Watcher.new(@generator) watcher.keep_alive = false watcher.observe else #@generator.transform! end # and a server server = Stack::Server.new(@generator) server.observe when /(watch)/ # setup a watcher watcher = Stack::Watcher.new(@generator) watcher.observe when /(create)/ File.open("#{Stack::runner.configuration.source}/_stack.yml", "w") { |file| YAML.dump(Stack::runner.configuration.to_hash, file) } puts "Created configuration file at '#{Stack::runner.configuration.source}/_stack.yml'" end end |