Class: Glimmer::FX::ControlProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/glimmer/fx/control_proxy.rb,
lib/glimmer/fx/control_proxy/app_proxy.rb,
lib/glimmer/fx/control_proxy/main_window_proxy.rb

Overview

Proxy for Fox control objects

Follows the Proxy Design Pattern

Direct Known Subclasses

AppProxy, MainWindowProxy

Defined Under Namespace

Classes: AppProxy, MainWindowProxy

Constant Summary collapse

KEYWORD_ALIASES =
{
#         'msg_box'       => 'message_box',
}

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyword, parent, args, &block) ⇒ ControlProxy

Returns a new instance of ControlProxy.



140
141
142
143
144
145
146
147
# File 'lib/glimmer/fx/control_proxy.rb', line 140

def initialize(keyword, parent, args, &block)
  @keyword = keyword
  @parent_proxy = parent
  @args = args
  @block = block
  build_control
  post_add_content if @block.nil?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



181
182
183
184
185
186
187
188
189
# File 'lib/glimmer/fx/control_proxy.rb', line 181

def method_missing(method_name, *args, &block)
  if @fx.respond_to?("#{method_name}=", true) && !args.empty?
    send_to_fx("#{method_name}=", *args, &block)
  elsif @fx.respond_to?(method_name, true)
    send_to_fx(method_name, *args, &block)
  else
    super
  end
end

Class Attribute Details

.app_proxyObject

Returns the value of attribute app_proxy.



67
68
69
# File 'lib/glimmer/fx/control_proxy.rb', line 67

def app_proxy
  @app_proxy
end

Instance Attribute Details

#argsObject (readonly)

fx returns the contained Fox object



137
138
139
# File 'lib/glimmer/fx/control_proxy.rb', line 137

def args
  @args
end

#blockObject (readonly)

fx returns the contained Fox object



137
138
139
# File 'lib/glimmer/fx/control_proxy.rb', line 137

def block
  @block
end

#content_addedObject (readonly) Also known as: content_added?

fx returns the contained Fox object



137
138
139
# File 'lib/glimmer/fx/control_proxy.rb', line 137

def content_added
  @content_added
end

#fxObject (readonly)

fx returns the contained Fox object



137
138
139
# File 'lib/glimmer/fx/control_proxy.rb', line 137

def fx
  @fx
end

#keywordObject (readonly)

fx returns the contained Fox object



137
138
139
# File 'lib/glimmer/fx/control_proxy.rb', line 137

def keyword
  @keyword
end

#parent_proxyObject (readonly)

fx returns the contained Fox object



137
138
139
# File 'lib/glimmer/fx/control_proxy.rb', line 137

def parent_proxy
  @parent_proxy
end

Class Method Details

.constant_symbol(keyword) ⇒ Object



85
86
87
# File 'lib/glimmer/fx/control_proxy.rb', line 85

def constant_symbol(keyword)
  "#{keyword.camelcase(:upper)}Proxy".to_sym
end

.control_proxy_class(keyword) ⇒ Object



81
82
83
# File 'lib/glimmer/fx/control_proxy.rb', line 81

def control_proxy_class(keyword)
  descendant_keyword_constant_map[keyword] || ControlProxy
end

.create(keyword, parent, args, &block) ⇒ Object



74
75
76
77
78
79
# File 'lib/glimmer/fx/control_proxy.rb', line 74

def create(keyword, parent, args, &block)
  return app_proxy if keyword == 'app' && app_proxy
  control_proxy_class(keyword).new(keyword, parent, args, &block).tap do |instance|
    self.app_proxy = instance if keyword == 'app'
  end
end

.descendant_keyword_constant_mapObject



101
102
103
# File 'lib/glimmer/fx/control_proxy.rb', line 101

def descendant_keyword_constant_map
  @descendant_keyword_constant_map ||= add_aliases_to_keyword_constant_map(map_descendant_keyword_constants_for(self))
