Class: ActiveRecordAnalyzer::Reflector::BelongsTo
- Inherits:
-
Object
- Object
- ActiveRecordAnalyzer::Reflector::BelongsTo
- Defined in:
- lib/active_record_analyzer/reflector/belongs_to.rb
Instance Method Summary collapse
- #attribute_type ⇒ Object
-
#attributes ⇒ Object
This returns foreign_keys and association names (ex: :company_id and :company).
- #has_attribute?(attribute) ⇒ Boolean
-
#initialize(klass) ⇒ BelongsTo
constructor
A new instance of BelongsTo.
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_type ⇒ Object
10 11 12 |
# File 'lib/active_record_analyzer/reflector/belongs_to.rb', line 10 def attribute_type @attribute_type ||= ActiveRecordAnalyzer::Attribute::BelongsTo end |
#attributes ⇒ Object
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
6 7 8 |
# File 'lib/active_record_analyzer/reflector/belongs_to.rb', line 6 def has_attribute?(attribute) attributes.include?(attribute.to_sym) end |