Class: SerializableProc

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/invoice_pdf_helper.rb

Overview

This let’s us add the on_start_new_page functionality in the PDF::Writer library

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proc_string) ⇒ SerializableProc

Returns a new instance of SerializableProc.



13
14
15
16
# File 'app/helpers/invoice_pdf_helper.rb', line 13

def initialize( proc_string )
@code = proc_string
@proc = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



22
23
24
25
26
27
28
# File 'app/helpers/invoice_pdf_helper.rb', line 22

def method_missing( method, *args )
if to_proc.respond_to? method
@proc.send(method, *args)
else
super
end
end

Class Method Details

._load(proc_string) ⇒ Object

:nodoc:



9
10
11
# File 'app/helpers/invoice_pdf_helper.rb', line 9

def self._load( proc_string )
new(proc_string)
end

Instance Method Details

#_dump(depth) ⇒ Object



18
19
20
# File 'app/helpers/invoice_pdf_helper.rb', line 18

def _dump( depth )
@code
end

#to_procObject



30
31
32
33
34
35
36
37
38
39
40
# File 'app/helpers/invoice_pdf_helper.rb', line 30

def to_proc( )
return @proc unless @proc.nil?

if @code =~ /\A\s*(?:lambda|proc)(?:\s*\{|\s+do).*(?:\}|end)\s*\Z/
@proc = eval @code
elsif @code =~ /\A\s*(?:\{|do).*(?:\}|end)\s*\Z/
@proc = eval "lambda #{@code}"
else
@proc = eval "lambda { #{@code} }"
end
end

#to_yamlObject



42
43
44
45
# File 'app/helpers/invoice_pdf_helper.rb', line 42

def to_yaml( )
@proc = nil
super
end