Class: Flounder::Relation
- Inherits:
-
Object
- Object
- Flounder::Relation
- Includes:
- Helpers::Entity
- Defined in:
- lib/flounder/relation.rb
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#entity_ref ⇒ Object
Returns the value of attribute entity_ref.
-
#join_conditions ⇒ Object
Returns the value of attribute join_conditions.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #apply(query) ⇒ Object
-
#initialize(domain, type, name, entity_ref, join_conditions) ⇒ Relation
constructor
A new instance of Relation.
- #linked_entity ⇒ Object
Methods included from Helpers::Entity
#convert_to_entity, #entity_like?
Constructor Details
#initialize(domain, type, name, entity_ref, join_conditions) ⇒ Relation
Returns a new instance of Relation.
8 9 10 11 |
# File 'lib/flounder/relation.rb', line 8 def initialize domain, type, name, entity_ref, join_conditions @domain, @type, @name, @entity_ref, @join_conditions = domain, type, name, entity_ref, join_conditions end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
5 6 7 |
# File 'lib/flounder/relation.rb', line 5 def domain @domain end |
#entity_ref ⇒ Object
Returns the value of attribute entity_ref.
6 7 8 |
# File 'lib/flounder/relation.rb', line 6 def entity_ref @entity_ref end |
#join_conditions ⇒ Object
Returns the value of attribute join_conditions.
6 7 8 |
# File 'lib/flounder/relation.rb', line 6 def join_conditions @join_conditions end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/flounder/relation.rb', line 6 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/flounder/relation.rb', line 5 def type @type end |
Instance Method Details
#apply(query) ⇒ Object
27 28 29 30 31 |
# File 'lib/flounder/relation.rb', line 27 def apply query query. join(linked_entity). on(join_conditions) end |
#linked_entity ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/flounder/relation.rb', line 13 def linked_entity @linked_entity ||= begin entity = convert_to_entity(entity_ref) if name != entity_ref # TODO maybe using name for both singular and plural is not a good # idea. Maybe it is. entity = entity.as(name, name) end entity end end |