class TavernaPlayer::ModelProxy
Attributes
class_name[R]
Public Class Methods
new(class_name, method_names = [])
click to toggle source
# File lib/taverna_player/model_proxy.rb, line 17 def initialize(class_name, method_names = []) @class_name = root_name(class_name.to_s) method_names.each do |name| add_method(name.to_sym) end end
Public Instance Methods
class_const()
click to toggle source
# File lib/taverna_player/model_proxy.rb, line 25 def class_const @const ||= begin Object.const_get(@class_name) rescue NameError @class_name.constantize end end
Private Instance Methods
add_method(name)
click to toggle source
# File lib/taverna_player/model_proxy.rb, line 39 def add_method(name) setter = "#{name}_method_name=".to_sym mapper = name (class << self; self; end).instance_eval do # Define the method to use the mapped method on the object. define_method name do |object| mapper.nil? ? nil : object.send(mapper) end # Define the method used to set the mapped method's name. define_method setter do |method_name| mapper = method_name.nil? ? nil : method_name.to_sym end end end
root_name(name)
click to toggle source
# File lib/taverna_player/model_proxy.rb, line 35 def root_name(name) name.start_with?("::") ? name : "::#{name}" end