Class: ActiveRecordAnalyzer::Reflector::BelongsTo

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_analyzer/reflector/belongs_to.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ BelongsTo

Returns a new instance of BelongsTo.



2
3
4
# File 'lib/active_record_analyzer/reflector/belongs_to.rb', line 2

def initialize(klass)
  @klass = klass
end

Instance Method Details

#attribute_typeObject



10
11
12
# File 'lib/active_record_analyzer/reflector/belongs_to.rb', line 10

def attribute_type
  @attribute_type ||= ActiveRecordAnalyzer::Attribute::BelongsTo
end

#attributesObject

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



15
16
17
18
19
20
21
# 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) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/active_record_analyzer/reflector/belongs_to.rb', line 6

def has_attribute?(attribute)
  attributes.include?(attribute.to_sym)
end