Class: RubyMVC::Views::View

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ View

Returns a new instance of View.



67
68
69
70
71
72
# File 'lib/ruby_mvc/views.rb', line 67

def initialize(*args)
  @widget = View.create_widget(self.class)
  if(options = args.last).is_a? Hash
    self.controller = options[:controller]
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &b) ⇒ Object



74
75
76
# File 'lib/ruby_mvc/views.rb', line 74

def method_missing(m, *a, &b)
  @widget.send(m, *a, &b)
end

Instance Attribute Details

#controllerObject

Returns the value of attribute controller.



66
67
68
# File 'lib/ruby_mvc/views.rb', line 66

def controller
  @controller
end

#widgetObject

Returns the value of attribute widget.



66
67
68
# File 'lib/ruby_mvc/views.rb', line 66

def widget
  @widget
end

Class Method Details

.create_widget(klass) ⇒ Object



44
45
46
47
48
49
# File 'lib/ruby_mvc/views.rb', line 44

def self.create_widget(klass)
  w = self.widget_def(klass)
  args = w[:args] 
  block = w[:block]
  args[0].new(*args[1..-1], &block)
end

.widget(*args, &block) ⇒ Object

This method is used to define the primary widget class through which this view may be added to other widgets.



56
57
58
59
# File 'lib/ruby_mvc/views.rb', line 56

def widget(*args, &block)
  puts "Set widget for #{self}: #{args.inspect}"
  @widget_def = { :args => args, :block => block }
end

.widget_def(targ = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby_mvc/views.rb', line 30

def self.widget_def(targ = nil)
  if targ == nil
    @widget_def
  else
    if (x = targ.widget_def).nil?
      if targ != RubyMVC::Views::View
        self.widget_def(targ.superclass)
      end
    else
      x
    end
  end
end

Instance Method Details

#peerObject



62
63
64
# File 'lib/ruby_mvc/views.rb', line 62

def peer
  @widget.peer
end