Class: Consular::DSL
- Inherits:
-
Object
- Object
- Consular::DSL
- Defined in:
- lib/consular/dsl.rb
Overview
The DSL class provides the DSL for the Consular scripting file. It provides the basic commands such as:
#setup - commands to run when invoked by 'consular setup'
#window - commands to run in the context of a window
#tab - commands to run in the context of tab
#before - commands to run in the context before every tab context
The DSL class can be extended to provide additional API’s for core specific DSL.
Defined Under Namespace
Modules: Yaml
Instance Attribute Summary collapse
-
#_context ⇒ Object
readonly
Returns the value of attribute _context.
-
#_setup ⇒ Object
readonly
Returns the value of attribute _setup.
-
#_windows ⇒ Object
readonly
Returns the value of attribute _windows.
Instance Method Summary collapse
-
#before(*commands, &block) ⇒ Object
Run commands prior to each tab context.
-
#initialize(path) ⇒ DSL
constructor
Initializes the DSL library and stores the commands.
-
#run(*commands) ⇒ Object
Store commands to run in context.
-
#setup(*commands, &block) ⇒ Object
Run commands using prior to the workflow using the command ‘consular setup`.
-
#tab(*args, &block) ⇒ Object
Run commands in the context of a tab.
-
#to_hash ⇒ Hash
Returns yaml file as Consular formmatted hash.
-
#window(*args, &block) ⇒ Object
Run commands in the conext of a window.
Constructor Details
#initialize(path) ⇒ DSL
Initializes the DSL library and stores the commands.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/consular/dsl.rb', line 29 def initialize(path) @_setup = [] @_windows = ActiveSupport::OrderedHash.new @_windows['default'] = window_hash @_context = @_windows['default'] file = File.read(path) if path =~ /\.yml$/ @_file = YAML.load file extend Yaml else instance_eval file, __FILE__, __LINE__ end end |
Instance Attribute Details
#_context ⇒ Object (readonly)
Returns the value of attribute _context.
18 19 20 |
# File 'lib/consular/dsl.rb', line 18 def _context @_context end |
#_setup ⇒ Object (readonly)
Returns the value of attribute _setup.
18 19 20 |
# File 'lib/consular/dsl.rb', line 18 def _setup @_setup end |
#_windows ⇒ Object (readonly)
Returns the value of attribute _windows.
18 19 20 |
# File 'lib/consular/dsl.rb', line 18 def _windows @_windows end |
Instance Method Details
#before(*commands, &block) ⇒ Object
Run commands prior to each tab context.
77 78 79 80 |
# File 'lib/consular/dsl.rb', line 77 def before(*commands, &block) context = (@_context[:before] ||= []) block_given? ? run_context(context, &block) : context.concat(commands) end |
#run(*commands) ⇒ Object
Store commands to run in context.
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/consular/dsl.rb', line 145 def run(*commands) context = case when @_context.is_a?(Hash) && @_context[:tabs] @_context[:tabs]['default'][:commands] when @_context.is_a?(Hash) @_context[:commands] else @_context end context << commands.map { |c| c =~ /&$/ ? "(#{c})" : c }.join(" && ") end |
#setup(*commands, &block) ⇒ Object
Run commands using prior to the workflow using the command ‘consular setup`. This allows you to perform any command that needs to be ran prior to setup a particular project/script.
57 58 59 |
# File 'lib/consular/dsl.rb', line 57 def setup(*commands, &block) block_given? ? run_context(@_setup, &block) : @_setup.concat(commands) end |
#tab(*args, &block) ⇒ Object
Run commands in the context of a tab.
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/consular/dsl.rb', line 122 def tab(*args, &block) tabs = @_context[:tabs] key = "tab#{tabs.keys.size}" return (tabs[key] = { :commands => args }) unless block_given? context = (tabs[key] = {:commands => []}) = args. [:name] = args.first unless args.empty? context[:options] = run_context context, &block @_context = @_windows[@_windows.keys.last] # Jump back out into the context of the last window. end |
#to_hash ⇒ Hash
Returns yaml file as Consular formmatted hash
163 164 165 |
# File 'lib/consular/dsl.rb', line 163 def to_hash { :setup => @_setup, :windows => @_windows } end |
#window(*args, &block) ⇒ Object
Run commands in the conext of a window.
98 99 100 101 102 103 104 |
# File 'lib/consular/dsl.rb', line 98 def window(*args, &block) key = "window#{@_windows.keys.size}" = args. [:name] = args.first unless args.empty? context = (@_windows[key] = window_hash.merge(:options => )) run_context context, &block end |