module ActiveFedora::AttributeMethods::ClassMethods
Public Instance Methods
dangerous_class_method?(method_name)
click to toggle source
A class method is ‘dangerous’ if it is already (re)defined by Active Record, but not by any ancestors. (So ‘puts’ is not dangerous but ‘new’ is.)
# File lib/active_fedora/attribute_methods.rb, line 83 def dangerous_class_method?(method_name) RESTRICTED_CLASS_METHODS.include?(method_name.to_s) || class_method_defined_within?(method_name, Base) end
instance_method_already_implemented?(method_name)
click to toggle source
Raises an ActiveFedora::DangerousAttributeError
exception when an Active Record method is defined in the model, otherwise false
.
class Person < ActiveRecord::Base def save 'already defined by Active Fedora' end end Person.instance_method_already_implemented?(:save) # => ActiveFedora::DangerousAttributeError: save is defined by Active Record. Check to make sure that you don't have an attribute or method with the same name. Person.instance_method_already_implemented?(:name) # => false
Calls superclass method
# File lib/active_fedora/attribute_methods.rb, line 49 def instance_method_already_implemented?(method_name) raise DangerousAttributeError, "#{method_name} is defined by Active Fedora. Check to make sure that you don't have an attribute or method with the same name." if dangerous_attribute_method?(method_name) if superclass == Base super else # If ThisClass < ... < SomeSuperClass < ... < Base and SomeSuperClass # defines its own attribute method, then we don't want to overwrite that. defined = method_defined_within?(method_name, superclass, Base) && !superclass.instance_method(method_name).owner.is_a?(GeneratedAttributeMethods) defined || super end end
Private Instance Methods
generate_method(name)
click to toggle source
@param name [Symbol] name of the attribute to generate
# File lib/active_fedora/attribute_methods.rb, line 102 def generate_method(name) generated_attribute_methods.synchronize do define_attribute_methods name end end