Class: ExecPHP::ScriptBatch

Inherits:
Object
  • Object
show all
Defined in:
lib/execphp/script_batch.rb

Overview

Represents a PHP script batch.

Instance Method Summary collapse

Constructor Details

#initialize {|batch| ... } ⇒ ScriptBatch

Constructor accepts a block for initialization.

Yields:

  • (batch)

    passes a self instance to the block

Yield Parameters:



10
11
12
13
# File 'lib/execphp/script_batch.rb', line 10

def initialize(&block)
  @buffer = ''
  block.call(self) if block_given?
end

Instance Method Details

#<<(script) ⇒ Object

Append a string of php code to a current batch.

Parameters:

  • script (String)

    a string of pure php code



32
33
34
# File 'lib/execphp/script_batch.rb', line 32

def << (script)
  @buffer << "#{script}\n\n"
end

#include_file(filename) ⇒ Object

Include php file to a current batch.

Parameters:

  • filename (String)

    php script filename



17
18
19
20
21
22
23
24
25
26
27
28
# 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_sString

Returns php script code.

Returns:

  • (String)

    php script code



37
38
39
# File 'lib/execphp/script_batch.rb', line 37

def to_s
  @buffer.chomp
end