Class: AMA::Entity::Mapper::Type::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/ama-entity-mapper/type/analyzer.rb

Overview

Some naive automatic attribute discovery

Class Method Summary collapse

Class Method Details

.analyze(klass) ⇒ AMA::Entity::Mapper:Type

Parameters:

  • klass (Class, Module)

Returns:

  • (AMA::Entity::Mapper:Type)


14
15
16
17
18
19
20
21
22
# File 'lib/ama-entity-mapper/type/analyzer.rb', line 14

def self.analyze(klass)
  type = Type.new(klass)
  writers = klass.instance_methods.grep(/\w+=$/)
  writers.map do |writer|
    attribute = writer[0..-2]
    type.attribute!(attribute, Type::Any::INSTANCE, nullable: true)
  end
  type
end