Class: RubyMVC::Views::PeerView

Inherits:
View show all
Defined in:
lib/ruby_mvc/views/view.rb

Direct Known Subclasses

BrowserView, GridTableView

Instance Attribute Summary collapse

Attributes inherited from View

#actions, #controller

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Toolkit::SignalHandler::ClassMethods

#signal, #signals, #valid_signal!, #valid_signal?

Methods included from Toolkit::SignalHandler

#signal_emit

Constructor Details

#initialize(options = {}) ⇒ PeerView

Returns a new instance of PeerView.



90
91
92
93
# File 'lib/ruby_mvc/views/view.rb', line 90

def initialize(options = {})
  super
  @widget = PeerView.create_widget(self.class, options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



116
117
118
# File 'lib/ruby_mvc/views/view.rb', line 116

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

Instance Attribute Details

#frameObject

This method is used to retrieve a reference to the parent frame



87
88
89
# File 'lib/ruby_mvc/views/view.rb', line 87

def frame
  @frame
end

#widgetObject

Returns the value of attribute widget.



89
90
91
# File 'lib/ruby_mvc/views/view.rb', line 89

def widget
  @widget
end

Class Method Details

.create_widget(klass, options = {}) ⇒ Object



63
64
65
66
67
68
# File 'lib/ruby_mvc/views/view.rb', line 63

def self.create_widget(klass, options = {})
  w = self.widget_def(klass)
  args = (w[:args].clone << options)
  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.



75
76
77
78
# File 'lib/ruby_mvc/views/view.rb', line 75

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

.widget_def(targ = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ruby_mvc/views/view.rb', line 49

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

Instance Method Details

#peerObject



81
82
83
# File 'lib/ruby_mvc/views/view.rb', line 81

def peer
  @widget.peer
end

#signal_connect(signal, &b) ⇒ Object

This method is required to ensure that concrete views appropriately manage signal registration



98
99
100
101
102
103
104
105
106
# File 'lib/ruby_mvc/views/view.rb', line 98

def signal_connect(signal, &b)
  puts "Widget class: #{@widget.class}"
  if @widget.class.valid_signal? signal
    @widget.signal_connect(signal, &b)
  else
   puts "super"
    super
  end
end

#signal_disconnect(signal, &b) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/ruby_mvc/views/view.rb', line 108

def signal_disconnect(signal, &b)
  if @widget.class.valid_signal? signal
    @widget.signal_connect(signal, &b)
  else
    super
  end
end