Sha256: a359792dc87332860630c9706f5c8b77d4cacb1aea5e9399aaf8e66f1d5e52e6

Contents?: true

Size: 871 Bytes

Versions: 3

Compression:

Stored size: 871 Bytes

Contents

# frozen_string_literal: true

module MissionKontrolRelay
  class AssociationMappingService
    def initialize(model)
      @model = model
    end

    def build
      {
        model: @model.name,
        columns: model_columns,
        associations: model_associations
      }
    end

    private

    def model_columns
      columns = []

      @model.columns.each do |column|
        columns << {
          column: column.name,
          type: column.sql_type_metadata.type
        }
      end

      columns
    end

    def model_associations
      associations = []

      @model.reflections.each do |association|
        association = association.last
        associations << {
          associated_model: association.name,
          type: association.macro,
          options: association.try(:options)
        }
      end

      associations
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mission_kontrol_relay-0.1.2 app/services/mission_kontrol_relay/association_mapping_service.rb
mission_kontrol_relay-0.1.1 app/services/mission_kontrol_relay/association_mapping_service.rb
mission_kontrol_relay-0.1.0 app/services/mission_kontrol_relay/association_mapping_service.rb