Class: Proteus::InstanceProxy

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

Overview

Provides the environment for rendering templates.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(renderer, instance) ⇒ InstanceProxy


Constructor



39
40
41
42
43
44
45
46
47
# File 'lib/InstanceProxy.rb', line 39

def initialize( renderer, instance )
  @renderer = renderer
  @instance = instance
  
  @kind = @instance.kind
  @properties = @instance.final_properties
  @props = PropertyHash.new( @properties, @renderer )
  @children = @instance.children
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args) ⇒ Object

Redirects missing method calls to the property hash.



77
78
79
# File 'lib/InstanceProxy.rb', line 77

def method_missing(m, *args)
  @props[ m.to_s ]
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



57
58
59
# File 'lib/InstanceProxy.rb', line 57

def children
  @children
end

#instanceObject

Returns the value of attribute instance.



57
58
59
# File 'lib/InstanceProxy.rb', line 57

def instance
  @instance
end

#kindObject

Returns the value of attribute kind.



57
58
59
# File 'lib/InstanceProxy.rb', line 57

def kind
  @kind
end

#propertiesObject

Returns the value of attribute properties.



57
58
59
# File 'lib/InstanceProxy.rb', line 57

def properties
  @properties
end

#propsObject

Returns the value of attribute props.



57
58
59
# File 'lib/InstanceProxy.rb', line 57

def props
  @props
end

#rendererObject

Returns the value of attribute renderer.



57
58
59
# File 'lib/InstanceProxy.rb', line 57

def renderer
  @renderer
end

Instance Method Details

#instance_envObject

Returns the binding in the scope of the proxy instance.



70
71
72
# File 'lib/InstanceProxy.rb', line 70

def instance_env( )
  return binding()
end

#next_childObject

Returns the next child, or nil.



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/InstanceProxy.rb', line 84

def next_child
  if @_last_child_index.nil?
    @last_child = nil
    @_last_child_index = 0
    return renderer.render( children[0] )
  end
  
  @last_child = children[ @_last_child_index ]
  @_last_child_index += 1
  
  return renderer.render( children[ @_last_child_index ] )
end