Completed
Push — master ( 308a2c...1aebdd )
by Fike
01:00
created

Analyzer.analyze()   A

Complexity

Conditions 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
1
# frozen_string_literal: true
2
3
require_relative '../type'
4
require_relative 'any'
5
6
module AMA
7
  module Entity
8
    class Mapper
9
      class Type
10
        # Some naive automatic attribute discovery
11
        class Analyzer
12
          # @param [Class, Module] klass
13
          # @return [AMA::Entity::Mapper:Type]
14
          def self.analyze(klass)
15
            type = Type.new(klass)
16
            writers = klass.instance_methods.grep(/\w+=$/)
17
            writers.map do |writer|
18
              attribute = writer[0..-2]
19
              type.attribute!(attribute, Type::Any::INSTANCE)
20
            end
21
            type
22
          end
23
        end
24
      end
25
    end
26
  end
27
end
28