Class: ActiveRecordAnalyzer::Reflector

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

Defined Under Namespace

Classes: BelongsTo, HasMany, Simple

Constant Summary collapse

REFLECTORS =
i(belongs_to has_many simple).freeze

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Reflector

Returns a new instance of Reflector.



4
5
6
# File 'lib/active_record_analyzer/reflector.rb', line 4

def initialize(klass)
  @klass = klass
end

Instance Method Details

#reflect(attribute) ⇒ Object

Asks every reflector if they find the given attribute in the class, and returns the attribute type (if any matched).



11
12
13
14
15
# File 'lib/active_record_analyzer/reflector.rb', line 11

def reflect(attribute)
  reflectors.find do |reflector|
    reflector.has_attribute?(attribute)
  end.try(:attribute_type)
end

#reflectorsObject



17
18
19
# File 'lib/active_record_analyzer/reflector.rb', line 17

def reflectors
  REFLECTORS.map { |reflector_name| find_reflector(reflector_name).new(@klass) }
end