Class: Screenomat::DSL::Session
- Inherits:
-
Object
- Object
- Screenomat::DSL::Session
- Defined in:
- lib/screenomat/dsl/session.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name = '', code = '', &block) ⇒ Session
constructor
A new instance of Session.
- #screen(*opts) ⇒ Object
- #screen!(*opts) ⇒ Object
- #to_cmd ⇒ Object
Constructor Details
#initialize(name = '', code = '', &block) ⇒ Session
Returns a new instance of Session.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/screenomat/dsl/session.rb', line 8 def initialize(name = '', code = '', &block) @name = name @screens = [] @start_screen = 0 @start_screen_to_use = nil if !code.empty? instance_eval(code) else instance_eval(&block) end end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/screenomat/dsl/session.rb', line 6 def name @name end |
Instance Method Details
#screen(*opts) ⇒ Object
22 23 24 |
# File 'lib/screenomat/dsl/session.rb', line 22 def screen(*opts) @screens << Screen.new(*opts) end |
#screen!(*opts) ⇒ Object
26 27 28 29 |
# File 'lib/screenomat/dsl/session.rb', line 26 def screen!(*opts) @start_screen_to_use = Screen.new(*opts) @screens << @start_screen_to_use end |
#to_cmd ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/screenomat/dsl/session.rb', line 31 def to_cmd output = [ %{screen -dmS "#{@name}"} ] available_screen_ids = (0..9).to_a output += @screens.collect { |screen| if !screen.screen_id screen.screen_id = available_screen_ids.shift end commands = [] commands << %{screen -X -S "#{@name}" #{screen.screen}} if !screen.screen.empty? commands << %{screen -X -S "#{@name}" #{screen.stuff}} }.flatten @start_screen = @start_screen_to_use.screen_id if @start_screen_to_use output << %{screen -x "#{@name}" -p #{@start_screen}} output end |