Class: Flounder::Field

Inherits:
Object
  • Object
show all
Includes:
SymbolExtensions
Defined in:
lib/flounder/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fieldArel::Attribute (readonly)

Returns arel attribute that corresponds to this field.

Returns:

  • (Arel::Attribute)

    arel attribute that corresponds to this field



13
14
15
# File 'lib/flounder/field.rb', line 13

def arel_field
  @arel_field
end

#entityEntity (readonly)

Returns entity this field belongs to.

Returns:

  • (Entity)

    entity this field belongs to



10
11
12
# File 'lib/flounder/field.rb', line 10

def entity
  @entity
end

#nameString (readonly)

Returns name of this field.

Returns:

  • (String)

    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_nameString

Returns a fully qualified name (table.field).

Returns:

  • (String)

    fully qualified field name



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

#hashObject



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

def hash
  self.entity.hash ^ self.name.hash
end

#inspectObject 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_fieldObject



30
31
32
# File 'lib/flounder/field.rb', line 30

def to_arel_field
  arel_field
end