end

.exists?(keyword) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
72
# File 'lib/glimmer/fx/control_proxy.rb', line 69

def exists?(keyword)
  ::Fox.const_get(fx_constant_symbol(keyword)) ||
    control_proxy_class(keyword)
end

.fx_class(keyword) ⇒ Object



93
94
95
# File 'lib/glimmer/fx/control_proxy.rb', line 93

def fx_class(keyword)
  ::Fox.const_get(fx_constant_symbol(keyword))
end

.fx_constant_symbol(keyword) ⇒ Object



89
90
91
# File 'lib/glimmer/fx/control_proxy.rb', line 89

def fx_constant_symbol(keyword)
  "FX#{keyword.camelcase(:upper)}".to_sym
end

.keyword(constant_symbol) ⇒ Object



97
98
99
# File 'lib/glimmer/fx/control_proxy.rb', line 97

def keyword(constant_symbol)
  constant_symbol.to_s.underscore.sub(/_proxy$/, '')
end

.map_descendant_keyword_constants_for(klass, accumulator: {}) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/glimmer/fx/control_proxy.rb', line 110

def map_descendant_keyword_constants_for(klass, accumulator: {})
  klass.constants.map do |constant_symbol|
    [constant_symbol, klass.const_get(constant_symbol)]
  end.select do |constant_symbol, constant|
    constant.is_a?(Module) && !accumulator.values.include?(constant)
  end.each do |constant_symbol, constant|
    accumulator[keyword(constant_symbol)] = constant
    map_descendant_keyword_constants_for(constant, accumulator: accumulator)
  end
  accumulator
end

.reset_descendant_keyword_constant_mapObject



105
106
107
108
# File 'lib/glimmer/fx/control_proxy.rb', line 105

def reset_descendant_keyword_constant_map
  @descendant_keyword_constant_map = nil
  descendant_keyword_constant_map
end

Instance Method Details

#childrenObject



162
163
164
# File 'lib/glimmer/fx/control_proxy.rb', line 162

def children
  @children ||= []
end

#content(&block) ⇒ Object



195
196
197
# File 'lib/glimmer/fx/control_proxy.rb', line 195

def content(&block)
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::FX::ControlExpression.new, @keyword, &block)
end

#post_add_contentObject

Subclasses may override to perform post add_content work (normally must call super)



150
151
152
153
154
155
# File 'lib/glimmer/fx/control_proxy.rb', line 150

def post_add_content
  unless @content_added
    @parent_proxy&.post_initialize_child(self)
    @content_added = true
  end
end

#post_initialize_child(child, add_child: true) ⇒ Object

Subclasses may override to perform post initialization work on an added child (normally must also call super)



158
159
160
# File 'lib/glimmer/fx/control_proxy.rb', line 158

def post_initialize_child(child, add_child: true)
  children << child if add_child
end

#respond_to?(method_name, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


172
173
174
175
# File 'lib/glimmer/fx/control_proxy.rb', line 172

def respond_to?(method_name, *args, &block)
  respond_to_fx?(method_name, *args, &block) ||
    super(method_name, true)
end

#respond_to_fx?(method_name, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/glimmer/fx/control_proxy.rb', line 177

def respond_to_fx?(method_name, *args, &block)
  @fx.respond_to?(method_name, true) || @fx.respond_to?("#{method_name}=", true)
end

#send_to_fx(method_name, *args, &block) ⇒ Object



191
192
193
# File 'lib/glimmer/fx/control_proxy.rb', line 191

def send_to_fx(method_name, *args, &block)
  @fx.send(method_name, *args, &block)
end

#window_proxyObject



166
167
168
169
170
# File 'lib/glimmer/fx/control_proxy.rb', line 166

def window_proxy
  found_proxy = self
  found_proxy = found_proxy.parent_proxy until found_proxy.nil? || found_proxy.is_a?(WindowProxy)
  found_proxy
end