class ActiveRecordAnalyzer::Reflector::BelongsTo

Public Class Methods

new(klass) click to toggle source
# File lib/active_record_analyzer/reflector/belongs_to.rb, line 2
def initialize(klass)
  @klass = klass
end

Public Instance Methods

attribute_type() click to toggle source
# File lib/active_record_analyzer/reflector/belongs_to.rb, line 10
def attribute_type
  @attribute_type ||= ActiveRecordAnalyzer::Attribute::BelongsTo
end
attributes() click to toggle source

This returns foreign_keys and association names (ex: :company_id and :company).

# File lib/active_record_analyzer/reflector/belongs_to.rb, line 15
def attributes
  @attributes ||= begin
    belongs_to_associations.map do |assoc|
      [assoc.foreign_key.to_sym, assoc.name]
    end.flatten
  end
end
has_attribute?(attribute) click to toggle source
# File lib/active_record_analyzer/reflector/belongs_to.rb, line 6
def has_attribute?(attribute)
  attributes.include?(attribute.to_sym)
end

Private Instance Methods

belongs_to_associations() click to toggle source
# File lib/active_record_analyzer/reflector/belongs_to.rb, line 25
def belongs_to_associations
  @belongs_to_associations ||= begin
    @klass.reflect_on_all_associations.select do |assoc| 
      assoc.is_a?(ActiveRecord::Reflection::BelongsToReflection)
    end
  end
end