Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define_attribute_methods overriding already defined methods #146

Closed
iamprich opened this issue Mar 26, 2019 · 0 comments
Closed

define_attribute_methods overriding already defined methods #146

iamprich opened this issue Mar 26, 2019 · 0 comments
Labels
enhancement New feature or request ready-to-release Internal Use Only: Has been fixed, specs passing and pushed to edge branch
Milestone

Comments

@iamprich
Copy link

iamprich commented Mar 26, 2019

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
@catmando catmando added the enhancement New feature or request label Apr 18, 2019
@catmando catmando modified the milestones: alpha1.4, alpha1.5 Apr 18, 2019
@catmando catmando added the ready-to-release Internal Use Only: Has been fixed, specs passing and pushed to edge branch label Apr 23, 2019
catmando added a commit that referenced this issue May 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready-to-release Internal Use Only: Has been fixed, specs passing and pushed to edge branch
Projects
None yet
Development

No branches or pull requests

2 participants