class Flounder::Relation

Attributes

domain[RW]
entity_ref[RW]
join_conditions[RW]
name[RW]
type[RW]

Public Class Methods

new(domain, type, name, entity_ref, join_conditions) click to toggle source
# 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

Public Instance Methods

apply(query) click to toggle source
# File lib/flounder/relation.rb, line 27
def apply query
  query.
    join(linked_entity).
    on(join_conditions)
end
linked_entity() click to toggle source
# 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

Private Instance Methods

has_entity?(sym) click to toggle source

Checks if a given symbol can be an entity after resolution.

# File lib/flounder/relation.rb, line 36
def has_entity? sym
  domain.has_entity?(sym)
end
resolve_entity(sym) click to toggle source

Resolves an entity through the domain.

# File lib/flounder/relation.rb, line 42
def resolve_entity sym
  domain[sym]
end