module HasMeta::DynamicMethods
Public Class Methods
included(base)
click to toggle source
# File lib/has_meta/dynamic_methods.rb, line 3 def self.included base base.extend ClassMethods end
Public Instance Methods
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/has_meta/dynamic_methods.rb, line 17 def method_missing method, *args, &block attribute = self.meta_attributes.select { |x| method.match /^#{x}(_id)?=?$/ }.pop if attribute object = self.class.find_object_from attribute if method =~ /=$/ # setter object ? meta_set!(:"#{attribute}_id", args.first.try(:id) || args.first) : meta_set!(attribute, args.first) else # getter if object method =~ /_id$/ ? meta_get(:"#{attribute}_id") : object.find_by_id(meta_get(:"#{attribute}_id")) else meta_get(attribute) end end else super end end
respond_to?(method, include_private=false)
click to toggle source
TODO: refactor this
Calls superclass method
# File lib/has_meta/dynamic_methods.rb, line 8 def respond_to? method, include_private=false attribute = self.meta_attributes.select { |x| method.match /^#{x}(_id)?=?$/ }.pop if attribute self.class.find_object_from(attribute) ? true : !method.match(/^#{attribute}=?$/).nil? else super end end