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

Analyzer   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
dl 0
loc 13
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A analyze() 0 9 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