Sha256: 66fd0024a584136500ffea4104e3011bb2cf5403d39dfb6fa56a185247fcf8e7
Contents?: true
Size: 1.46 KB
Versions: 8
Compression:
Stored size: 1.46 KB
Contents
# frozen_string_literal: true module Orthoses module ActiveRecord class HasOne def initialize(loader) @loader = loader end def call @loader.call.tap do |store| ::ActiveRecord::Base.descendants.each do |base| next if base.abstract_class? base_name = Utils.module_name(base) || next lines = base.reflect_on_all_associations(:has_one).flat_map do |ref| type = Orthoses::ActiveRecord.reflection_klass_name(ref) or next opt = "#{type}?" [ "def #{ref.name}: () -> #{opt}", "def #{ref.name}=: (#{opt}) -> #{opt}", "def build_#{ref.name}: (?untyped attributes) ?{ (#{type}) -> void } -> #{type}", "def create_#{ref.name}: (?untyped attributes) ?{ (#{type}) -> void } -> #{type}", "def create_#{ref.name}!: (?untyped attributes) ?{ (#{type}) -> void } -> #{type}", "def reload_#{ref.name}: () -> #{opt}", ] end generated_association_methods = "#{base_name}::GeneratedAssociationMethods" store[generated_association_methods].header = "module #{generated_association_methods}" store[generated_association_methods].concat(lines) sig = "include #{generated_association_methods}" store[base_name] << sig if !store[base_name].body.include?(sig) end end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems