Class: ActiveRecordAnalyzer::Reflector::HasMany

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

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ HasMany

Returns a new instance of HasMany.



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

def initialize(klass)
  @klass = klass
end

Instance Method Details

#attribute_typeObject



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

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

#attributesObject

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



15
16
17
# File 'lib/active_record_analyzer/reflector/has_many.rb', line 15

def attributes
  @attributes ||= has_many_associations.map { |assoc| assoc.name }
end

#has_attribute?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


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

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