class Vizkit::CallbackSpec
Holds all the information about a plugin callback. A callback is a method or code block which is able to handle a specific object type for example for displaying it.
Attributes
argument[R]
@return [String] name of the argument type which can be handled by the code block
callback[R]
@return [CallbackAdapter] the callback adapter
Public Class Methods
new(value,callback_type=nil,default=false,method_name = nil,&block)
click to toggle source
Creates a new object of CallbackSpec
@param [Object] value the object which can be handled by the callback @param [callback_type] callback_type the type of the callback :display,:control @param [false,true] default @param [Symbol] method_name name of the method that will be invoked on the plugin
will be ignored if a block is given
@example
CallbackSpec.new(Float,:display,true) do |obj| puts obj end
# File lib/vizkit/plugin.rb, line 338 def initialize(value,callback_type=nil,default=false,method_name = nil,&block) @callback =if !block if method_name.respond_to?(:to_sym) MethodNameAdapter.new(method_name) else NoCallbackAdapter.new end elsif block.kind_of?(Method) UnboundBlockAdapter.new(block) else BlockAdapter.new(block) end @argument = PluginHelper.normalize_obj(value,false).first callback_type(callback_type) default(default) end
Public Instance Methods
call(*args)
click to toggle source
# File lib/vizkit/plugin.rb, line 355 def call(*args) @callback.call(*args) end
match?(*pattern)
click to toggle source
# File lib/vizkit/plugin.rb, line 359 def match?(*pattern) return true if pattern.empty? pattern = pattern.first pattern, options = Kernel.filter_options(pattern,:callback_type => nil,:argument => nil,:default => nil,:exact => nil) raise ArgumentError, "Wrong options #{options}" unless options.empty? if pattern[:callback_type] return if pattern[:callback_type] != @callback_type end if pattern[:default] !=nil return if pattern[:default] != @default end if pattern[:argument] # match against all available names for the argument names = PluginHelper.normalize_obj(pattern[:argument],!pattern[:exact]) return if ! names.include?(@argument) end return true end
pretty_print(pp)
click to toggle source
# File lib/vizkit/plugin.rb, line 379 def pretty_print(pp) pp.text "argument: #{argument}" pp.nest(2) do pp.breakable pp.text "callback method: #{callback.block_name}" pp.breakable pp.text "type: #{callback_type}" pp.breakable pp.text "default: #{default ? true : false}" end pp.breakable end