Sha256: 37c226be3a91b6ca25d50f4391e7dce6d7ec414f600f17531d8b8d7d5ff7879c

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require_relative 'active_record/belongs_to'
require_relative 'active_record/delegated_type'
require_relative 'active_record/enum'
require_relative 'active_record/generated_attribute_methods'
require_relative 'active_record/has_many'
require_relative 'active_record/has_one'
require_relative 'active_record/persistence'
require_relative 'active_record/query_methods'
require_relative 'active_record/relation'
require_relative 'active_record/scope'
require_relative 'active_record/secure_token'

module Orthoses
  module ActiveRecord
    # Thanks https://github.com/pocke/rbs_rails/blob/8a128a8d29f0861aa2c25aa4110ff7c2ea674865/lib/rbs_rails/active_record.rb#L525-L551
    def self.sql_type_to_rbs(t)
      case t
      when :integer, :big_integer
        '::Integer'
      when :float
        '::Float'
      when :decimal
        '::BigDecimal'
      when :string, :text, :citext, :uuid, :binary, :immutable_string
        '::String'
      when :datetime
        '::ActiveSupport::TimeWithZone'
      when :boolean
        "bool"
      when :date
        '::Date'
      when :time
        '::Time'
      when :cidr, :inet
        "::IPAddr"
      when :bit, :bit_varying, :enum, :hstore,
           :interval, :jsonb, :json, :legacy_point, :money, :point, :vector, :xml
        # FIXME
        'untyped'
      else
        # Unknown column type, give up
        'untyped'
      end
    end

    def self.reflection_klass_name(ref)
      Utils.module_name(ref.klass)
    rescue NameError, ArgumentError => e
      while e
        Orthoses.logger.warn(e.message)
        e = e.cause
      end

      nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
orthoses-rails-1.7.0 lib/orthoses/active_record.rb
orthoses-rails-1.6.0 lib/orthoses/active_record.rb