module Archivist::ArchiveMethods

Public Class Methods

included(base) click to toggle source
# File lib/archivist/archive.rb, line 3
def self.included(base)
  base.class_eval do
    extend ArchiveClassMethods
    protected :get_klass,:get_klass_name,:get_klass_instance_methods,:build_proxy_method
  end
end

Public Instance Methods

build_proxy_method(method_name) click to toggle source
# File lib/archivist/archive.rb, line 45
def build_proxy_method(method_name)
  class_eval <<-EOF
    def #{method_name}(*args,&block)
      instance = #{get_klass_name}.new(self.attributes.reject{|k,v| !#{get_klass.new.attribute_names.inspect}.include?(k.to_s)})
      instance.#{method_name}(*args,&block)
    end
  EOF
end
get_klass() click to toggle source
# File lib/archivist/archive.rb, line 27
def get_klass
  @klass ||= Kernel.const_get(get_klass_name)
end
get_klass_instance_methods() click to toggle source
# File lib/archivist/archive.rb, line 36
def get_klass_instance_methods
  @klass_instance_methods ||= get_klass.instance_methods(false)
end
get_klass_name() click to toggle source
# File lib/archivist/archive.rb, line 31
def get_klass_name
  @klass_name ||= self.class.to_s.split("::").first
end
method_missing(method,*args,&block) click to toggle source
Calls superclass method
# File lib/archivist/archive.rb, line 10
def method_missing(method,*args,&block)
  if get_klass_instance_methods.include?(method)
    build_proxy_method(method.to_s)
    self.method(method).call(*args,&block)
  else
    super(method,*args,&block)
  end
end
respond_to?(method,include_private=false) click to toggle source
Calls superclass method
# File lib/archivist/archive.rb, line 19
def respond_to?(method,include_private=false)
  if get_klass_instance_methods.include?(method)
    return true
  else
    super(method,include_private)
  end
end