Class: Remoting::Dsl::ScriptBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/remoting/dsl/script_builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScriptBuilder

Returns a new instance of ScriptBuilder.



23
24
25
# File 'lib/remoting/dsl/script_builder.rb', line 23

def initialize
  @commands = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object (private)



44
45
46
# File 'lib/remoting/dsl/script_builder.rb', line 44

def method_missing(*args)
  command(*args)       
end

Class Method Details

.build(&block) ⇒ Object



16
17
18
19
20
# File 'lib/remoting/dsl/script_builder.rb', line 16

def build(&block)  
  instance = self.new
  instance.instance_eval(&block)
  instance.commands
end

Instance Method Details

#command(*args) ⇒ Object



36
37
38
39
40
# File 'lib/remoting/dsl/script_builder.rb', line 36

def command(*args)
  cmd = args.map(&:to_s).join(" ")
  @commands << cmd
  cmd
end

#commandsObject



27
28
29
30
31
32
33
34
# File 'lib/remoting/dsl/script_builder.rb', line 27

def commands()
    @commands.flatten.map! do |c|
      c.split(/[\r\n]/).map{|l|
        line = l.strip
        line.empty? ? nil : line
      }
    end.flatten.compact.delete_if(&:empty?)
end