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

combine Virtus classes #344

Open
abaird opened this issue Sep 30, 2015 · 1 comment
Open

combine Virtus classes #344

abaird opened this issue Sep 30, 2015 · 1 comment

Comments

@abaird
Copy link

abaird commented Sep 30, 2015

I want to do something like this:

  class UserModel
    include Virtus.model
    attribute(:first, String, default:Faker::Name.first_name )
    attribute(:last, String, default: Faker::Name.last_name )
    attribute(:email, String, default:lambda{|user, attribute| "#{user.first}.#{user.last}@devmail.company.com"} )
  end

  class OwnerModel
    include UserModel
    attribute(:email, String, default:lambda{|owner, attribute| "#{owner.first}.#{owner.last}@owner.company.com" })
    attribute(:address, String, default:'5210 Paseo de Pablo' )
  end

However, when I do that I get an error saying: wrong argument type Class (expected Module) (TypeError). I believe this is because Virtus wants me to combine things as Modules. However, if I change both of these above to Modules and then include them in my own class, I no longer get methods like attributes on my own class.

Is there a supported way to do this kind of composing?

@neumachen
Copy link

That would defeat of the coercion that virtus does. But if you must, you can always pass coerce: false and see if that would work.

And you can't include the your first class because it's a class and not a module.

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