Guest User

Untitled

a guest
Jun 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. # This module hides the implementation details that
  2. # relationships are stored in a hash, which is bound to change anyway.
  3. # Also, it allows to *fail fast* when trying to access a relationship
  4. # that is not defined in a model (via the relationship! method)
  5.  
  6. module RelationshipAccess
  7.  
  8. def relationship(name, repository_name = default_repository_name)
  9. relationships(repository_name)[name]
  10. end
  11.  
  12. def relationship!(name, repository_name = default_repository_name)
  13. unless relationship = relationship(name, repository_name)
  14. raise(ArgumentError, "No relationship #{name.inspect} for #{self.name} in #{repository_name}")
  15. end
  16. relationship
  17. end
  18.  
  19. end
Add Comment
Please, Sign In to add comment