Class: Flounder::EntityAlias
- Inherits:
-
Object
- Object
- Flounder::EntityAlias
- Defined in:
- lib/flounder/entity_alias.rb
Overview
Alias for an Entity, implementing roughly the same interface.
Instance Attribute Summary collapse
-
#entity ⇒ Object
readonly
Entity this alias refers to.
-
#plural ⇒ Object
(also: #name)
readonly
Plural name of the alias.
-
#singular ⇒ Object
readonly
Singular name of the alias.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #column_names ⇒ Object
- #fields(*a) ⇒ Object
-
#initialize(entity, plural, singular) ⇒ EntityAlias
constructor
A new instance of EntityAlias.
- #inspect ⇒ Object (also: #to_s)
- #relations(*a) ⇒ Object
- #table ⇒ Object
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
#entity ⇒ Object (readonly)
Entity this alias refers to
15 16 17 |
# File 'lib/flounder/entity_alias.rb', line 15 def entity @entity end |
#plural ⇒ Object (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 |
#singular ⇒ Object (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_names ⇒ Object
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 |
#inspect ⇒ Object 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 |
#table ⇒ Object
26 27 28 29 |
# File 'lib/flounder/entity_alias.rb', line 26 def table table = entity.table table.alias(plural) end |