Class: Trestle::Attribute::Association

Inherits:
Trestle::Attribute show all
Defined in:
lib/trestle/attribute.rb

Instance Attribute Summary

Attributes inherited from Trestle::Attribute

#name, #options, #type

Instance Method Summary collapse

Methods inherited from Trestle::Attribute

#array?

Constructor Details

#initialize(name, options = {}) ⇒ Association

Returns a new instance of Association.



14
15
16
# File 'lib/trestle/attribute.rb', line 14

def initialize(name, options={})
  super(name, :association, options)
end

Instance Method Details

#association_classObject



22
23
24
# File 'lib/trestle/attribute.rb', line 22

def association_class
  options[:class].respond_to?(:call) ? options[:class].call : options[:class]
end

#association_nameObject



18
19
20
# File 'lib/trestle/attribute.rb', line 18

def association_name
  options[:name] || name.to_s.sub(/_id$/, "")
end

#polymorphic?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/trestle/attribute.rb', line 26

def polymorphic?
  options[:polymorphic] == true
end