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

Inheritance support #9

Open
alexsotocx opened this issue Apr 18, 2017 · 1 comment
Open

Inheritance support #9

alexsotocx opened this issue Apr 18, 2017 · 1 comment

Comments

@alexsotocx
Copy link

Hello I'm facing the issue with inheritance, attributes are not being copied.

Ruby 2.3.1
model_attribute (3.1.1)

require 'model_attribute'
class Person
  extend ModelAttribute
  attribute :name,       :string
  attribute :last_name,       :string

  def initialize(attributes = {})
    set_attributes(attributes)
  end
end


class User < Person

  def initialize(attributes = {})
    super(attributes)
    self.name = "This is an error"
  end
end


User.attributes # nil
User.new({})

# /Users/soto/.rvm/gems/ruby-2.3.1/gems/model_attribute-3.1.1/lib/model_attribute.rb:87:in `read_attribute': undefined method `include?' for nil:NilClass (NoMethodError)
# 	from /Users/soto/.rvm/gems/ruby-2.3.1/gems/model_attribute-3.1.1/lib/model_attribute.rb:66:in `write_attribute'
# 	from /Users/soto/.rvm/gems/ruby-2.3.1/gems/model_attribute-3.1.1/lib/model_attribute.rb:27:in `name='
# 	from script.rb:17:in `initialize'
# 	from script.rb:22:in `new'
# 	from script.rb:22:in `<main>'
@dwaller
Copy link
Contributor

dwaller commented Apr 19, 2017

Hi @alexsotocx, thanks for raising the issue.

I vaguely recall running into this issue a long time ago (two years ago) and setting out to fix it. I don't fully recall why I stopped, but I think I found that it was harder than I had thought to define what the desired behaviour actually was! If you would like to have a go, feel free to create a PR that defines and implements some sensible behaviour (don't forget rigorous specs!). You might want to start with my aborted attempt: 1f42a27.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants