Class: Relationship
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Relationship
- Defined in:
- app/models/relationship.rb
Overview
This class models a relationship between two users.
For example, John is the brother of Sue.
who: John relationship.user1 relationship.who
is: Brother relationship.is relationship.name
of: Sue relationship.user2 relationship.of
Class Method Summary collapse
-
.add(params) ⇒ Object
Adding new relationships:.
Instance Method Summary collapse
-
#is ⇒ Object
John is the brother of Sue.
- #is=(name) ⇒ Object
-
#of ⇒ Object
John is the brother of Sue.
- #of=(user) ⇒ Object
-
#of_by_title ⇒ Object
Access method for the second user being given by his title.
- #of_by_title=(title) ⇒ Object
-
#who ⇒ Object
John is the brother of Sue.
- #who=(user) ⇒ Object
-
#who_by_title ⇒ Object
Access method for the first user being given by his title.
- #who_by_title=(title) ⇒ Object
Methods inherited from ActiveRecord::Base
Class Method Details
.add(params) ⇒ Object
Adding new relationships:
Relationship.add( who: john_user, is: :brother, of: :sue_user )
which is the same as:
Relationship.create( who: john_user, is: :brother, of: :sue_user )
56 57 58 |
# File 'app/models/relationship.rb', line 56 def self.add( params ) self.create( params ) end |
Instance Method Details
#is ⇒ Object
John is the brother of Sue.
------- is: brother
31 32 33 |
# File 'app/models/relationship.rb', line 31 def is self.name end |
#is=(name) ⇒ Object
34 35 36 |
# File 'app/models/relationship.rb', line 34 def is=( name ) self.name = name end |
#of ⇒ Object
John is the brother of Sue.
--- of: Sue
41 42 43 |
# File 'app/models/relationship.rb', line 41 def of self.user2 end |
#of=(user) ⇒ Object
44 45 46 |
# File 'app/models/relationship.rb', line 44 def of=( user ) self.user2 = user end |
#of_by_title ⇒ Object
Access method for the second user being given by his title.
71 72 73 |
# File 'app/models/relationship.rb', line 71 def of_by_title self.of.title if self.of end |
#of_by_title=(title) ⇒ Object
74 75 76 |
# File 'app/models/relationship.rb', line 74 def of_by_title=( title ) self.of = User.find_by_title( title ) end |
#who ⇒ Object
John is the brother of Sue. —- who: John
21 22 23 |
# File 'app/models/relationship.rb', line 21 def who self.user1 end |
#who=(user) ⇒ Object
24 25 26 |
# File 'app/models/relationship.rb', line 24 def who=( user ) self.user1 = user end |
#who_by_title ⇒ Object
Access method for the first user being given by his title.
62 63 64 |
# File 'app/models/relationship.rb', line 62 def who_by_title self.who.title if self.who end |
#who_by_title=(title) ⇒ Object
65 66 67 |
# File 'app/models/relationship.rb', line 65 def who_by_title=( title ) self.who = User.find_by_title( title ) end |