Module: Her::Model::Relationships
- Extended by:
- ActiveSupport::Concern
- Included in:
- Her::Model
- Defined in:
- lib/her/model/relationships.rb
Overview
This module adds relationships to models
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#get_relationship(relationship_name) ⇒ Object
Returns the resource/collection corresponding to the relationship_name relationship.
-
#has_relationship?(relationship_name) ⇒ Boolean
Returns true if the model has a relationship_name relationship, false otherwise.
Instance Method Details
#get_relationship(relationship_name) ⇒ Object
Returns the resource/collection corresponding to the relationship_name relationship.
14 15 16 |
# File 'lib/her/model/relationships.rb', line 14 def get_relationship(relationship_name) send(relationship_name) if has_relationship?(relationship_name) end |
#has_relationship?(relationship_name) ⇒ Boolean
Returns true if the model has a relationship_name relationship, false otherwise.
8 9 10 11 |
# File 'lib/her/model/relationships.rb', line 8 def has_relationship?(relationship_name) relationships = self.class.relationships.values.flatten.map { |r| r[:name] } relationships.include?(relationship_name) end |