Class: ExecPHP::ScriptBatch
- Inherits:
-
Object
- Object
- ExecPHP::ScriptBatch
- Defined in:
- lib/execphp/script_batch.rb
Overview
Represents a PHP script batch.
Instance Method Summary collapse
-
#<<(script) ⇒ Object
Append a string of php code to a current batch.
-
#include_file(filename) ⇒ Object
Include php file to a current batch.
-
#initialize {|batch| ... } ⇒ ScriptBatch
constructor
Constructor accepts a block for initialization.
-
#to_s ⇒ String
Php script code.
Constructor Details
#initialize {|batch| ... } ⇒ ScriptBatch
Constructor accepts a block for initialization.
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.
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.
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_s ⇒ String
Returns php script code.
37 38 39 |
# File 'lib/execphp/script_batch.rb', line 37 def to_s @buffer.chomp end |