Class: Flounder::Relation

Inherits:
Object
  • Object
show all
Includes:
Helpers::Entity
Defined in:
lib/flounder/relation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#domainObject

Returns the value of attribute domain.



5
6
7
# File 'lib/flounder/relation.rb', line 5

def domain
  @domain
end

#entity_refObject

Returns the value of attribute entity_ref.



6
7
8
# File 'lib/flounder/relation.rb', line 6

def entity_ref
  @entity_ref
end

#join_conditionsObject

Returns the value of attribute join_conditions.



6
7
8
# File 'lib/flounder/relation.rb', line 6

def join_conditions
  @join_conditions
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/flounder/relation.rb', line 6

def name
  @name
end

#typeObject

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_entityObject



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