Class: PgSerializable::Nodes::Association
- Defined in:
- lib/pg_serializable/nodes/association.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#trait ⇒ Object
readonly
Returns the value of attribute trait.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #association ⇒ Object
- #foreign_key ⇒ Object
-
#initialize(klass, name, type, label: nil, trait: :default) ⇒ Association
constructor
A new instance of Association.
- #primary_key ⇒ Object
- #target ⇒ Object
- #to_sql(outer_alias, aliaser) ⇒ Object
Methods inherited from Base
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
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
4 5 6 |
# File 'lib/pg_serializable/nodes/association.rb', line 4 def klass @klass end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
4 5 6 |
# File 'lib/pg_serializable/nodes/association.rb', line 4 def label @label end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/pg_serializable/nodes/association.rb', line 4 def name @name end |
#trait ⇒ Object (readonly)
Returns the value of attribute trait.
4 5 6 |
# File 'lib/pg_serializable/nodes/association.rb', line 4 def trait @trait end |
#type ⇒ Object (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
#association ⇒ Object
22 23 24 |
# File 'lib/pg_serializable/nodes/association.rb', line 22 def association @association ||= @klass.reflect_on_association(@name) end |
#foreign_key ⇒ Object
26 27 28 |
# File 'lib/pg_serializable/nodes/association.rb', line 26 def foreign_key @foreign_key ||= association.join_foreign_key end |
#primary_key ⇒ Object
30 31 32 |
# File 'lib/pg_serializable/nodes/association.rb', line 30 def primary_key @primary_key ||= association.join_primary_key end |
#target ⇒ Object
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 |