Created
          November 25, 2013 16:34 
        
      - 
      
- 
        Save elskwid/7644176 to your computer and use it in GitHub Desktop. 
    Using a module instead of a class with Virtus
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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