Skip to content

Instantly share code, notes, and snippets.

@elskwid
Created November 25, 2013 16:34
Show Gist options
  • Save elskwid/7644176 to your computer and use it in GitHub Desktop.
Save elskwid/7644176 to your computer and use it in GitHub Desktop.
Using a module instead of a class with Virtus
module Entity
include Virtus.module
attribute :id, Integer
def persisted?
!id.nil?
end
end
class Loan
include Virtus.model(finalize: false)
include Entity
attribute :lender, "Person"
attribute :thing, "Thing"
attribute :borrower, "Person"
end
class Person
include Virtus.model(finalize: false)
include Entity
attribute :name, String
attribute :email, String
attribute :loans, Array["Loan"]
end
class Thing
include Virtus.model
include Entity
attribute :name, String
attribute :description, String
end
Virtus.finalize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment