Class: PgSerializable::Nodes::Association

Inherits:
Base
  • Object
show all
Defined in:
lib/pg_serializable/nodes/association.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_s

Constructor Details

#initialize(klass, name, type, label: nil, trait: :default) ⇒ Association

Returns a new instance of Association.



6
7
8
9
10
11
12
# File 'lib/pg_serializable/nodes/association.rb', line 6

def initialize(klass, name, type, label: nil, trait: :default)
  @name = name
  @klass = klass
  @type = type
  @label = label || name
  @trait = trait
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/pg_serializable/nodes/association.rb', line 4

def klass
  @klass
end

#labelObject (readonly)

Returns the value of attribute label.



4
5
6
# File 'lib/pg_serializable/nodes/association.rb', line 4

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/pg_serializable/nodes/association.rb', line 4

def name
  @name
end

#traitObject (readonly)

Returns the value of attribute trait.



4
5
6
# File 'lib/pg_serializable/nodes/association.rb', line 4

def trait
  @trait
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/pg_serializable/nodes/association.rb', line 4

def type
  @type
end

Instance Method Details

#associationObject



22
23
24
# File 'lib/pg_serializable/nodes/association.rb', line 22

def association
  @association ||= @klass.reflect_on_association(@name)
end

#foreign_keyObject



26
27
28
# File 'lib/pg_serializable/nodes/association.rb', line 26

def foreign_key
  @foreign_key ||= association.join_foreign_key
end

#primary_keyObject



30
31
32
# File 'lib/pg_serializable/nodes/association.rb', line 30

def primary_key
  @primary_key ||= association.join_primary_key
end

#targetObject



18
19
20
# File 'lib/pg_serializable/nodes/association.rb', line 18

def target
  @target ||= association.klass
end

#to_sql(outer_alias, aliaser) ⇒ Object



14
15
16
# File 'lib/pg_serializable/nodes/association.rb', line 14

def to_sql(outer_alias, aliaser)
  ["\'#{@label}\'", "(#{value(outer_alias, aliaser)})"].join(',')
end