Module: Processing::Proxy
- Defined in:
- lib/ruby-processing/app.rb
Overview
This module will get automatically mixed in to any inner class of a Processing::App, in order to mimic Java’s inner classes, which have unfettered access to the methods defined in the surrounding class.
Class Method Summary collapse
-
.desired_method_names ⇒ Object
Generate the list of method names that we’d like to proxy for inner classes.
-
.included(inner_class) ⇒ Object
Don’t do all of the work unless we have an inner class that needs it.
-
.proxy_constants ⇒ Object
Proxy the sketch’s constants on to the inner classes.
-
.proxy_methods ⇒ Object
Proxy methods through to the sketch.
Class Method Details
.desired_method_names ⇒ Object
Generate the list of method names that we’d like to proxy for inner classes. Nothing camelCased, nothing __internal__, just the Processing API.
488 489 490 491 492 493 494 |
# File 'lib/ruby-processing/app.rb', line 488 def self.desired_method_names bad_method = /__/ # Internal JRuby methods. unwanted = PApplet.superclass.instance_methods + Object.instance_methods unwanted -= ['width', 'height', 'cursor'] methods = Processing::App.public_instance_methods methods.reject {|m| unwanted.include?(m) || bad_method.match(m) } end |
.included(inner_class) ⇒ Object
Don’t do all of the work unless we have an inner class that needs it.
523 524 525 526 527 528 |
# File 'lib/ruby-processing/app.rb', line 523 def self.included(inner_class) return if @already_defined proxy_methods proxy_constants @already_defined = true end |
.proxy_constants ⇒ Object
Proxy the sketch’s constants on to the inner classes.
515 516 517 518 519 |
# File 'lib/ruby-processing/app.rb', line 515 def self.proxy_constants Processing::App.constants.each do |name| Processing::Proxy.const_set(name, Processing::App.const_get(name)) end end |
.proxy_methods ⇒ Object
Proxy methods through to the sketch.
498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/ruby-processing/app.rb', line 498 def self.proxy_methods code = desired_method_names.inject('') do |code, method| code << <<-EOS def #{method}(*args, &block) # def rect(*args, &block) if block_given? # if block_given? $app.send :'#{method}', *args, &block # $app.send(:rect, *args, &block) else # else $app.#{method} *args # $app.rect *args end # end end # end EOS end module_eval(code, "Processing::Proxy", 1) end |