Method: Plaza::RestfulModel#method_missing

Defined in:
lib/plaza/models/restful_model.rb

#method_missing(method_name, *args, &block) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/plaza/models/restful_model.rb', line 142

def method_missing(method_name, *args, &block)
  method_name = method_name.to_s
  if self.respond_to?(method_name + '_id')
    obj_id = self.send(method_name + '_id')
    class_name = Plaza::Inflector.classify(method_name)
    klass = (self.class.name.split('::')[0..-2] + [class_name]).reduce(Module, :const_get)
    return klass.find(obj_id)
  else
    raise NoMethodError.new "undefined method '#{method_name}' for #{self.class}"
  end
end