Class: Flounder::EntityAlias

Inherits:
Object
  • Object
show all
Defined in:
lib/flounder/entity_alias.rb

Overview

Alias for an Entity, implementing roughly the same interface.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity, plural, singular) ⇒ EntityAlias

Returns a new instance of EntityAlias.



8
9
10
11
12
# File 'lib/flounder/entity_alias.rb', line 8

def initialize entity, plural, singular
  @entity = entity
  @plural = plural
  @singular = singular
end

Instance Attribute Details

#entityObject (readonly)

Entity this alias refers to



15
16
17
# File 'lib/flounder/entity_alias.rb', line 15

def entity
  @entity
end

#pluralObject (readonly) Also known as: name

Plural name of the alias



18
19
20
# File 'lib/flounder/entity_alias.rb', line 18

def plural
  @plural
end

#singularObject (readonly)

Singular name of the alias



21
22
23
# File 'lib/flounder/entity_alias.rb', line 21

def singular
  @singular
end

Instance Method Details

#[](name) ⇒ Object



49
50
51
# File 'lib/flounder/entity_alias.rb', line 49

def [] name
  Field.new(self, name, table[name])
end

#column_namesObject



31
32
33
# File 'lib/flounder/entity_alias.rb', line 31

def column_names
  entity.column_names
end

#fields(*a) ⇒ Object



39
40
41
# File 'lib/flounder/entity_alias.rb', line 39

def fields *a
  a.map { |n| self[n] }
end

#inspectObject Also known as: to_s



43
44
45
# File 'lib/flounder/entity_alias.rb', line 43

def inspect
  "<Flounder/Entity/Alias #{entity.name}(#{entity.table_name}) as (#{plural}, #{singular}))>"
end

#relations(*a) ⇒ Object



35
36
37
# File 'lib/flounder/entity_alias.rb', line 35

def relations *a
  entity.relations *a
end

#tableObject



26
27
28
29
# File 'lib/flounder/entity_alias.rb', line 26

def table
  table = entity.table 
  table.alias(plural)
end