Class: Mullet::View

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

Overview

Decorates model with additional variables that can be rendered in a template. Applications will typically define subclasses with attributes that will be referenced by name from the templates.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Allow model values to be queried as if they were attributes.



29
30
31
32
33
34
35
# File 'lib/mullet/view.rb', line 29

def method_missing(name, *args)
  value = fetch(name)
  if value == Scope::NOT_FOUND
    value = super.method_missing(name, *args)
  end
  return value
end

Instance Method Details

#fetch(name) ⇒ Object

Resolves variable name to value from the model.



24
25
26
# File 'lib/mullet/view.rb', line 24

def fetch(name)
  return @model.get_variable_value(name)
end

#set_model(*data_objects) ⇒ Object

Sets model to decorate. Applications do not have to call this method directly. The template engine will call this method implicitly.



15
16
17
# File 'lib/mullet/view.rb', line 15

def set_model(*data_objects)
  @model = DefaultNestedScope.new(*data_objects)
end