class ExecPHP::ScriptBatch

Represents a PHP script batch.

Public Class Methods

new(&block) click to toggle source

Constructor accepts a block for initialization. @yield [batch] passes a self instance to the block @yieldparam batch [ScriptBatch] reference to itself

# File lib/execphp/script_batch.rb, line 10
def initialize(&block)
  @buffer = ''
  block.call(self) if block_given?
end

Public Instance Methods

<<(script) click to toggle source

Append a string of php code to a current batch. @param script [String] a string of pure php code

# File lib/execphp/script_batch.rb, line 32
def << (script)
  @buffer << "#{script}\n\n"
end
include_file(filename) click to toggle source

Include php file to a current batch. @param filename [String] php script filename

# File lib/execphp/script_batch.rb, line 17
def include_file(filename)
  contents = File.read(filename)

  match = /<\?(?:php)?\s*/.match(contents)
  if match
    contents.slice!(0, match[0].size)
  else
    contents = "?>\n#{contents}"
  end

  @buffer << "#{contents.chomp}\n\n"
end
to_s() click to toggle source

@return [String] php script code

# File lib/execphp/script_batch.rb, line 37
def to_s
  @buffer.chomp
end