Class: Terminitor::Dsl
- Inherits:
-
Object
- Object
- Terminitor::Dsl
- Defined in:
- lib/terminitor/dsl.rb
Overview
This class parses the Termfile to fit the new Ruby Dsl Syntax
Instance Method Summary collapse
-
#before(*commands, &block) ⇒ Object
runs commands before each tab in window context.
-
#initialize(path) ⇒ Dsl
constructor
A new instance of Dsl.
-
#run(*commands) ⇒ Object
stores command in context.
-
#setup(*commands, &block) ⇒ Object
Contains all commands that will be run prior to the usual ‘workflow’ e.g bundle install, setup forks, etc …
-
#tab(*args, &block) ⇒ Object
sets command context to be run inside specific tab.
-
#to_hash ⇒ Hash
Returns yaml file as Terminitor formmatted hash.
-
#window(options = {}, &block) ⇒ Object
sets command context to be run inside a specific window.
Constructor Details
#initialize(path) ⇒ Dsl
Returns a new instance of Dsl.
6 7 8 9 10 11 12 |
# File 'lib/terminitor/dsl.rb', line 6 def initialize(path) file = File.read(path) @setup = [] @windows = { 'default' => {:tabs => {'default' =>{:commands=>[]}}}} @_context = @windows['default'] instance_eval(file) end |
Instance Method Details
#before(*commands, &block) ⇒ Object
runs commands before each tab in window context
65 66 67 68 69 70 71 72 |
# File 'lib/terminitor/dsl.rb', line 65 def before(*commands, &block) @_context[:before] ||= [] if block_given? in_context @_context[:before], &block else @_context[:before].concat(commands) end end |
#run(*commands) ⇒ Object
stores command in context
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/terminitor/dsl.rb', line 46 def run(*commands) # if we are in a window context, append commands to default tab. if @_context.is_a?(Hash) && @_context[:tabs] current = @_context[:tabs]['default'][:commands] else current = @_context end current << commands.map do |c| c =~ /&$/ ? "(#{c})" : c end.join(" && ") end |
#setup(*commands, &block) ⇒ Object
Contains all commands that will be run prior to the usual ‘workflow’ e.g bundle install, setup forks, etc …
21 22 23 24 25 26 27 |
# File 'lib/terminitor/dsl.rb', line 21 def setup(*commands, &block) if block_given? in_context @setup, &block else @setup.concat(commands) end end |
#tab(*args, &block) ⇒ Object
sets command context to be run inside specific tab
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/terminitor/dsl.rb', line 80 def tab(*args, &block) tabs = @_context[:tabs] tab_name = "tab#{tabs.keys.size}" if block_given? tab_contents = tabs[tab_name] = {:commands => []} = {} = args.pop if args.last.is_a? Hash [:name] = args.first if args.first.is_a?(String) || args.first.is_a?(Symbol) tab_contents[:options] = unless .empty? in_context tab_contents[:commands], &block else tabs[tab_name] = { :commands => args} end end |
#to_hash ⇒ Hash
Returns yaml file as Terminitor formmatted hash
100 101 102 |
# File 'lib/terminitor/dsl.rb', line 100 def to_hash { :setup => @setup, :windows => @windows } end |
#window(options = {}, &block) ⇒ Object
sets command context to be run inside a specific window
35 36 37 38 39 40 |
# File 'lib/terminitor/dsl.rb', line 35 def window( = {}, &block) window_name = "window#{@windows.keys.size}" window_contents = @windows[window_name] = {:tabs => {'default' => {:commands =>[]}}} window_contents[:options] = unless .empty? in_context window_contents, &block end |