Class: Flounder::Field
- Inherits:
-
Object
- Object
- Flounder::Field
- Includes:
- SymbolExtensions
- Defined in:
- lib/flounder/field.rb
Instance Attribute Summary collapse
-
#arel_field ⇒ Arel::Attribute
readonly
Arel attribute that corresponds to this field.
-
#entity ⇒ Entity
readonly
Entity this field belongs to.
-
#name ⇒ String
readonly
Name of this field.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Allow comparison and inclusion in hashes.
-
#fully_qualified_name ⇒ String
Returns a fully qualified name (table.field).
- #hash ⇒ Object
-
#initialize(entity, name, arel_field) ⇒ Field
constructor
A new instance of Field.
-
#inspect ⇒ Object
(also: #to_s)
Allow printing for debug purposes.
- #to_arel_field ⇒ Object
Constructor Details
#initialize(entity, name, arel_field) ⇒ Field
Returns a new instance of Field.
3 4 5 6 7 |
# File 'lib/flounder/field.rb', line 3 def initialize entity, name, arel_field @entity = entity @name = name @arel_field = arel_field end |
Instance Attribute Details
#arel_field ⇒ Arel::Attribute (readonly)
Returns arel attribute that corresponds to this field.
13 14 15 |
# File 'lib/flounder/field.rb', line 13 def arel_field @arel_field end |
#entity ⇒ Entity (readonly)
Returns entity this field belongs to.
10 11 12 |
# File 'lib/flounder/field.rb', line 10 def entity @entity end |
#name ⇒ String (readonly)
Returns name of this field.
16 17 18 |
# File 'lib/flounder/field.rb', line 16 def name @name end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Allow comparison and inclusion in hashes.
35 36 37 |
# File 'lib/flounder/field.rb', line 35 def == other self.entity == other.entity && self.name == other.name end |
#fully_qualified_name ⇒ String
Returns a fully qualified name (table.field).
22 23 24 25 26 27 28 |
# File 'lib/flounder/field.rb', line 22 def fully_qualified_name entity.with_connection do |conn| table = conn.quote_table_name(entity.table_name) column = conn.quote_column_name(name) "#{table}.#{column}" end end |
#hash ⇒ Object
39 40 41 |
# File 'lib/flounder/field.rb', line 39 def hash self.entity.hash ^ self.name.hash end |
#inspect ⇒ Object Also known as: to_s
Allow printing for debug purposes
44 45 46 |
# File 'lib/flounder/field.rb', line 44 def inspect "<Flounder/Field #{entity} #{name}>" end |
#to_arel_field ⇒ Object
30 31 32 |
# File 'lib/flounder/field.rb', line 30 def to_arel_field arel_field end |