Skip to content

define_attribute_methods overriding already defined methods #146

Closed
@iamprich

Description

@iamprich

define_attribute_methods should only define a method if the method is not already defined.

def define_attribute_methods
  columns_hash.each do |name, column_hash|
    next if name == primary_key
    define_method(name) { @backing_record.get_attr_value(name, nil) } unless method_defined?(name)
    define_method("#{name}!") { @backing_record.get_attr_value(name, true) } unless method_defined?("#{name}!")
    define_method("#{name}=") { |val| @backing_record.set_attr_value(name, val) } unless method_defined?("#{name}=")
    define_method("#{name}_changed?") { @backing_record.changed?(name) } unless method_defined?("#{name}_changed?")
    define_method("#{name}?") { @backing_record.get_attr_value(name, nil).present? } unless method_defined?("#{name}?")
  end
  self.inheritance_column = nil if inheritance_column && !columns_hash.key?(inheritance_column)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestready-to-releaseInternal Use Only: Has been fixed, specs passing and pushed to edge branch

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions