class Glimmer::FX::ControlProxy
Proxy for Fox control objects
Follows the Proxy Design Pattern
Constants
- KEYWORD_ALIASES
Attributes
app_proxy[RW]
args[R]
fx returns the contained Fox object
block[R]
fx returns the contained Fox object
content_added[R]
fx returns the contained Fox object
content_added?[R]
fx returns the contained Fox object
fx[R]
fx returns the contained Fox object
keyword[R]
fx returns the contained Fox object
parent_proxy[R]
fx returns the contained Fox object
Public Class Methods
constant_symbol(keyword)
click to toggle source
# File lib/glimmer/fx/control_proxy.rb, line 85 def constant_symbol(keyword) "#{keyword.camelcase(:upper)}Proxy".to_sym end
control_proxy_class(keyword)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/glimmer/fx/control_proxy.rb, line 89 def fx_constant_symbol(keyword) "FX#{keyword.camelcase(:upper)}".to_sym end
keyword(constant_symbol)
click to toggle source
# 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: {})
click to toggle source
# 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
new(keyword, parent, args, &block)
click to toggle source
# 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
reset_descendant_keyword_constant_map()
click to toggle source
# 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
Private Class Methods
add_aliases_to_keyword_constant_map(keyword_constant_map)
click to toggle source
# File lib/glimmer/fx/control_proxy.rb, line 124 def add_aliases_to_keyword_constant_map(keyword_constant_map) KEYWORD_ALIASES.each do |keyword, alias_keyword| keyword_constant_map[alias_keyword] = keyword_constant_map[keyword] end keyword_constant_map end
Public Instance Methods
children()
click to toggle source
# File lib/glimmer/fx/control_proxy.rb, line 162 def children @children ||= [] end
content(&block)
click to toggle source
# 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
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# 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
post_add_content()
click to toggle source
Subclasses may override to perform post add_content work (normally must call super)
# 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)
click to toggle source
Subclasses may override to perform post initialization work on an added child (normally must also call super)
# 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)
click to toggle source
Calls superclass method
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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
Private Instance Methods
build_control()
click to toggle source
# File lib/glimmer/fx/control_proxy.rb, line 201 def build_control new_args = [@parent_proxy] + @args new_args = new_args.compact new_args = normalize_args(new_args) @fx = ControlProxy.fx_class(@keyword).new(*new_args) end
normalize_args(args)
click to toggle source
# File lib/glimmer/fx/control_proxy.rb, line 208 def normalize_args(args) result_args = args.map do |arg| arg.is_a?(ControlProxy) ? arg.fx : arg end kwargs = result_args.last.is_a?(Hash) ? result_args.pop : {} opts = [kwargs.delete(:opts) || kwargs.delete('opts')].flatten.compact opts_value = opts.map do |opt| ::Fox.const_get(opt.upcase.to_sym) end.reduce(:|) kwargs = kwargs.merge(opts: opts_value) unless opts.empty? kwargs.empty? ? result_args : result_args + [kwargs] end