Skip to content

define_attribute_methods overriding already defined methods #146

Closed

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

Activity

  1. modified the milestones: alpha1.4, alpha1.5 on Apr 18, 2019
  2. added a commit that references this issue on Apr 23, 2019
    d68eeb7
  3. added
    ready-to-releaseInternal Use Only: Has been fixed, specs passing and pushed to edge branch
    on Apr 23, 2019
  4. added a commit that references this issue on May 30, 2019
    aad5bed
  5. added 2 commits that reference this issue on Sep 2, 2026
    e3c72ff
    4b9a145
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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