Module: JRubyFX::DSL::ClassUtils
- Includes:
- FXImports
- Defined in:
- lib/jrubyfx/dsl.rb
Overview
Contains methods to be defined inside all classes that include JRubyFX
Constant Summary
Constants included from FXImports
FXImports::JFX_CLASS_HIERARCHY
Instance Method Summary collapse
-
#getter_setter(name) ⇒ Object
Define a dual-mode method which acts as both a getter and setter depending on whether it has been supplied an argument or not.
-
#include_add(adder = :get_children) ⇒ Object
call-seq: include_add include_add :child_getter.
-
#include_method_missing(type) ⇒ Object
Adds a method_missing that automatically calls add if the DSL builds it as the given type.
-
#include_rotate ⇒ Object
Adds a function to the class that Adds rotate to transform (manually added ebcause there is a getRotate on Node already. Use get_rotate to get property.
-
#register_type(type, name = nil) ⇒ Object
Register your own type for use in the DSL.
Instance Method Details
#getter_setter(name) ⇒ Object
Define a dual-mode method which acts as both a getter and setter depending on whether it has been supplied an argument or not.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jrubyfx/dsl.rb', line 53 def getter_setter(name) self.class_eval do # FIXME: Is arity of splat the best way to do this? define_method(name) do |*r| if r.length > 0 set_effect *r else get_effect end end end end |
#include_add(adder = :get_children) ⇒ Object
call-seq:
include_add
include_add :child_getter
Include a function to add to child list (optional argument) without need to ask for children include_add include_add :elements
78 79 80 81 82 83 84 |
# File 'lib/jrubyfx/dsl.rb', line 78 def include_add(adder = :get_children) self.class_eval do define_method :add do |value| self.send(adder) << value end end end |
#include_method_missing(type) ⇒ Object
Adds a method_missing that automatically calls add if the DSL builds it as the given type. This will defer to node to construct proper object, but will optionally add paths primary child automatically if it is a PathElement.
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/jrubyfx/dsl.rb', line 104 def include_method_missing(type) self.class_eval do define_method :method_missing do |name, *args, &block| # we must manually call super otherwise it will call super(type) super(name, *args, &block).tap do |obj| add(obj) if obj.kind_of?(type) && !name.to_s.end_with?('!') end end end end |
#include_rotate ⇒ Object
Adds a function to the class that Adds rotate to transform (manually added ebcause there is a getRotate on Node already. Use get_rotate to get property
90 91 92 93 94 95 96 |
# File 'lib/jrubyfx/dsl.rb', line 90 def include_rotate self.class_eval do def rotate(*args) #:nodoc: transforms << build(Rotate, *args) end end end |
#register_type(type, name = nil) ⇒ Object
Register your own type for use in the DSL.
class MyFooWidget < Region
#...
end
#...
register_type(MyFooWidget)
register_type(MyFooWidget, "aliased_name")
Note, this also makes it possible to override existing definitions of built-in components.
43 44 45 46 |
# File 'lib/jrubyfx/dsl.rb', line 43 def register_type(type, name=nil) name = type.name.snake_case unless name JRubyFX::DSL::NAME_TO_CLASSES[name.to_s] = type end |