class Administrate::Field::Associative

Public Class Methods

associated_class(resource_class, attr) click to toggle source
# File lib/administrate/field/associative.rb, line 14
def self.associated_class(resource_class, attr)
  reflection(resource_class, attr).klass
end
associated_class_name(resource_class, attr) click to toggle source
# File lib/administrate/field/associative.rb, line 18
def self.associated_class_name(resource_class, attr)
  associated_class(resource_class, attr).name
end
association_primary_key_for(resource_class, attr) click to toggle source
# File lib/administrate/field/associative.rb, line 10
def self.association_primary_key_for(resource_class, attr)
  reflection(resource_class, attr).association_primary_key
end
foreign_key_for(resource_class, attr) click to toggle source
# File lib/administrate/field/associative.rb, line 6
def self.foreign_key_for(resource_class, attr)
  reflection(resource_class, attr).foreign_key
end
reflection(resource_class, attr) click to toggle source
# File lib/administrate/field/associative.rb, line 22
def self.reflection(resource_class, attr)
  resource_class.reflect_on_association(attr)
end

Public Instance Methods

associated_class() click to toggle source
# File lib/administrate/field/associative.rb, line 30
def associated_class
  if option_given?(:class_name)
    associated_class_name.constantize
  else
    self.class.associated_class(resource.class, attribute)
  end
end
associated_class_name() click to toggle source
# File lib/administrate/field/associative.rb, line 38
def associated_class_name
  if option_given?(:class_name)
    deprecated_option(:class_name)
  else
    self.class.associated_class_name(
      resource.class,
      attribute,
    )
  end
end
display_associated_resource() click to toggle source
# File lib/administrate/field/associative.rb, line 26
def display_associated_resource
  associated_dashboard.display_resource(data)
end

Private Instance Methods

associated_dashboard() click to toggle source
# File lib/administrate/field/associative.rb, line 51
def associated_dashboard
  "#{associated_class_name}Dashboard".constantize.new
end
association_primary_key() click to toggle source
# File lib/administrate/field/associative.rb, line 61
def association_primary_key
  if option_given?(:primary_key)
    deprecated_option(:primary_key)
  else
    self.class.association_primary_key_for(resource.class, attribute)
  end
end
deprecated_option(name) click to toggle source
# File lib/administrate/field/associative.rb, line 81
def deprecated_option(name)
  Administrate.warn_of_deprecated_option(name)
  options.fetch(name)
end
foreign_key() click to toggle source
# File lib/administrate/field/associative.rb, line 69
def foreign_key
  if option_given?(:foreign_key)
    deprecated_option(:foreign_key)
  else
    self.class.foreign_key_for(resource.class, attribute)
  end
end
option_given?(name) click to toggle source
# File lib/administrate/field/associative.rb, line 77
def option_given?(name)
  options.key?(name)
end
primary_key() click to toggle source
# File lib/administrate/field/associative.rb, line 55
def primary_key
  # Deprecated, renamed `association_primary_key`
  Administrate.warn_of_deprecated_method(self.class, :primary_key)
  association_primary_key
end