Class: Glimmer::FX::ControlProxy
- Inherits:
-
Object
- Object
- Glimmer::FX::ControlProxy
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
Defined Under Namespace
Classes: AppProxy, MainWindowProxy
Constant Summary
collapse
- KEYWORD_ALIASES =
{
}
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#children ⇒ Object
-
#content(&block) ⇒ Object
-
#initialize(keyword, parent, args, &block) ⇒ ControlProxy
constructor
A new instance of ControlProxy.
-
#method_missing(method_name, *args, &block) ⇒ Object
-
#post_add_content ⇒ Object
Subclasses may override to perform post add_content work (normally must call super).
-
#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).
-
#respond_to?(method_name, *args, &block) ⇒ Boolean
-
#respond_to_fx?(method_name, *args, &block) ⇒ Boolean
-
#send_to_fx(method_name, *args, &block) ⇒ Object
-
#window_proxy ⇒ Object
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_proxy ⇒ Object
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
#args ⇒ Object
fx returns the contained Fox object
137
138
139
|
# File 'lib/glimmer/fx/control_proxy.rb', line 137
def args
@args
end
|
#block ⇒ Object
fx returns the contained Fox object
137
138
139
|
# File 'lib/glimmer/fx/control_proxy.rb', line 137
def block
@block
end
|
#content_added ⇒ Object
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
|
#fx ⇒ Object
fx returns the contained Fox object
137
138
139
|
# File 'lib/glimmer/fx/control_proxy.rb', line 137
def fx
@fx
end
|
#keyword ⇒ Object
fx returns the contained Fox object
137
138
139
|
# File 'lib/glimmer/fx/control_proxy.rb', line 137
def keyword
@keyword
end
|
#parent_proxy ⇒ Object
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_map ⇒ Object
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
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_map ⇒ Object
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
#children ⇒ Object
162
163
164
|
# File 'lib/glimmer/fx/control_proxy.rb', line 162
def children
@children ||= []
end
|
#content(&block) ⇒ Object
#post_add_content ⇒ Object
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
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
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_proxy ⇒ Object
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
|